linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/11] gpiolib: work towards removing gpiochip_find()
@ 2023-09-12 10:07 Bartosz Golaszewski
  2023-09-12 10:07 ` [PATCH v2 01/11] gpiolib: make gpio_device_get() and gpio_device_put() public Bartosz Golaszewski
                   ` (10 more replies)
  0 siblings, 11 replies; 24+ messages in thread
From: Bartosz Golaszewski @ 2023-09-12 10:07 UTC (permalink / raw)
  To: Linus Walleij, Andy Shevchenko, Mika Westerberg
  Cc: linux-gpio, linux-kernel, linux-acpi, Bartosz Golaszewski

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/

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     |  32 +++---
 drivers/gpio/gpiolib-swnode.c |  33 +++---
 drivers/gpio/gpiolib-sysfs.c  |   2 +-
 drivers/gpio/gpiolib.c        | 201 ++++++++++++++++++++++++++--------
 drivers/gpio/gpiolib.h        |  10 --
 include/linux/gpio/driver.h   |  13 +++
 7 files changed, 211 insertions(+), 92 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2023-09-15  9:44 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-12 10:07 [PATCH v2 00/11] gpiolib: work towards removing gpiochip_find() Bartosz Golaszewski
2023-09-12 10:07 ` [PATCH v2 01/11] gpiolib: make gpio_device_get() and gpio_device_put() public Bartosz Golaszewski
2023-09-12 10:07 ` [PATCH v2 02/11] gpiolib: add support for scope-based management to gpio_device Bartosz Golaszewski
2023-09-12 11:33   ` Andy Shevchenko
2023-09-12 11:36     ` Bartosz Golaszewski
2023-09-12 10:07 ` [PATCH v2 03/11] gpiolib: provide gpio_device_find() Bartosz Golaszewski
2023-09-12 10:07 ` [PATCH v2 04/11] gpiolib: provide gpio_device_find_by_label() Bartosz Golaszewski
2023-09-12 10:57   ` Andy Shevchenko
2023-09-14 19:55     ` Bartosz Golaszewski
2023-09-12 10:07 ` [PATCH v2 05/11] gpiolib: provide gpio_device_get_desc() Bartosz Golaszewski
2023-09-12 11:00   ` Andy Shevchenko
2023-09-12 10:07 ` [PATCH v2 06/11] gpiolib: reluctantly provide gpio_device_get_chip() Bartosz Golaszewski
2023-09-12 10:07 ` [PATCH v2 07/11] gpiolib: replace find_chip_by_name() with gpio_device_find_by_label() Bartosz Golaszewski
2023-09-12 11:08   ` Andy Shevchenko
2023-09-12 11:34     ` Bartosz Golaszewski
2023-09-12 11:16   ` Andy Shevchenko
2023-09-12 11:35     ` Bartosz Golaszewski
2023-09-15  9:44       ` Bartosz Golaszewski
2023-09-12 10:07 ` [PATCH v2 08/11] gpio: of: replace gpiochip_find_* with gpio_device_find_* Bartosz Golaszewski
2023-09-12 11:20   ` Andy Shevchenko
2023-09-12 10:07 ` [PATCH v2 09/11] gpio: acpi: replace gpiochip_find() with gpio_device_find() Bartosz Golaszewski
2023-09-12 11:31   ` Andy Shevchenko
2023-09-12 10:07 ` [PATCH v2 10/11] gpio: swnode: replace gpiochip_find() with gpio_device_find_by_label() Bartosz Golaszewski
2023-09-12 10:07 ` [PATCH v2 11/11] gpio: sysfs: drop the mention of gpiochip_find() from sysfs code Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).