Message ID | 20230915150327.81918-1-brgl@bgdev.pl |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1171174vqi; Fri, 15 Sep 2023 09:29:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFs6kbrpc86T+vxYmUf9Repc3kg3k0NWlePLUydjoqfDTlNYYJhLQwamkKMxWRt2igBbvw1 X-Received: by 2002:a05:6358:339a:b0:139:5a46:ea7e with SMTP id i26-20020a056358339a00b001395a46ea7emr2701584rwd.28.1694795348021; Fri, 15 Sep 2023 09:29:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694795347; cv=none; d=google.com; s=arc-20160816; b=TwpF6G1p51tSr+aoKEEzs9DSG9m8XCAvjs32fDz2W5hXX/jd6mEqA8ggMhPHtalGLN pcwm2jfVDSvbqtTXoduOZAFa/OJecjJbhhi4nUK+fN7sy8QQLQ0LnGOghhodl4fA/ZMS rogh8bv5NkO404JvzryasyzCi9SpenUtCbVQK7h8cB+o8GOhfIlTySD9hkkoszEhXgdE e+q+Ygd7lrjwl2cPlE8YZblADREx2/0aImBe4pbTWPixoC0av+ufsFUwy2euyruynlPs pMj2LPOH8ohn+KAzMlDrf7FPIH8DEBeH8uCGvipwjaFOdz1ajOvlsxZJzYn001KOtpXy pJ4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=v2icBidhNqLF921D274+HegN9s4sM/PCTy5BqMLL57c=; fh=sKfwLbYyGsqFA9J5964tfV31zxizqPhzkdLiyF/udjc=; b=DooiZoBkwFZ7aAbqxDZ/IAdykMKMhPp2jNxxujBqXdCpCvvPdB+iAyyGF1OJf9zcVi AWB7cL1OpN/AGzughk9aQqdooJpqZi0XcQcsKnohjD3WtsY4U7eC9FTnLiW4ybFYtcy0 riE3rggskWlC0Hyn+oey/uYXSu/EXV0QKJoPD2vJCiS7adayhLDYLQjNc2yawhzwG6ie zym71QtxRqhdqFno1tPqxKcsyoPX9ZmBIwHjFjHh9njEuajuU5xqwbIKNGkMGG2jCoup Q2unDaths3CQX6R/UDaZ8C9/0C6rABVTb9yexp1ZiEXZBpTIf4zwtUcPlZX39Rmg4Qri /CzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=x+TQ3jbv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id e10-20020a63690a000000b00573fa8f2827si3378937pgc.340.2023.09.15.09.29.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 09:29:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=x+TQ3jbv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4D09D8446E6A; Fri, 15 Sep 2023 08:04:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235911AbjIOPDz (ORCPT <rfc822;ruipengqi7@gmail.com> + 31 others); Fri, 15 Sep 2023 11:03:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbjIOPDj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 15 Sep 2023 11:03:39 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36442211E for <linux-kernel@vger.kernel.org>; Fri, 15 Sep 2023 08:03:32 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-31f853f2f3aso2228466f8f.0 for <linux-kernel@vger.kernel.org>; Fri, 15 Sep 2023 08:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694790210; x=1695395010; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=v2icBidhNqLF921D274+HegN9s4sM/PCTy5BqMLL57c=; b=x+TQ3jbvdGtso1IF9KzIw5VBjDCeGxZzua2+ltbfk/Q6ccsT9ckmoEmB6Vwww8Ya1p x5DEBj9e9fMTtm6x+6Z2KWv4RlbqCFxIIwHL33FE9p9rmWg+5ukU9483ehDlE8JwYaC4 zsn/OdN83lSofAYFsMvVkOMdacpmEp2t0EGMOcH6Fb+VNv0ufeuzvJx+XlKxmcFtpJ8V smnsfxxDR9EB27ePdweKgXpclwitYh3hPI+/aGIQVwO/OOBsNIRekL2s4bu9xgYtCOfK rWC0JVR66XXSWKKiIM9TJdNIzliWaIu0LksZ2JB8O0wh9WbJELVM7Pzm3s7T/rOL6dzb uaHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694790210; x=1695395010; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v2icBidhNqLF921D274+HegN9s4sM/PCTy5BqMLL57c=; b=d7GZwHb8Y9RSfKKovz8gbpEVJtDetrsXT/7aXQNPmzgcx8lcJUXJFKF/Not2Jn/Rx0 lPf7Og+EI2L83g0NqAHmk+TFvP/09nQIDY/uujpUVzcCuvTHTj5VUcGOVoGf8lVYpnPR 3CcLgwTbp9Ph8/ytTbw7xEJKytadaNu6OwR28erzRoZL1j0xhdFWKIej09fn7a2GJNIO 2e2DLP7fKGGQ3T6ZCI0zNa6g65k+5J5kp2uURrXo2LA0k4cWGiHCc7W3do6BFUm6fif2 gU9reY1i3Fq6B56Jm3MpGm/OZrYi5qrqjH2tyYHFuSxfPSS/A1Z8NxnHkn6FxYF8no3F F3sw== X-Gm-Message-State: AOJu0YyI5Hme3efjuZ4MsnsgcDVoKKzCU9l6bocyBfVf7fWSiQjynSNx FutENDQR9aR4hVlkPIXs/rUvWQ== X-Received: by 2002:a5d:6f15:0:b0:31f:ecb2:d774 with SMTP id ay21-20020a5d6f15000000b0031fecb2d774mr2343475wrb.19.1694790210397; Fri, 15 Sep 2023 08:03:30 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:aa19:4569:aeeb:c0d3]) by smtp.gmail.com with ESMTPSA id hn40-20020a05600ca3a800b003fef19bb55csm4853369wmb.34.2023.09.15.08.03.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 08:03:29 -0700 (PDT) From: Bartosz Golaszewski <brgl@bgdev.pl> To: Linus Walleij <linus.walleij@linaro.org>, Andy Shevchenko <andriy.shevchenko@linux.intel.com>, Mika Westerberg <mika.westerberg@linux.intel.com> Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Subject: [PATCH v3 00/11] gpiolib: work towards removing gpiochip_find() Date: Fri, 15 Sep 2023 17:03:15 +0200 Message-Id: <20230915150327.81918-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 15 Sep 2023 08:04:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777121726648938639 X-GMAIL-MSGID: 1777121726648938639 |
Series |
gpiolib: work towards removing gpiochip_find()
|
|
Message
Bartosz Golaszewski
Sept. 15, 2023, 3:03 p.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This is a reduced subset of patches from the initial sumbission[1]
limited only to changes inside GPIOLIB. Once this is upstream, we can
then slowly merge patches for other subsystems (like HTE) and then
eventually remove gpiochip_find() entirely.
The GPIO subsystem does not handle hot-unplug events very well. We have
recently patched the user-space part of it so that at least a rouge user
cannot crash the kernel but in-kernel users are still affected by a lot of
issues: from incorrect locking or lack thereof to using structures that are
private to GPIO drivers. Since almost all GPIO controllers can be unbound,
not to mention that we have USB devices registering GPIO expanders as well as
I2C-on-USB HID devices on which I2C GPIO expanders can live, various media
gadgets etc., we really need to make GPIO hotplug/unplug friendly.
Before we can even get to fixing the locking, we need to address a serious
abuse of the GPIO driver API - accessing struct gpio_chip by anyone who isn't
the driver owning this object. This structure is owned by the GPIO provider
and its lifetime is tied to that of that provider. It is destroyed when the
device is unregistered and this may happen at any moment. struct gpio_device
is the opaque, reference counted interface to struct gpio_chip (which is the
low-level implementation) and all access should pass through it.
The end-goal is to make all gpio_device manipulators check the existence of
gdev->chip and then lock it for the duration of any of the calls using SRCU.
Before we can get there, we need to first provide a set of functions that will
replace any gpio_chip functions and convert all in-kernel users.
This series adds several new helpers to the public GPIO API and uses
them across the core GPIO code.
Note that this does not make everything correct just yet. Especially the
GPIOLIB internal users release the reference returned by the lookup function
after getting the descriptor of interest but before requesting it. This will
eventually be addressed. This is not a regression either.
[1] https://lore.kernel.org/lkml/20230905185309.131295-1-brgl@bgdev.pl/T/
v2 -> v3:
- use gpio_device_get_chip() consistently
- clarify comments
- fix buggy chip assignment
- check for PTR_ERR() in automatic cleanup
- rearrange code as requested by Andy
v1 -> v2:
- drop all non-GPIOLIB patches
- collect tags
- fix kernel docs
- use gpio_device_get_chip() and gpio_device_get_desc() where applicable
Bartosz Golaszewski (11):
gpiolib: make gpio_device_get() and gpio_device_put() public
gpiolib: add support for scope-based management to gpio_device
gpiolib: provide gpio_device_find()
gpiolib: provide gpio_device_find_by_label()
gpiolib: provide gpio_device_get_desc()
gpiolib: reluctantly provide gpio_device_get_chip()
gpiolib: replace find_chip_by_name() with gpio_device_find_by_label()
gpio: of: replace gpiochip_find_* with gpio_device_find_*
gpio: acpi: replace gpiochip_find() with gpio_device_find()
gpio: swnode: replace gpiochip_find() with gpio_device_find_by_label()
gpio: sysfs: drop the mention of gpiochip_find() from sysfs code
drivers/gpio/gpiolib-acpi.c | 12 +-
drivers/gpio/gpiolib-of.c | 33 +++---
drivers/gpio/gpiolib-swnode.c | 33 +++---
drivers/gpio/gpiolib-sysfs.c | 2 +-
drivers/gpio/gpiolib.c | 202 ++++++++++++++++++++++++++--------
drivers/gpio/gpiolib.h | 10 --
include/linux/gpio/driver.h | 16 +++
7 files changed, 216 insertions(+), 92 deletions(-)