gpio: convert users to gpio_device_find() and remove gpiochip_find()
Subsystems (9)
cover gpio: convert users to gpio_device_find() and remove gpiochip_find()
From: Bartosz Golaszewski <[email protected]>
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 starts the process by replacing gpiochip_find() with gpio_device_find(). This is in line with other device_find type interfaces and returns a reference to the GPIO device that is guaranteed to remain valid until it is put.
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.
First we add a bunch of new APIs that are needed to start replacing calls to gpiochip_find. We then use them first in external users and then locally in GPIOLIB core. Finally we remove gpiochip_find().
Bartosz Golaszewski (21):
gpiolib: make gpio_device_get() and gpio_device_put() public
gpiolib: provide gpio_device_find()
gpiolib: provide gpio_device_find_by_label()
gpiolib: provide gpio_device_get_desc()
gpiolib: add support for scope-based management to gpio_device
gpiolib: provide gpiod_to_device()
gpiolib: provide gpio_device_get_base()
gpio: acpi: provide acpi_gpio_device_free_interrupts()
gpiolib: reluctantly provide gpio_device_get_chip()
gpiolib: replace find_chip_by_name() with gpio_device_find_by_label()
platform: x86: android-tablets: don't access GPIOLIB private members
hte: allow building modules with COMPILE_TEST enabled
hte: tegra194: improve the GPIO-related comment
hte: tegra194: don't access struct gpio_chip
arm: omap1: ams-delta: stop using gpiochip_find()
gpio: of: correct notifier return codes
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
gpiolib: remove gpiochip_find()
arch/arm/mach-omap1/board-ams-delta.c | 36 ++-- drivers/gpio/gpiolib-acpi.c | 37 +++- drivers/gpio/gpiolib-of.c | 48 ++--- drivers/gpio/gpiolib-swnode.c | 29 ++- drivers/gpio/gpiolib-sysfs.c | 2 +- drivers/gpio/gpiolib.c | 203 +++++++++++++----- drivers/gpio/gpiolib.h | 10 - drivers/hte/Kconfig | 4 +- drivers/hte/hte-tegra194.c | 49 +++-- .../platform/x86/x86-android-tablets/core.c | 38 ++-- include/linux/gpio/driver.h | 30 ++- 11 files changed, 316 insertions(+), 170 deletions(-)
Signature · 1 line
2.39.2
PATCH 1/21 gpiolib: make gpio_device_get() and gpio_device_put() public
From: Bartosz Golaszewski <[email protected]>
In order to start migrating away from accessing struct gpio_chip by users other than their owners, let's first make the reference management functions for the opaque struct gpio_device public in the driver.h header.
--- drivers/gpio/gpiolib.c | 24 ++++++++++++++++++++++++ drivers/gpio/gpiolib.h | 10 ---------- include/linux/gpio/driver.h | 3 +++ 3 files changed, 27 insertions(+), 10 deletions(-)
drivers/gpio/gpiolib.c +24 -0
@@ -1058,6 +1058,30 @@ static struct gpio_chip *find_chip_by_name(const char *name)return gpiochip_find ((void *)name, gpiochip_match_name); } +/** +* gpio_device_get() - Increase the reference count of this GPIO device +* @gdev: GPIO device to increase the refcount for +* +* Returns: +* Pointer to @gdev. +*/ +struct gpio_device *gpio_device_get (struct gpio_device *gdev) +{ +return to_gpio_device (get_device (&gdev->dev)); +} +EXPORT_SYMBOL_GPL (gpio_device_get); + +/** +* gpio_device_put() - Decrease the reference count of this GPIO device and +* possibly free all resources associated with it. +* @gdev: GPIO device to decrease the reference count for +*/ +void gpio_device_put (struct gpio_device *gdev) +{ +put_device (&gdev->dev); +} +EXPORT_SYMBOL_GPL (gpio_device_put); +#ifdef CONFIG_GPIOLIB_IRQCHIP /*
drivers/gpio/gpiolib.h +0 -10
@@ -86,16 +86,6 @@ static inline struct gpio_device *to_gpio_device(struct device *dev) return container_of(dev, struct gpio_device, dev); } -static inline struct gpio_device *gpio_device_get (struct gpio_device *gdev) -{ -return to_gpio_device (get_device (&gdev->dev)); -} - -static inline void gpio_device_put (struct gpio_device *gdev) -{ -put_device (&gdev->dev); -} -/* gpio suffixes used for ACPI and device tree lookup */ static __maybe_unused const char *const gpio_suffixes[] = {"gpios" ,"gpio" };
include/linux/gpio/driver.h +3 -0
@@ -606,6 +606,9 @@ int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc,struct gpio_chip *gpiochip_find (void *data,int (*match)(struct gpio_chip *gc,void *data)); +struct gpio_device *gpio_device_get (struct gpio_device *gdev); +void gpio_device_put (struct gpio_device *gdev); +bool gpiochip_line_is_irq (struct gpio_chip *gc,unsigned int offset);int gpiochip_reqres_irq (struct gpio_chip *gc,unsigned int offset);void gpiochip_relres_irq (struct gpio_chip *gc,unsigned int offset);
Signature · 1 line
2.39.2
PATCH 2/21 gpiolib: provide gpio_device_find()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
gpiochip_find() is wrong and its kernel doc is misleading as the function doesn't return a reference to the gpio_chip but just a raw pointer. The chip itself is not guaranteed to stay alive, in fact it can be deleted at any point. Also: other than GPIO drivers themselves, nobody else has any business accessing gpio_chip structs.
Provide a new gpio_device_find() function that returns a real reference to the opaque gpio_device structure that is guaranteed to stay alive for as long as there are active users of it.
--- drivers/gpio/gpiolib.c | 64 ++++++++++++++++++++++++++----------- include/linux/gpio/driver.h | 4 +++ 2 files changed, 50 insertions(+), 18 deletions(-)
drivers/gpio/gpiolib.c +46 -18
@@ -1014,16 +1014,10 @@ void gpiochip_remove(struct gpio_chip *gc) }EXPORT_SYMBOL_GPL (gpiochip_remove); -/** -* gpiochip_find() - iterator for locating a specific gpio_chip -* @data: data to pass to match function -* @match: Callback function to check gpio_chip +/* +* FIXME: This will be removed soon. * -* Similar to bus_find_device. It returns a reference to a gpio_chip as -* determined by a user supplied @match callback. The callback should return -* 0 if the device doesn't match and non-zero if it does. If the callback is -* non-zero, this function will return to the caller and not iterate over any -* more gpio_chips. +* This function is depracated, don't use. */ struct gpio_chip *gpiochip_find(void *data, int (*match)(struct gpio_chip *gc,
@@ -1031,21 +1025,55 @@ struct gpio_chip *gpiochip_find(void *data, {struct gpio_device *gdev;struct gpio_chip *gc =NULL ; -unsigned long flags; -spin_lock_irqsave (&gpio_lock, flags); -list_for_each_entry (gdev, &gpio_devices, list) -if (gdev->chip &&match (gdev->chip, data)) { - gc = gdev->chip; -break ; - } - -spin_unlock_irqrestore (&gpio_lock, flags); + gdev =gpio_device_find (data, match); +if (gdev) { + gc = gdev->chip; +gpio_device_put (gdev); + }return gc; }EXPORT_SYMBOL_GPL (gpiochip_find); +/** +* gpio_device_find() - find a specific GPIO device +* @data: data to pass to match function +* @match: Callback function to check gpio_chip +* +* Returns: +* New reference to struct gpio_device. +* +* Similar to bus_find_device(). It returns a reference to a gpio_device as +* determined by a user supplied @match callback. The callback should return +* 0 if the device doesn't match and non-zero if it does. If the callback +* returns non-zero, this function will return to the caller and not iterate +* over any more gpio_devices. +* +* The callback takes the GPIO chip structure as argument. During the execution +* of the callback function the chip is protected from being freed. TODO: This +* actually has yet to be implemented. +* +* If the function returns non-NULL, the returned reference must be freed by +* the caller using gpio_device_put(). +*/ +struct gpio_device *gpio_device_find (void *data, +int (*match)(struct gpio_chip *gc, +void *data)) +{ +struct gpio_device *gdev; + +guard (spinlock_irqsave)(&gpio_lock); + +list_for_each_entry (gdev, &gpio_devices, list) { +if (gdev->chip &&match (gdev->chip, data)) +return gpio_device_get (gdev); + } + +return NULL ; +} +EXPORT_SYMBOL_GPL (gpio_device_find); +static int gpiochip_match_name (struct gpio_chip *gc,void *data) {const char *name = data;
include/linux/gpio/driver.h +4 -0
@@ -606,6 +606,10 @@ int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc,struct gpio_chip *gpiochip_find (void *data,int (*match)(struct gpio_chip *gc,void *data)); +struct gpio_device *gpio_device_find (void *data, +int (*match)(struct gpio_chip *gc, +void *data)); +struct gpio_device *gpio_device_get (struct gpio_device *gdev);void gpio_device_put (struct gpio_device *gdev);
Signature · 1 line
2.39.2
PATCH 3/21 gpiolib: provide gpio_device_find_by_label()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
By far the most common way of looking up GPIO devices is using their label. Provide a helpers for that to avoid every user implementing their own matching function.
--- drivers/gpio/gpiolib.c | 21 +++++++++++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 22 insertions(+)
drivers/gpio/gpiolib.c +21 -0
@@ -20,6 +20,7 @@#include <linux/seq_file.h> #include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/string.h> #include <linux/gpio.h> #include <linux/gpio/driver.h>
@@ -1074,6 +1075,26 @@ struct gpio_device *gpio_device_find(void *data, }EXPORT_SYMBOL_GPL (gpio_device_find); +static int gpio_chip_match_by_label (struct gpio_chip *gc,void *label) +{ +return gc->label && !strcmp (gc->label, label); +} + +/** +* gpio_device_find_by_label() - wrapper around gpio_device_find() finding the +* GPIO device by its backing chip's label +* @label: Label to lookup +* +* Returns: +* Reference to the GPIO device or NULL. Reference must be released with +* ``gpio_device_put``. +*/ +struct gpio_device *gpio_device_find_by_label (const char *label) +{ +return gpio_device_find ((void *)label, gpio_chip_match_by_label); +} +EXPORT_SYMBOL_GPL (gpio_device_find_by_label); +static int gpiochip_match_name (struct gpio_chip *gc,void *data) {const char *name = data;
include/linux/gpio/driver.h +1 -0
@@ -609,6 +609,7 @@ struct gpio_chip *gpiochip_find(void *data,struct gpio_device *gpio_device_find (void *data,int (*match)(struct gpio_chip *gc,void *data)); +struct gpio_device *gpio_device_find_by_label (const char *label);struct gpio_device *gpio_device_get (struct gpio_device *gdev);void gpio_device_put (struct gpio_device *gdev);
Signature · 1 line
2.39.2
PATCH 4/21 gpiolib: provide gpio_device_get_desc()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Getting the GPIO descriptor directly from the gpio_chip struct is dangerous as we don't take the reference to the underlying GPIO device. In order to start working towards removing gpiochip_get_desc(), let's provide a safer variant that works with an existing reference to struct gpio_device.
--- drivers/gpio/gpiolib.c | 45 +++++++++++++++++++++++++++---------- include/linux/gpio/driver.h | 2 ++ 2 files changed, 35 insertions(+), 12 deletions(-)
drivers/gpio/gpiolib.c +33 -12
@@ -147,27 +147,48 @@ struct gpio_desc *gpio_to_desc(unsigned gpio) }EXPORT_SYMBOL_GPL (gpio_to_desc); -/** -* gpiochip_get_desc - get the GPIO descriptor corresponding to the given -* hardware number for this chip -* @gc: GPIO chip -* @hwnum: hardware number of the GPIO for this chip -* -* Returns: -* A pointer to the GPIO descriptor or ``ERR_PTR(-EINVAL)`` if no GPIO exists -* in the given chip for the specified hardware number. -*/ +/* This function is deprecated and will be removed soon, don't use. */ struct gpio_desc *gpiochip_get_desc (struct gpio_chip *gc,unsigned int hwnum) { -struct gpio_device *gdev = gc->gpiodev; +return gpio_device_get_desc (gc->gpiodev, hwnum); +} +EXPORT_SYMBOL_GPL (gpiochip_get_desc); + +/** +* gpio_device_get_desc() - get the GPIO descriptor corresponding to the given +* hardware number for this GPIO device +* @gdev: GPIO device to get the descriptor from +* @hwnum: hardware number of the GPIO for this chip +* +* Returns: +* A pointer to the GPIO descriptor or ``ERR_PTR(-EINVAL)`` if no GPIO exists +* in the given chip for the specified hardware number or ``ERR_PTR(-ENODEV)`` +* if the underlying chip already vanished. +* +* The reference count of struct gpio_device is *NOT* increased like when the +* GPIO is being requested for exclusive usage. It's up to the caller to make +* sure the GPIO device will stay alive together with the descriptor returned +* by this function. +*/ +struct gpio_desc * +gpio_device_get_desc (struct gpio_device *gdev,unsigned int hwnum) +{ +struct gpio_chip *gc = gdev->chip; + +/* +* FIXME: This will be locked once we protect gdev->chip everywhere +* with SRCU. +*/ +if (!gc) +return ERR_PTR (-ENODEV );if (hwnum >= gdev->ngpio)return ERR_PTR (-EINVAL );return &gdev->descs[hwnum]; } -EXPORT_SYMBOL_GPL (gpiochip_get_desc); +EXPORT_SYMBOL_GPL (gpio_device_get_desc);/** * desc_to_gpio - convert a GPIO descriptor to the integer namespace
include/linux/gpio/driver.h +2 -0
@@ -766,6 +766,8 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc,void gpiochip_free_own_desc (struct gpio_desc *desc);struct gpio_desc *gpiochip_get_desc (struct gpio_chip *gc,unsigned int hwnum); +struct gpio_desc * +gpio_device_get_desc (struct gpio_device *gdev,unsigned int hwnum);#ifdef CONFIG_GPIOLIB
Signature · 1 line
2.39.2
PATCH 5/21 gpiolib: add support for scope-based management to gpio_device
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
As the few users that need to get the reference to the GPIO device often release it right after inspecting its properties, let's add support for the automatic reference release to struct gpio_device.
--- include/linux/gpio/driver.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/gpio/driver.h +2 -0
@@ -614,6 +614,8 @@ struct gpio_device *gpio_device_find_by_label(const char *label);struct gpio_device *gpio_device_get (struct gpio_device *gdev);void gpio_device_put (struct gpio_device *gdev); +DEFINE_FREE(gpio_device_put, struct gpio_device *, if (_T) gpio_device_put(_T)); +bool gpiochip_line_is_irq (struct gpio_chip *gc,unsigned int offset);int gpiochip_reqres_irq (struct gpio_chip *gc,unsigned int offset);void gpiochip_relres_irq (struct gpio_chip *gc,unsigned int offset);
Signature · 1 line
2.39.2
PATCH 6/21 gpiolib: provide gpiod_to_device()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
struct gpio_desc is opaque so provide a way for users to retrieve the underlying GPIO device.
--- drivers/gpio/gpiolib.c | 14 ++++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 15 insertions(+)
drivers/gpio/gpiolib.c +14 -0
@@ -219,6 +219,20 @@ struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) }EXPORT_SYMBOL_GPL (gpiod_to_chip); +/** +* gpiod_to_device() - Return the GPIO device owning this descriptor +* @desc: GPIO descriptor +* +* Returns: +* Pointer to the opaque struct gpio_device object. This function does not +* increase the reference count of gpio_device. +*/ +struct gpio_device *gpiod_to_device (struct gpio_desc *desc) +{ +return gpio_device_get (desc->gdev); +} +EXPORT_SYMBOL_GPL (gpiod_to_device); +/* dynamic allocation of GPIOs, e.g. on a hotplugged device */ static int gpiochip_find_base (int ngpio) {
include/linux/gpio/driver.h +1 -0
@@ -778,6 +778,7 @@ int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset);void gpiochip_unlock_as_irq (struct gpio_chip *gc,unsigned int offset);struct gpio_chip *gpiod_to_chip (const struct gpio_desc *desc); +struct gpio_device *gpiod_to_device (struct gpio_desc *desc);#else /* CONFIG_GPIOLIB */
Signature · 1 line
2.39.2
PATCH 7/21 gpiolib: provide gpio_device_get_base()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Let's start adding getters for the opaque struct gpio_device. Start with a function allowing to retrieve the base GPIO number.
--- drivers/gpio/gpiolib.c | 13 +++++++++++++ include/linux/gpio/driver.h | 3 +++ 2 files changed, 16 insertions(+)
drivers/gpio/gpiolib.c +13 -0
@@ -233,6 +233,19 @@ struct gpio_device *gpiod_to_device(struct gpio_desc *desc) }EXPORT_SYMBOL_GPL (gpiod_to_device); +/** +* gpio_device_get_base() - Get the base GPIO number allocated by this device +* @gdev: GPIO device +* +* Returns: +* First GPIO number in the global GPIO numberspace for this device. +*/ +int gpio_device_get_base (struct gpio_device *gdev) +{ +return gdev->base; +} +EXPORT_SYMBOL_GPL (gpio_device_get_base); +/* dynamic allocation of GPIOs, e.g. on a hotplugged device */ static int gpiochip_find_base (int ngpio) {
include/linux/gpio/driver.h +3 -0
@@ -780,6 +780,9 @@ void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset);struct gpio_chip *gpiod_to_chip (const struct gpio_desc *desc);struct gpio_device *gpiod_to_device (struct gpio_desc *desc); +/* struct gpio_device getters */ +int gpio_device_get_base (struct gpio_device *gdev); +#else /* CONFIG_GPIOLIB */ #include <linux/err.h>
Signature · 1 line
2.39.2
PATCH 8/21 gpio: acpi: provide acpi_gpio_device_free_interrupts()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
We're moving away from public functions that take struct gpio_chip as argument as the chip - unlike struct gpio_device - is owned by its provider and tied to its lifetime.
Provide an alternative to acpi_gpiochip_free_interrupts().
--- drivers/gpio/gpiolib-acpi.c | 29 +++++++++++++++++++++++------ include/linux/gpio/driver.h | 12 ++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib-acpi.c +23 -6
@@ -558,12 +558,9 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) }EXPORT_SYMBOL_GPL (acpi_gpiochip_request_interrupts); -/** -* acpi_gpiochip_free_interrupts() - Free GPIO ACPI event interrupts. -* @chip: GPIO chip -* -* Free interrupts associated with GPIO ACPI event method for the given -* GPIO chip. +/* +* This function is deprecated, use acpi_gpio_device_free_interrupts() +* instead. */ void acpi_gpiochip_free_interrupts (struct gpio_chip *chip) {
@@ -604,6 +601,26 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) }EXPORT_SYMBOL_GPL (acpi_gpiochip_free_interrupts); +/** +* acpi_gpio_device_free_interrupts() - Free GPIO ACPI event interrupts. +* @chip GPIO device +* +* Free interrupts associated with GPIO ACPI event method for the given +* GPIO device. +*/ +void acpi_gpio_device_free_interrupts (struct gpio_device *gdev) +{ +struct gpio_chip *gc; + +/* TODO: protect gdev->chip once SRCU is in place in GPIOLIB. */ + gc = gdev->chip; +if (!gc) +return ; + +acpi_gpiochip_free_interrupts (gc); +} +EXPORT_SYMBOL_GPL (acpi_gpio_device_free_interrupts); +int acpi_dev_add_driver_gpios (struct acpi_device *adev,const struct acpi_gpio_mapping *gpios) {
include/linux/gpio/driver.h +12 -0
@@ -835,4 +835,16 @@ static inline struct fwnode_handle *gpiochip_node_get_first(struct device *dev) return NULL; } +/* +* FIXME: Remove this once the only driver that uses it - android tablets - +* becomes a good citizen and stops abusing GPIOLIB. +*/ +#ifdef CONFIG_ACPI +void acpi_gpio_device_free_interrupts (struct gpio_device *gdev); +#else +static inline void acpi_gpio_device_free_interrupts (struct gpio_device *gdev) +{ +} +#endif +#endif /* __LINUX_GPIO_DRIVER_H */
Signature · 1 line
2.39.2
PATCH 9/21 gpiolib: reluctantly provide gpio_device_get_chip()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
The process of converting all unauthorized users of struct gpio_chip to using dedicated struct gpio_device function will be long so in the meantime we must provide a way of retrieving the pointer to struct gpio_chip from a GPIO device.
--- drivers/gpio/gpiolib.c | 18 ++++++++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 19 insertions(+)
drivers/gpio/gpiolib.c +18 -0
@@ -246,6 +246,24 @@ int gpio_device_get_base(struct gpio_device *gdev) }EXPORT_SYMBOL_GPL (gpio_device_get_base); +/** +* gpio_device_get_chip() - Get the gpio_chip implementation of this GPIO device +* @gdev: GPIO device +* +* Until we can get rid of all non-driver users struct gpio_chip, we must +* provide a way of retrieving the pointer to it from struct gpio_device. This +* is *NOT* safe as the GPIO API is considered to be hot-unpluggable and the +* chip can dissapear at any moment (unlike reference-counted struct +* gpio_device). +* +* Use at your own risk. +*/ +struct gpio_chip *gpio_device_get_chip (struct gpio_device *gdev) +{ +return gdev->chip; +} +EXPORT_SYMBOL_GPL (gpio_device_get_chip); +/* dynamic allocation of GPIOs, e.g. on a hotplugged device */ static int gpiochip_find_base (int ngpio) {
include/linux/gpio/driver.h +1 -0
@@ -782,6 +782,7 @@ struct gpio_device *gpiod_to_device(struct gpio_desc *desc);/* struct gpio_device getters */ int gpio_device_get_base (struct gpio_device *gdev); +struct gpio_chip *gpio_device_get_chip (struct gpio_device *gdev);#else /* CONFIG_GPIOLIB */
Signature · 1 line
2.39.2
PATCH 10/21 gpiolib: replace find_chip_by_name() with gpio_device_find_by_label()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Remove all remaining uses of find_chip_by_name() (and subsequently:gpiochip_find()) from gpiolib.c and use the new gpio_device_find_by_label() instead.
--- drivers/gpio/gpiolib.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)
drivers/gpio/gpiolib.c +12 -24
@@ -1161,18 +1161,6 @@ struct gpio_device *gpio_device_find_by_label(const char *label) }EXPORT_SYMBOL_GPL (gpio_device_find_by_label); -static int gpiochip_match_name (struct gpio_chip *gc,void *data) -{ -const char *name = data; - -return !strcmp (gc->label, name); -} - -static struct gpio_chip *find_chip_by_name (const char *name) -{ -return gpiochip_find ((void *)name, gpiochip_match_name); -} -/** * gpio_device_get() - Increase the reference count of this GPIO device * @gdev: GPIO device to increase the refcount for
@@ -3924,21 +3912,22 @@ EXPORT_SYMBOL_GPL(gpiod_remove_lookup_table);*/ void gpiod_add_hogs (struct gpiod_hog *hogs) { -struct gpio_chip *gc;struct gpiod_hog *hog;mutex_lock (&gpio_machine_hogs_mutex);for (hog = &hogs[0 ]; hog->chip_label; hog++) { + struct gpio_device *gdev __free(gpio_device_put) = NULL; +list_add_tail (&hog->list, &gpio_machine_hogs);/* * The chip may have been registered earlier, so check if it * exists and, if so, try to hog the line now. */ - gc =find_chip_by_name (hog->chip_label); -if (gc) -gpiochip_machine_hog (gc, hog); + gdev =gpio_device_find_by_label (hog->chip_label); +if (gdev) +gpiochip_machine_hog (gdev->chip, hog); }mutex_unlock (&gpio_machine_hogs_mutex);
@@ -3999,7 +3988,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,return desc;for (p = &table->table[0 ]; p->key; p++) { -struct gpio_chip *gc; + struct gpio_device *gdev __free(gpio_device_put) = NULL;/* idx must always match exactly */ if (p->idx != idx)
@@ -4021,9 +4010,8 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,return ERR_PTR (-EPROBE_DEFER ); } - gc =find_chip_by_name (p->key); - -if (!gc) { + gdev =gpio_device_find_by_label (p->key); +if (!gdev) {/* * As the lookup table indicates a chip with * p->key should exist, assume it may
@@ -4036,15 +4024,15 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,return ERR_PTR (-EPROBE_DEFER ); } -if (gc->ngpio <= p->chip_hwnum) { +if (gdev->chip->ngpio <= p->chip_hwnum) {dev_err (dev,"requested GPIO %u (%u) is out of range [0..%u] for chip %s\n" , - idx, p->chip_hwnum, gc->ngpio -1 , - gc->label); + idx, p->chip_hwnum, gdev->chip->ngpio -1 , + gdev->chip->label);return ERR_PTR (-EINVAL ); } - desc =gpiochip_get_desc (gc, p->chip_hwnum); + desc =gpiochip_get_desc (gdev->chip, p->chip_hwnum); *flags = p->flags;return desc;
Signature · 1 line
2.39.2
PATCH 11/21 platform: x86: android-tablets: don't access GPIOLIB private members
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
We're slowly removing cases of abuse of the GPIOLIB public API. One of the biggest issues is looking up and accessing struct gpio_chip whose life-time is tied to the provider and which can disappear from under any user at any given moment. We have provided new interfaces that use the opaque struct gpio_device which is reference counted and will soon be thorougly protected with appropriate locking.
Stop using old interfaces in this driver and switch to safer alternatives.
--- .../platform/x86/x86-android-tablets/core.c | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-)
drivers/platform/x86/x86-android-tablets/core.c +20 -18
@@ -12,6 +12,7 @@#include <linux/acpi.h> #include <linux/dmi.h> +#include <linux/gpio/consumer.h> #include <linux/gpio/driver.h> #include <linux/gpio/machine.h> #include <linux/irq.h>
@@ -21,27 +22,28 @@#include <linux/string.h> #include "x86-android-tablets.h" -/* For gpiochip_get_desc() which is EXPORT_SYMBOL_GPL() */ -#include "../../../gpio/gpiolib.h" -#include "../../../gpio/gpiolib-acpi.h" - -static int gpiochip_find_match_label (struct gpio_chip *gc,void *data) -{ -return gc->label && !strcmp (gc->label, data); -}int x86_android_tablet_get_gpiod (const char *label,int pin,struct gpio_desc **desc) { +struct gpio_device *gdev;struct gpio_desc *gpiod; -struct gpio_chip *chip; - chip =gpiochip_find ((void *)label, gpiochip_find_match_label); -if (!chip) { -pr_err ("error cannot find GPIO chip %s\n" , label); +/* +* FIXME: handle GPIOs correctly! This driver should really use struct +* device and GPIO lookup tables. +* +* WONTDO: We do leak this reference, but the whole approach to getting +* GPIOs in this driver is such an abuse of the GPIOLIB API that it +* doesn't make it much worse and it's the only way to keep the +* interrupt requested later functional... +*/ + gdev =gpio_device_find_by_label (label); +if (!gdev) { +pr_err ("error cannot find GPIO device %s\n" , label);return -ENODEV ; } - gpiod =gpiochip_get_desc (chip, pin); + gpiod =gpio_device_get_desc (gdev, pin);if (IS_ERR (gpiod)) {pr_err ("error %ld getting GPIO %s %d\n" ,PTR_ERR (gpiod), label, pin);return PTR_ERR (gpiod);
@@ -257,9 +259,9 @@ static void x86_android_tablet_cleanup(void)static __init int x86_android_tablet_init (void ) { + struct gpio_device *gdev __free(gpio_device_put) = NULL;const struct x86_dev_info *dev_info;const struct dmi_system_id *id; -struct gpio_chip *chip;int i, ret =0 ; id =dmi_first_match (x86_android_tablet_ids);
@@ -273,13 +275,13 @@ static __init int x86_android_tablet_init(void)* _AEI (ACPI Event Interrupt) handlers, disable these. */ if (dev_info->invalid_aei_gpiochip) { - chip =gpiochip_find (dev_info->invalid_aei_gpiochip, - gpiochip_find_match_label); -if (!chip) { + gdev =gpio_device_find_by_label ( + dev_info->invalid_aei_gpiochip); +if (!gdev) {pr_err ("error cannot find GPIO chip %s\n" , dev_info->invalid_aei_gpiochip);return -ENODEV ; } -acpi_gpiochip_free_interrupts (chip); +acpi_gpio_device_free_interrupts (gdev); }/*
Signature · 1 line
2.39.2
PATCH 12/21 hte: allow building modules with COMPILE_TEST enabled
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Allow building all HTE modules with COMPILE_TEST Kconfig option enabled.
--- drivers/hte/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hte/Kconfig +2 -2
@@ -16,7 +16,7 @@ if HTE config HTE_TEGRA194 tristate "NVIDIA Tegra194 HTE Support" - depends on ARCH_TEGRA_194_SOC + depends on (ARCH_TEGRA_194_SOC || COMPILE_TEST) help Enable this option for integrated hardware timestamping engine also known as generic timestamping engine (GTE) support on NVIDIA Tegra194
@@ -25,7 +25,7 @@ config HTE_TEGRA194 config HTE_TEGRA194_TEST tristate "NVIDIA Tegra194 HTE Test" - depends on HTE_TEGRA194 + depends on (HTE_TEGRA194 || COMPILE_TEST) help The NVIDIA Tegra194 GTE test driver demonstrates how to use HTE framework to timestamp GPIO and LIC IRQ lines.
Signature · 1 line
2.39.2
PATCH 13/21 hte: tegra194: improve the GPIO-related comment
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Using any of the GPIO interfaces using the global numberspace is deprecated. Make it clear in the comment.
--- drivers/hte/hte-tegra194.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/hte/hte-tegra194.c +8 -5
@@ -407,12 +407,15 @@ static int tegra_hte_line_xlate(struct hte_chip *gc,return -EINVAL ;/* +* GPIO consumers can access GPIOs in two ways: * -* There are two paths GPIO consumers can take as follows: -* 1) The consumer (gpiolib-cdev for example) which uses GPIO global -* number which gets assigned run time. -* 2) The consumer passing GPIO from the DT which is assigned -* statically for example by using TEGRA194_AON_GPIO gpio DT binding. +* 1) Using the global GPIO numberspace. +* +* This is the old, now DEPRECATED method and should not be used in +* new code. TODO: Check if tegra is even concerned by this. +* +* 2) Using GPIO descriptors that can be assigned to consumer devices +* using device-tree, ACPI or lookup tables. * * The code below addresses both the consumer use cases and maps into * HTE/GTE namespace.
Signature · 1 line
2.39.2
PATCH 14/21 hte: tegra194: don't access struct gpio_chip
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Using struct gpio_chip is not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted struct gpio_device and its dedicated accessors.
--- drivers/hte/hte-tegra194.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)
drivers/hte/hte-tegra194.c +23 -13
@@ -132,7 +132,7 @@ struct tegra_hte_soc {const struct tegra_hte_data *prov_data;struct tegra_hte_line_data *line_data;struct hte_chip *chip; -struct gpio_chip *c; +struct gpio_device *gdev;void __iomem *regs; };
@@ -421,7 +421,7 @@ static int tegra_hte_line_xlate(struct hte_chip *gc,* HTE/GTE namespace. */ if (gs->prov_data->type ==HTE_TEGRA_TYPE_GPIO && !args) { - line_id = desc->attr.line_id - gs->c->base; + line_id = desc->attr.line_id -gpio_device_get_base (gs->gdev); map = gs->prov_data->map; map_sz = gs->prov_data->map_sz; }else if (gs->prov_data->type ==HTE_TEGRA_TYPE_GPIO && args) {
@@ -643,12 +643,15 @@ static irqreturn_t tegra_hte_isr(int irq, void *dev_id)static bool tegra_hte_match_from_linedata (const struct hte_chip *chip,const struct hte_ts_desc *hdesc) { + struct gpio_device *gdev __free(gpio_device_put) = NULL;struct tegra_hte_soc *hte_dev = chip->data;if (!hte_dev || (hte_dev->prov_data->type !=HTE_TEGRA_TYPE_GPIO ))return false; -return hte_dev->c ==gpiod_to_chip (hdesc->attr.line_data); + gdev =gpiod_to_device (hdesc->attr.line_data); + +return hte_dev->gdev == gdev; }static const struct of_device_id tegra_hte_of_match[] = {
@@ -676,16 +679,18 @@ static void tegra_gte_disable(void *data)tegra_hte_writel (gs,HTE_TECTRL ,0 ); } -static int tegra_get_gpiochip_from_name (struct gpio_chip *chip,void *data) -{ -return !strcmp (chip->label, data); -} -static int tegra_gpiochip_match (struct gpio_chip *chip,void *data) {return chip->fwnode ==of_node_to_fwnode (data); } +static void tegra_hte_put_gpio_device (void *data) +{ +struct gpio_device *gdev = data; + +gpio_device_put (gdev); +} +static int tegra_hte_probe (struct platform_device *pdev) {int ret;
@@ -763,8 +768,8 @@ static int tegra_hte_probe(struct platform_device *pdev)if (of_device_is_compatible (dev->of_node,"nvidia,tegra194-gte-aon" )) { - hte_dev->c =gpiochip_find ("tegra194-gpio-aon" , - tegra_get_gpiochip_from_name); + hte_dev->gdev = +gpio_device_find_by_label ("tegra194-gpio-aon" ); }else { gpio_ctrl = of_parse_phandle(dev->of_node, "nvidia,gpio-controller",
@@ -775,14 +780,19 @@ static int tegra_hte_probe(struct platform_device *pdev)return -ENODEV ; } - hte_dev->c =gpiochip_find (gpio_ctrl, - tegra_gpiochip_match); + hte_dev->gdev =gpio_device_find (gpio_ctrl, + tegra_gpiochip_match);of_node_put (gpio_ctrl); } -if (!hte_dev->c) +if (!hte_dev->gdev)return dev_err_probe (dev, -EPROBE_DEFER ,"wait for gpio controller\n" ); + + ret =devm_add_action_or_reset (dev, tegra_hte_put_gpio_device, + hte_dev->gdev); +if (ret) +return ret; } hte_dev->chip = gc;
Signature · 1 line
2.39.2
PATCH 15/21 arm: omap1: ams-delta: stop using gpiochip_find()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
gpiochip_find() is going away as it's not hot-unplug safe. This platform is not affected by any of the related problems as this GPIO controller cannot really go away but in order to finally remove this function, we need to convert it to using gpio_device_find() as well.
--- arch/arm/mach-omap1/board-ams-delta.c | 36 +++++++++++++-------------- 1 file changed, 17 insertions(+), 19 deletions(-)
arch/arm/mach-omap1/board-ams-delta.c +17 -19
@@ -560,22 +560,6 @@ static struct gpiod_lookup_table *ams_delta_gpio_tables[] __initdata = { &ams_delta_nand_gpio_table, }; -/* -* Some drivers may not use GPIO lookup tables but need to be provided -* with GPIO numbers. The same applies to GPIO based IRQ lines - some -* drivers may even not use GPIO layer but expect just IRQ numbers. -* We could either define GPIO lookup tables then use them on behalf -* of those devices, or we can use GPIO driver level methods for -* identification of GPIO and IRQ numbers. For the purpose of the latter, -* defina a helper function which identifies GPIO chips by their labels. -*/ -static int gpiochip_match_by_label (struct gpio_chip *chip,void *data) -{ -char *label = data; - -return !strcmp (label, chip->label); -} -static struct gpiod_hog ams_delta_gpio_hogs[] = {GPIO_HOG (LATCH2_LABEL ,LATCH2_PIN_KEYBRD_DATAOUT ,"keybrd_dataout" ,GPIO_ACTIVE_HIGH ,GPIOD_OUT_LOW ),
@@ -615,14 +599,28 @@ static void __init modem_assign_irq(struct gpio_chip *chip)*/ static void __init omap_gpio_deps_init (void ) { +struct gpio_device *gdev;struct gpio_chip *chip; - chip =gpiochip_find (OMAP_GPIO_LABEL , gpiochip_match_by_label); -if (!chip) { -pr_err ("%s: OMAP GPIO chip not found\n" , __func__); +/* +* Some drivers may not use GPIO lookup tables but need to be provided +* with GPIO numbers. The same applies to GPIO based IRQ lines - some +* drivers may even not use GPIO layer but expect just IRQ numbers. +* We could either define GPIO lookup tables then use them on behalf +* of those devices, or we can use GPIO driver level methods for +* identification of GPIO and IRQ numbers. +* +* This reference will be leaked but that's alright as this device +* never goes down. +*/ + gdev =gpio_device_find_by_label (OMAP_GPIO_LABEL ); +if (!gdev) { +pr_err ("%s: OMAP GPIO device not found\n" , __func__);return ; } + chip =gpio_device_get_chip (gdev); +/* * Start with FIQ initialization as it may have to request * and release successfully each OMAP GPIO pin in turn.
Signature · 1 line
2.39.2
PATCH 16/21 gpio: of: correct notifier return codes
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
According to the comments in linux/notifier.h, the code to return when a notifications is "not for us" is NOTIFY_DONE, not NOTIFY_OK.
--- drivers/gpio/gpiolib-of.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/gpio/gpiolib-of.c +8 -8
@@ -834,14 +834,14 @@ static int of_gpio_notify(struct notifier_block *nb, unsigned long action,switch (of_reconfig_get_state_change (action, arg)) {case OF_RECONFIG_CHANGE_ADD :if (!of_property_read_bool (rd->dn,"gpio-hog" )) -return NOTIFY_OK ;/* not for us */ +return NOTIFY_DONE ;/* not for us */ if (of_node_test_and_set_flag (rd->dn,OF_POPULATED )) -return NOTIFY_OK ; +return NOTIFY_DONE ; chip =of_find_gpiochip_by_node (rd->dn->parent);if (chip ==NULL ) -return NOTIFY_OK ;/* not for us */ +return NOTIFY_DONE ;/* not for us */ ret =of_gpiochip_add_hog (chip, rd->dn);if (ret <0 ) {
@@ -850,22 +850,22 @@ static int of_gpio_notify(struct notifier_block *nb, unsigned long action,of_node_clear_flag (rd->dn,OF_POPULATED );return notifier_from_errno (ret); } -break ; +return NOTIFY_OK ;case OF_RECONFIG_CHANGE_REMOVE :if (!of_node_check_flag (rd->dn,OF_POPULATED )) -return NOTIFY_OK ;/* already depopulated */ +return NOTIFY_DONE ;/* already depopulated */ chip =of_find_gpiochip_by_node (rd->dn->parent);if (chip ==NULL ) -return NOTIFY_OK ;/* not for us */ +return NOTIFY_DONE ;/* not for us */ of_gpiochip_remove_hog (chip, rd->dn);of_node_clear_flag (rd->dn,OF_POPULATED ); -break ; +return NOTIFY_OK ; } -return NOTIFY_OK ; +return NOTIFY_DONE ; }struct notifier_block gpio_of_notifier = {
Signature · 1 line
2.39.2
PATCH 17/21 gpio: of: replace gpiochip_find_* with gpio_device_find_*
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
We're porting all users of gpiochip_find() to using gpio_device_find(). Update the OF GPIO code.
--- drivers/gpio/gpiolib-of.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/gpio/gpiolib-of.c +16 -16
@@ -127,10 +127,10 @@ static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data) chip->of_xlate (chip, gpiospec,NULL ) >=0 ; } -static struct gpio_chip *of_find_gpiochip_by_xlate ( -struct of_phandle_args *gpiospec) +static struct gpio_device * +of_find_gpio_device_by_xlate (struct of_phandle_args *gpiospec) { -return gpiochip_find (gpiospec, of_gpiochip_match_node_and_xlate); +return gpio_device_find (gpiospec, of_gpiochip_match_node_and_xlate); } static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
@@ -362,8 +362,8 @@ static void of_gpio_flags_quirks(const struct device_node *np,static struct gpio_desc *of_get_named_gpiod_flags (const struct device_node *np,const char *propname,int index,enum of_gpio_flags *flags) { + struct gpio_device *gdev __free(gpio_device_put) = NULL;struct of_phandle_args gpiospec; -struct gpio_chip *chip;struct gpio_desc *desc;int ret;
@@ -375,13 +375,13 @@ static struct gpio_desc *of_get_named_gpiod_flags(const struct device_node *np,return ERR_PTR (ret); } - chip =of_find_gpiochip_by_xlate (&gpiospec); -if (!chip) { + gdev =of_find_gpio_device_by_xlate (&gpiospec); +if (!gdev) { desc =ERR_PTR (-EPROBE_DEFER ); goto out; } - desc =of_xlate_and_get_gpiod_flags (chip, &gpiospec, flags); + desc =of_xlate_and_get_gpiod_flags (gdev->chip, &gpiospec, flags);if (IS_ERR (desc)) goto out;
@@ -813,16 +813,16 @@ static int of_gpiochip_match_node(struct gpio_chip *chip, void *data)return device_match_of_node (&chip->gpiodev->dev, data); } -static struct gpio_chip *of_find_gpiochip_by_node (struct device_node *np) +static struct gpio_device *of_find_gpio_device_by_node (struct device_node *np) { -return gpiochip_find (np, of_gpiochip_match_node); +return gpio_device_find (np, of_gpiochip_match_node); }static int of_gpio_notify (struct notifier_block *nb,unsigned long action,void *arg) { + struct gpio_device *gdev __free(gpio_device_put) = NULL;struct of_reconfig_data *rd = arg; -struct gpio_chip *chip;int ret;/*
@@ -839,11 +839,11 @@ static int of_gpio_notify(struct notifier_block *nb, unsigned long action,if (of_node_test_and_set_flag (rd->dn,OF_POPULATED ))return NOTIFY_DONE ; - chip =of_find_gpiochip_by_node (rd->dn->parent); -if (chip ==NULL ) + gdev =of_find_gpio_device_by_node (rd->dn->parent); +if (!gdev)return NOTIFY_DONE ;/* not for us */ - ret =of_gpiochip_add_hog (chip, rd->dn); + ret =of_gpiochip_add_hog (gdev->chip, rd->dn);if (ret <0 ) {pr_err ("%s: failed to add hogs for %pOF\n" , __func__, rd->dn);
@@ -856,11 +856,11 @@ static int of_gpio_notify(struct notifier_block *nb, unsigned long action,if (!of_node_check_flag (rd->dn,OF_POPULATED ))return NOTIFY_DONE ;/* already depopulated */ - chip =of_find_gpiochip_by_node (rd->dn->parent); -if (chip ==NULL ) + gdev =of_find_gpio_device_by_node (rd->dn->parent); +if (!gdev)return NOTIFY_DONE ;/* not for us */ -of_gpiochip_remove_hog (chip, rd->dn); +of_gpiochip_remove_hog (gdev->chip, rd->dn);of_node_clear_flag (rd->dn,OF_POPULATED );return NOTIFY_OK ; }
Signature · 1 line
2.39.2
PATCH 18/21 gpio: acpi: replace gpiochip_find() with gpio_device_find()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
We're porting all users of gpiochip_find() to using gpio_device_find(). Update the ACPI GPIO code.
--- drivers/gpio/gpiolib-acpi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib-acpi.c +4 -4
@@ -143,7 +143,7 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)*/ static struct gpio_desc *acpi_get_gpiod (char *path,unsigned int pin) { -struct gpio_chip *chip; + struct gpio_device *gdev __free(gpio_device_put) = NULL;acpi_handle handle;acpi_status status;
@@ -151,11 +151,11 @@ static struct gpio_desc *acpi_get_gpiod(char *path, unsigned int pin)if (ACPI_FAILURE (status))return ERR_PTR (-ENODEV ); - chip =gpiochip_find (handle, acpi_gpiochip_find); -if (!chip) + gdev =gpio_device_find (handle, acpi_gpiochip_find); +if (!gdev)return ERR_PTR (-EPROBE_DEFER ); -return gpiochip_get_desc (chip, pin); +return gpiochip_get_desc (gdev->chip, pin); }/**
Signature · 1 line
2.39.2
PATCH 19/21 gpio: swnode: replace gpiochip_find() with gpio_device_find_by_label()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
We're porting all users of gpiochip_find() to using gpio_device_find(). Update the swnode GPIO code.
--- drivers/gpio/gpiolib-swnode.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-)
drivers/gpio/gpiolib-swnode.c +12 -17
@@ -31,31 +31,26 @@ static void swnode_format_propname(const char *con_id, char *propname,strscpy (propname,"gpios" , max_size); } -static int swnode_gpiochip_match_name (struct gpio_chip *chip,void *data) +static struct gpio_device *swnode_get_gpio_device (struct fwnode_handle *fwnode) { -return !strcmp (chip->label, data); -} +const struct software_node *gdev_node; +struct gpio_device *gdev; -static struct gpio_chip *swnode_get_chip (struct fwnode_handle *fwnode) -{ -const struct software_node *chip_node; -struct gpio_chip *chip; - - chip_node =to_software_node (fwnode); -if (!chip_node || !chip_node->name) + gdev_node =to_software_node (fwnode); +if (!gdev_node || !gdev_node->name)return ERR_PTR (-EINVAL ); - chip =gpiochip_find ((void *)chip_node->name, swnode_gpiochip_match_name); -return chip ?:ERR_PTR (-EPROBE_DEFER ); + gdev =gpio_device_find_by_label ((void *)gdev_node->name); +return gdev ?:ERR_PTR (-EPROBE_DEFER ); }struct gpio_desc *swnode_find_gpio (struct fwnode_handle *fwnode,const char *con_id,unsigned int idx,unsigned long *flags) { + struct gpio_device *gdev __free(gpio_device_put) = NULL;const struct software_node *swnode;struct fwnode_reference_args args; -struct gpio_chip *chip;struct gpio_desc *desc;char propname[32 ];/* 32 is max size of property name */ int error;
@@ -77,12 +72,12 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode,return ERR_PTR (error); } - chip =swnode_get_chip (args.fwnode); + gdev =swnode_get_gpio_device (args.fwnode);fwnode_handle_put (args.fwnode); -if (IS_ERR (chip)) -return ERR_CAST (chip); +if (IS_ERR (gdev)) +return ERR_CAST (gdev); - desc =gpiochip_get_desc (chip, args.args[0 ]); + desc =gpiochip_get_desc (gdev->chip, args.args[0 ]); *flags = args.args[1 ];/* We expect native GPIO flags */ pr_debug("%s: parsed '%s' property of node '%pfwP[%d]' - status (%d)\n",
Signature · 1 line
2.39.2
PATCH 20/21 gpio: sysfs: drop the mention of gpiochip_find() from sysfs code
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
We have removed all callers of gpiochip_find() so don't mention it in gpiolib-sysfs.c.
--- drivers/gpio/gpiolib-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib-sysfs.c +1 -1
@@ -814,7 +814,7 @@ static int __init gpiolib_sysfs_init(void)* gpiochip_sysfs_register() acquires a mutex. This is unsafe * and needs to be fixed. * -* Also it would be nice to use gpiochip_find() here so we +* Also it would be nice to use gpio_device_find() here so we * can keep gpio_chips local to gpiolib.c, but the yield of * gpio_lock prevents us from doing this. */
Signature · 1 line
2.39.2
PATCH 21/21 gpiolib: remove gpiochip_find()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
With all users of gpiochip_find() converted to using gpio_device_find(), we can now remove this function from the kernel.
--- drivers/gpio/gpiolib.c | 22 ---------------------- include/linux/gpio/driver.h | 3 --- 2 files changed, 25 deletions(-)
drivers/gpio/gpiolib.c +0 -22
@@ -1081,28 +1081,6 @@ void gpiochip_remove(struct gpio_chip *gc) }EXPORT_SYMBOL_GPL (gpiochip_remove); -/* -* FIXME: This will be removed soon. -* -* This function is depracated, don't use. -*/ -struct gpio_chip *gpiochip_find (void *data, -int (*match)(struct gpio_chip *gc, -void *data)) -{ -struct gpio_device *gdev; -struct gpio_chip *gc =NULL ; - - gdev =gpio_device_find (data, match); -if (gdev) { - gc = gdev->chip; -gpio_device_put (gdev); - } - -return gc; -} -EXPORT_SYMBOL_GPL (gpiochip_find); -/** * gpio_device_find() - find a specific GPIO device * @data: data to pass to match function
include/linux/gpio/driver.h +0 -3
@@ -603,9 +603,6 @@ int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, void *data, struct lock_class_key *lock_key, struct lock_class_key *request_key); -struct gpio_chip *gpiochip_find (void *data, -int (*match)(struct gpio_chip *gc,void *data)); -struct gpio_device *gpio_device_find (void *data,int (*match)(struct gpio_chip *gc,void *data));
Signature · 1 line
2.39.2
Re: [PATCH 08/21] gpio: acpi: provide acpi_gpio_device_free_interrupts()
In reply to Bartosz GolaszewskiHi,
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We're moving away from public functions that take struct
gpio_chipas argument as the chip - unlike structgpio_device- is owned by its provider and tied to its lifetime.Provide an alternative to
acpi_gpiochip_free_interrupts().
Looks good to me, few minor comments below.
Quoted 2 lines
Signed-off-by Bartosz Golaszewski <[email protected]>
Quoted 26 lines
--- drivers/gpio/gpiolib-acpi.c | 29 +++++++++++++++++++++++------ include/linux/gpio/driver.h | 12 ++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-)drivers/gpio/gpiolib-acpi.c +3
-6@@ -558,12 +558,9 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) }EXPORT_SYMBOL_GPL (acpi_gpiochip_request_interrupts); -/** -* acpi_gpiochip_free_interrupts() - Free GPIO ACPI event interrupts. -* @chip: GPIO chip -* -* Free interrupts associated with GPIO ACPI event method for the given -* GPIO chip. +/* +* This function is deprecated, use acpi_gpio_device_free_interrupts() +* instead. */ void acpi_gpiochip_free_interrupts (struct gpio_chip *chip) {
drivers/gpio/gpiolib-acpi.c void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) · line 606
Quoted 6 lines
drivers/gpio/gpiolib-acpi.c +3
-0@@ -604,6 +601,26 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) }EXPORT_SYMBOL_GPL (acpi_gpiochip_free_interrupts); +/** +* acpi_gpio_device_free_interrupts() - Free GPIO ACPI event interrupts. +* @chip GPIO device
Should be:
@chip: GPIO device
Quoted 25 lines
drivers/gpio/gpiolib-acpi.c +17
-0+* +* Free interrupts associated with GPIO ACPI event method for the given +* GPIO device. +*/ +void acpi_gpio_device_free_interrupts (struct gpio_device *gdev) +{ +struct gpio_chip *gc; + +/* TODO: protect gdev->chip once SRCU is in place in GPIOLIB. */ + gc = gdev->chip; +if (!gc) +return ; + +acpi_gpiochip_free_interrupts (gc); +} +EXPORT_SYMBOL_GPL (acpi_gpio_device_free_interrupts); +int acpi_dev_add_driver_gpios (struct acpi_device *adev,const struct acpi_gpio_mapping *gpios) {include/linux/gpio/driver.h +0
-0
include/linux/gpio/driver.h static inline struct fwnode_handle *gpiochip_node_get_first(struct device *dev) · line 840
Quoted 6 lines
include/linux/gpio/driver.h +3
-0@@ -835,4 +835,16 @@ static inline struct fwnode_handle *gpiochip_node_get_first(struct device *dev)return NULL ; } +/* +* FIXME: Remove this once the only driver that uses it - android tablets - +* becomes a good citizen and stops abusing GPIOLIB.
There are a acouple of more when grepping for acpi_gpiochip_free_interrupts().
I'm not entirely sure why these functions are exposed to the drivers in the first place. IMHO GPIOLIB should deal with these but perhaps there is some good reason these drivers do it...
include/linux/gpio/driver.h static inline struct fwnode_handle *gpiochip_node_get_first(struct device *dev) · line 847
Quoted 7 lines
include/linux/gpio/driver.h +7
-0+*/ +#ifdef CONFIG_ACPI +void acpi_gpio_device_free_interrupts (struct gpio_device *gdev); +#else +static inline void acpi_gpio_device_free_interrupts (struct gpio_device *gdev) +{ +}
I would put these {} to the same line:
static inline void acpi_gpio_device_free_interrupts(struct gpio_device *gdev) { }
Quoted 5 lines
include/linux/gpio/driver.h +2
-0+#endif +#endif /* __LINUX_GPIO_DRIVER_H */ Signature · 1 line
2.39.2
Re: [RFT PATCH 11/21] platform: x86: android-tablets: don't access GPIOLIB private members
In reply to Bartosz GolaszewskiHi Bartosz,
Quoted 9 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We're slowly removing cases of abuse of the GPIOLIB public API. One of the biggest issues is looking up and accessing struct
gpio_chipwhose life-time is tied to the provider and which can disappear from under any user at any given moment. We have provided new interfaces that use the opaque structgpio_devicewhich is reference counted and will soon be thorougly protected with appropriate locking.
Quoted 4 lines
Stop using old interfaces in this driver and switch to safer alternatives.
Signed-off-by Bartosz Golaszewski <[email protected]>
First of all sorry for the issues this hack-ish kernel module is causing for cleaning up gpiolib APIs.
I don't know how close a look you took at the code, so first of all let me try to briefly explain what this hackish kernel module is for:
There are some x86_64/ACPI tablets which shipped with Android as factory OS. On these tablets the device-specific (BSP style) kernel has things like the touchscreen driver simply having a hardcoded I2C bus-number + I2C client address. Combined with also hardcoded GPIO numbers (using the old number base APIs) for any GPIOs it needs.
So the original Android kernels do not need the devices to be properly described in ACPI and the ACPI tables are just one big copy and paste job from some BSP which do not accurately describe the hardware at all.
x86-android-tablets.ko identifies affected models by their DMI strings and then manually instantiates things like i2c-clients for the touchscreen, accelerometer and also other stuff. Yes this is ugly but it allows mainline kernels to run pretty well on these devices since other then the messed up ACPI tables these are pretty standard x86/ACPI tablets.
I hope this explains the hacks, now on to the problems these are causing:
Quoted 48 lines
--- .../platform/x86/x86-android-tablets/core.c | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-)drivers/platform/x86/x86-android-tablets/core.c +12
-12@@ -12,6 +12,7 @@#include <linux/acpi.h> #include <linux/dmi.h> +#include <linux/gpio/consumer.h> #include <linux/gpio/driver.h> #include <linux/gpio/machine.h> #include <linux/irq.h> @@ -21,27 +22,28 @@#include <linux/string.h> #include "x86-android-tablets.h" -/* For gpiochip_get_desc() which is EXPORT_SYMBOL_GPL() */ -#include "../../../gpio/gpiolib.h" -#include "../../../gpio/gpiolib-acpi.h" - -static int gpiochip_find_match_label (struct gpio_chip *gc,void *data) -{ -return gc->label && !strcmp (gc->label, data); -}int x86_android_tablet_get_gpiod (const char *label,int pin,struct gpio_desc **desc) { +struct gpio_device *gdev;struct gpio_desc *gpiod; -struct gpio_chip *chip; - chip =gpiochip_find ((void *)label, gpiochip_find_match_label); -if (!chip) { -pr_err ("error cannot find GPIO chip %s\n" , label); +/* +* FIXME: handle GPIOs correctly! This driver should really use struct +* device and GPIO lookup tables. +* +* WONTDO: We do leak this reference, but the whole approach to getting +* GPIOs in this driver is such an abuse of the GPIOLIB API that it +* doesn't make it much worse and it's the only way to keep the +* interrupt requested later functional... +*/ + gdev =gpio_device_find_by_label (label);
drivers/platform/x86/x86-android-tablets/core.c line 49
Quoted 10 lines
drivers/platform/x86/x86-android-tablets/core.c +3
-1+if (!gdev) { +pr_err ("error cannot find GPIO device %s\n" , label);return -ENODEV ; } - gpiod =gpiochip_get_desc (chip, pin); + gpiod =gpio_device_get_desc (gdev, pin);if (IS_ERR (gpiod)) {pr_err ("error %ld getting GPIO %s %d\n" ,PTR_ERR (gpiod), label, pin);return PTR_ERR (gpiod);
So rather then the above I think what needs to happen here (and I can hopefully make some time for that this weekend) is:
1. Have the x86-android-tablets code instantiate a "x86-android-tablets" platform-dev
2. Have the code generate a gpiod_lookup_table for all GPIOs for which it currently uses x86_android_tablet_get_gpiod() with the .dev_id set to "x86-android-tablets"
3. Use regular gpiod_get() on the "x86-android-tablets" pdev to get the desc.
I think this should solve all the issues withx86_android_tablet_get_gpiod() poking inside
gpiolib external since now it is only using
public gpiolib APIs, right ?
One question about 2. there are 2 ways to do this:
i. Have the module_init() function loop over all x86_dev_info members which will result in calling x86_android_tablet_get_gpiod() and have it generate one big gpiod_lookup_table for all GPIOs needed in one go. At which point x86_android_tablet_get_gpiod() goes away and can be directly replaced with gpiod_get() calls on the pdev.
ii. Keep x86_android_tablet_get_gpiod() and have it generate a gpiod_lookup_table with just 1 entry for the GPIO which its caller wants. Register the lookup table, do the gpiod_get() and then immediately unregister the lookup table again.
ii. Would be easier for me to implement, especially since there is also some custom (board specific) init code calling x86_android_tablet_get_gpiod() which would require some special handling for i.
OTOH I guess some people will consider ii. somewhat ugly, although AFAICT it is perfectly ok to use the gpiolib lookup APIs this way.
Can you please let me known if you are ok with ii, or if you would prefer me going with solution i. ?
That way when I can make some time to start working on this I can pick the preferred solution right away.
Quoted 19 lines
drivers/platform/x86/x86-android-tablets/core.c +2
-4@@ -257,9 +259,9 @@ static void x86_android_tablet_cleanup(void)static __init int x86_android_tablet_init (void ) { + struct gpio_device *gdev __free(gpio_device_put) = NULL;const struct x86_dev_info *dev_info;const struct dmi_system_id *id; -struct gpio_chip *chip;int i, ret =0 ; id =dmi_first_match (x86_android_tablet_ids);@@ -273,13 +275,13 @@ static __init int x86_android_tablet_init(void)* _AEI (ACPI Event Interrupt) handlers, disable these. */ if (dev_info->invalid_aei_gpiochip) { - chip =gpiochip_find (dev_info->invalid_aei_gpiochip, - gpiochip_find_match_label); -if (!chip) { + gdev = gpio_device_find_by_label(
drivers/platform/x86/x86-android-tablets/core.c static __init int x86_android_tablet_init(void) · line 287
Quoted 10 lines
drivers/platform/x86/x86-android-tablets/core.c +3
-1+ dev_info->invalid_aei_gpiochip); +if (!gdev) {pr_err ("error cannot find GPIO chip %s\n" , dev_info->invalid_aei_gpiochip);return -ENODEV ; } -acpi_gpiochip_free_interrupts (chip); +acpi_gpio_device_free_interrupts (gdev); }/*
After some recent improvements there is only 1 board left which sets dev_info->invalid_aei_gpiochip and that can easily be replaced with with adding 1 extra entry to gpiolib_acpi_quirks[] inside drivers/gpio/gpiolib-acpi.c .
So I believe the right solution here is to just remove dev_info->invalid_aei_gpiochip support for x86-android-tablets all together and then at least x86-android-tablets will no longer be making any hackish acpi_gpiochip_free_interrupts() calls.
I don't want to make any promises wrt the timing, but I should be able to prepare a set of patches which simply removes all the private gpiolib API use from x86-android-tablets, so that you don't need to workaround that in this patch series.
With some luck I can have an immutable branch with 6.6-rc1 + such a patch-series ready for you soon after 6.6-rc1 is released.
Regards,
Hans
Re: [PATCH 02/21] gpiolib: provide gpio_device_find()
In reply to Bartosz GolaszewskiQuoted 11 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is wrong and its kernel doc is misleading as the function doesn't return a reference to thegpio_chipbut just a raw pointer. The chip itself is not guaranteed to stay alive, in fact it can be deleted at any point. Also: other than GPIO drivers themselves, nobody else has any business accessinggpio_chipstructs.Provide a new
gpio_device_find()function that returns a real reference to the opaquegpio_devicestructure that is guaranteed to stay alive for as long as there are active users of it.
...
Quoted 7 lines
+/**
+ *gpio_device_find()- find a specific GPIO device
+ * @data: data to pass to match function
+ * @match: Callback function to checkgpio_chip+ * Returns:
+ * New reference to structgpio_device.
I believe this is wrong location of the Return section.
AFAIU how kernel doc uses section markers, this entire description becomes a Return(s) section. Have you tried to render man/html/pdf and see this?
Quoted 13 lines
+ * Similar to
bus_find_device(). It returns a reference to agpio_deviceas
+ * determined by a user supplied @match callback. The callback should return
+ * 0 if the device doesn't match and non-zero if it does. If the callback
+ * returns non-zero, this function will return to the caller and not iterate
+ * over any moregpio_devices.
+ *
+ * The callback takes the GPIO chip structure as argument. During the execution
+ * of the callback function the chip is protected from being freed. TODO: This
+ * actually has yet to be implemented.
+ *
+ * If the function returns non-NULL, the returned reference must be freed by
+ * the caller usinggpio_device_put().
+ */
drivers/gpio/gpiolib.c struct gpio_chip *gpiochip_find(void *data, · line 1062
Quoted 4 lines
drivers/gpio/gpiolib.c +3
-0+struct gpio_device *gpio_device_find (void *data, +int (*match)(struct gpio_chip *gc, +void *data))
One line?
Or maybe a type for it? (gpio_match_fn, for example)
Quoted 12 lines
drivers/gpio/gpiolib.c +12
-0+{ +struct gpio_device *gdev; + +guard (spinlock_irqsave)(&gpio_lock); + +list_for_each_entry (gdev, &gpio_devices, list) { +if (gdev->chip &&match (gdev->chip, data)) +return gpio_device_get (gdev); + } + +return NULL ; +}
...
include/linux/gpio/driver.h int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, · line 611
Quoted 3 lines
include/linux/gpio/driver.h +3
-0+struct gpio_device *gpio_device_find (void *data, +int (*match)(struct gpio_chip *gc, +void *data));
Ditto.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 03/21] gpiolib: provide gpio_device_find_by_label()
In reply to Bartosz GolaszewskiQuoted 5 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
By far the most common way of looking up GPIO devices is using their label. Provide a helpers for that to avoid every user implementing their own matching function.
...
Quoted 9 lines
+/**
+ *gpio_device_find_by_label()- wrapper aroundgpio_device_find()finding the
+ * GPIO device by its backing chip's label
+ * @label: Label to lookup
+ *
+ * Returns:
+ * Reference to the GPIO device or NULL. Reference must be released with+ * ``gpio_device_put``.
Out of a sudden different format to refer the function. Should be gpio_device_put(), so kernel-doc makes a hyperlink.
Quoted 1 line
+ */
So, please, render all your kernel docs and look at the end result.
...
drivers/gpio/gpiolib.c struct gpio_device *gpio_device_find(void *data, · line 1094
Quoted 1 line
drivers/gpio/gpiolib.c +1
-0+return gpio_device_find ((void *)label, gpio_chip_match_by_label);
This casting is a bit awkward... But I have no good proposal for a change.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 04/21] gpiolib: provide gpio_device_get_desc()
In reply to Bartosz GolaszewskiQuoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Getting the GPIO descriptor directly from the
gpio_chipstruct is dangerous as we don't take the reference to the underlying GPIO device. In order to start working towards removinggpiochip_get_desc(), let's provide a safer variant that works with an existing reference to structgpio_device.
...
Quoted 8 lines
+/**
+ *gpio_device_get_desc()- get the GPIO descriptor corresponding to the given
+ * hardware number for this GPIO device
+ * @gdev: GPIO device to get the descriptor from
+ * @hwnum: hardware number of the GPIO for this chip
+ *
+ * Returns:
+ * A pointer to the GPIO descriptor or ``ERR_PTR(-EINVAL)`` if no GPIO exists
The known constants can be referenced as %EINVAL.
Quoted 1 line
+ * in the given chip for the specified hardware number or ``ERR_PTR(-ENODEV)``
Ditto.
Quoted 7 lines
+ * if the underlying chip already vanished.
+ *
+ * The reference count of structgpio_deviceis *NOT* increased like when the
+ * GPIO is being requested for exclusive usage. It's up to the caller to make
+ * sure the GPIO device will stay alive together with the descriptor returned
+ * by this function.
+ */
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 06/21] gpiolib: provide gpiod_to_device()
In reply to Bartosz GolaszewskiQuoted 4 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
struct
gpio_descis opaque so provide a way for users to retrieve the underlying GPIO device.
...
Quoted 7 lines
+/**
+ *gpiod_to_device()- Return the GPIO device owning this descriptor
+ * @desc: GPIO descriptor
+ *
+ * Returns:
+ * Pointer to the opaque structgpio_deviceobject. This function does not
+ * increase the reference count ofgpio_device.
GPIO device.
Quoted 1 line
+ */
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 10/21] gpiolib: replace find_chip_by_name() with gpio_device_find_by_label()
In reply to Bartosz GolaszewskiQuoted 5 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Remove all remaining uses of
find_chip_by_name()(and subsequently:gpiochip_find()) fromgpiolib.cand use the newgpio_device_find_by_label()instead.
...
drivers/gpio/gpiolib.c static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, · line 4035
Quoted 2 lines
drivers/gpio/gpiolib.c +1
-1- desc =gpiochip_get_desc (gc, p->chip_hwnum); + desc =gpiochip_get_desc (gdev->chip, p->chip_hwnum);
Why not gpio_device_get_desc()?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFT PATCH 11/21] platform: x86: android-tablets: don't access GPIOLIB private members
In reply to Hans de GoedeQuoted 45 lines · Hans de Goede
Hi Bartosz,
Quoted 9 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We're slowly removing cases of abuse of the GPIOLIB public API. One of the biggest issues is looking up and accessing struct
gpio_chipwhose life-time is tied to the provider and which can disappear from under any user at any given moment. We have provided new interfaces that use the opaque structgpio_devicewhich is reference counted and will soon be thorougly protected with appropriate locking.Quoted 4 lines
Stop using old interfaces in this driver and switch to safer alternatives.
Signed-off-by Bartosz Golaszewski <[email protected]>First of all sorry for the issues this hack-ish kernel module is causing for cleaning up gpiolib APIs.
I don't know how close a look you took at the code, so first of all let me try to briefly explain what this hackish kernel module is for:
There are some x86_64/ACPI tablets which shipped with Android as factory OS. On these tablets the device-specific (BSP style) kernel has things like the touchscreen driver simply having a hardcoded I2C bus-number + I2C client address. Combined with also hardcoded GPIO numbers (using the old number base APIs) for any GPIOs it needs.
So the original Android kernels do not need the devices to be properly described in ACPI and the ACPI tables are just one big copy and paste job from some BSP which do not accurately describe the hardware at all.
x86-android-tablets.ko identifies affected models by their DMI strings and then manually instantiates things like i2c-clients for the touchscreen, accelerometer and also other stuff. Yes this is ugly but it allows mainline kernels to run pretty well on these devices since other then the messed up ACPI tables these are pretty standard x86/ACPI tablets.
Quoted 2 lines
I hope this explains the hacks, now on to the problems these are causing:
This makes sense! Maybe we'd need a good-old board file setting up all non-described devices using the driver model?
Quoted 98 lines
Quoted 49 lines
--- .../platform/x86/x86-android-tablets/core.c | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-)drivers/platform/x86/x86-android-tablets/core.c +12
-12@@ -12,6 +12,7 @@#include <linux/acpi.h> #include <linux/dmi.h> +#include <linux/gpio/consumer.h> #include <linux/gpio/driver.h> #include <linux/gpio/machine.h> #include <linux/irq.h> @@ -21,27 +22,28 @@#include <linux/string.h> #include "x86-android-tablets.h" -/* For gpiochip_get_desc() which is EXPORT_SYMBOL_GPL() */ -#include "../../../gpio/gpiolib.h" -#include "../../../gpio/gpiolib-acpi.h" - -static int gpiochip_find_match_label (struct gpio_chip *gc,void *data) -{ -return gc->label && !strcmp (gc->label, data); -}int x86_android_tablet_get_gpiod (const char *label,int pin,struct gpio_desc **desc) { +struct gpio_device *gdev;struct gpio_desc *gpiod; -struct gpio_chip *chip; - chip =gpiochip_find ((void *)label, gpiochip_find_match_label); -if (!chip) { -pr_err ("error cannot find GPIO chip %s\n" , label); +/* +* FIXME: handle GPIOs correctly! This driver should really use struct +* device and GPIO lookup tables. +* +* WONTDO: We do leak this reference, but the whole approach to getting +* GPIOs in this driver is such an abuse of the GPIOLIB API that it +* doesn't make it much worse and it's the only way to keep the +* interrupt requested later functional... +*/ + gdev =gpio_device_find_by_label (label);drivers/platform/x86/x86-android-tablets/core.c line 49
Quoted 10 lines
drivers/platform/x86/x86-android-tablets/core.c +3
-1+if (!gdev) { +pr_err ("error cannot find GPIO device %s\n" , label);return -ENODEV ; } - gpiod =gpiochip_get_desc (chip, pin); + gpiod =gpio_device_get_desc (gdev, pin);if (IS_ERR (gpiod)) {pr_err ("error %ld getting GPIO %s %d\n" ,PTR_ERR (gpiod), label, pin);return PTR_ERR (gpiod);So rather then the above I think what needs to happen here (and I can hopefully make some time for that this weekend) is:
1. Have the x86-android-tablets code instantiate a "x86-android-tablets" platform-dev
2. Have the code generate agpiod_lookup_tablefor all GPIOs for which it currently usesx86_android_tablet_get_gpiod()with the .dev_id set to "x86-android-tablets"
3. Use regulargpiod_get()on the "x86-android-tablets" pdev to get the desc.I think this should solve all the issues with
x86_android_tablet_get_gpiod()poking inside
gpiolib external since now it is only using
public gpiolib APIs, right ?One question about 2. there are 2 ways to do this:
i. Have the
module_init()function loop over allx86_dev_infomembers which will result in callingx86_android_tablet_get_gpiod()and have it generate one biggpiod_lookup_tablefor all GPIOs needed in one go. At which pointx86_android_tablet_get_gpiod()goes away and can be directly replaced withgpiod_get()calls on the pdev.ii. Keep
x86_android_tablet_get_gpiod()and have it generate agpiod_lookup_tablewith just 1 entry for the GPIO which its caller wants. Register the lookup table, do thegpiod_get()and then immediately unregister the lookup table again.ii. Would be easier for me to implement, especially since there is also some custom (board specific) init code calling
x86_android_tablet_get_gpiod()which would require some special handling for i.
Quoted 7 lines
OTOH I guess some people will consider ii. somewhat ugly, although AFAICT it is perfectly ok to use the gpiolib lookup APIs this way.
Can you please let me known if you are ok with ii, or if you would prefer me going with solution i. ?
I am fine with ii. I have recently sent a patch that does exactly that in one of the SPI drivers. It's ugly but it's better than what we have now.
Quoted 45 lines
That way when I can make some time to start working on this I can pick the preferred solution right away.
Quoted 19 lines
drivers/platform/x86/x86-android-tablets/core.c +2
-4@@ -257,9 +259,9 @@ static void x86_android_tablet_cleanup(void)static __init int x86_android_tablet_init (void ) { + struct gpio_device *gdev __free(gpio_device_put) = NULL;const struct x86_dev_info *dev_info;const struct dmi_system_id *id; -struct gpio_chip *chip;int i, ret =0 ; id =dmi_first_match (x86_android_tablet_ids);@@ -273,13 +275,13 @@ static __init int x86_android_tablet_init(void)* _AEI (ACPI Event Interrupt) handlers, disable these. */ if (dev_info->invalid_aei_gpiochip) { - chip =gpiochip_find (dev_info->invalid_aei_gpiochip, - gpiochip_find_match_label); -if (!chip) { + gdev = gpio_device_find_by_label(drivers/platform/x86/x86-android-tablets/core.c static __init int x86_android_tablet_init(void) · line 287
Quoted 10 lines
drivers/platform/x86/x86-android-tablets/core.c +3
-1+ dev_info->invalid_aei_gpiochip); +if (!gdev) {pr_err ("error cannot find GPIO chip %s\n" , dev_info->invalid_aei_gpiochip);return -ENODEV ; } -acpi_gpiochip_free_interrupts (chip); +acpi_gpio_device_free_interrupts (gdev); }/* After some recent improvements there is only 1 board left which sets
dev_info->invalid_aei_gpiochipand that can easily be replaced with with adding 1 extra entry to gpiolib_acpi_quirks[] insidedrivers/gpio/gpiolib-acpi.c.So I believe the right solution here is to just remove
dev_info->invalid_aei_gpiochipsupport for x86-android-tablets all together and then at least x86-android-tablets will no longer be making any hackishacpi_gpiochip_free_interrupts()calls.
Quoted 9 lines
I don't want to make any promises wrt the timing, but I should be able to prepare a set of patches which simply removes all the private gpiolib API use from x86-android-tablets, so that you don't need to workaround that in this patch series.
With some luck I can have an immutable branch with 6.6-rc1 + such a patch-series ready for you soon after 6.6-rc1 is released.
That would be awesome, thanks a lot!
Quoted 6 lines
Regards,
Hans
Bart
Re: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
In reply to Bartosz GolaszewskiQuoted 5 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.
...
drivers/hte/hte-tegra194.c static irqreturn_t tegra_hte_isr(int irq, void *dev_id) · line 646
Quoted 1 line
drivers/hte/hte-tegra194.c +1
-0+ struct gpio_device *gdev __free(gpio_device_put) = NULL;
Using this requires cleanup.h to be included.
Does any of the included GPIO headers guarantee that inclusion implicitly? Even though, it's a good practice to include headers of what we are using independently if other (library) headers include them. I.o.w. we can rely only on our headers (here HTE framework related) to guarantee any inclusions implicitly.
This also applies to other users of the same construct.
...
Quoted 4 lines
static int
tegra_gpiochip_match(struct gpio_chip *chip, void *data){
returnchip->fwnode==of_node_to_fwnode(data);
}
Not sure how many users of this kind of match, but it might be useful to have it by GPIO library
gpio_device_find_by_fwnode()
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFT PATCH 15/21] arm: omap1: ams-delta: stop using gpiochip_find()
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is going away as it's not hot-unplug safe. This platform is not affected by any of the related problems as this GPIO controller cannot really go away but in order to finally remove this function, we need to convert it to usinggpio_device_find()as well.
Side question, have you used --patience when preparing this series?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 18/21] gpio: acpi: replace gpiochip_find() with gpio_device_find()
In reply to Bartosz GolaszewskiQuoted 4 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We're porting all users of
gpiochip_find()to usinggpio_device_find(). Update the ACPI GPIO code.
...
drivers/gpio/gpiolib-acpi.c static struct gpio_desc *acpi_get_gpiod(char *path, unsigned int pin) · line 158
Quoted 2 lines
drivers/gpio/gpiolib-acpi.c +1
-1-return gpiochip_get_desc (chip, pin); +return gpiochip_get_desc (gdev->chip, pin);
gpio_device_get_desc() ?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 19/21] gpio: swnode: replace gpiochip_find() with gpio_device_find_by_label()
In reply to Bartosz GolaszewskiQuoted 4 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We're porting all users of
gpiochip_find()to usinggpio_device_find(). Update the swnode GPIO code.
...
drivers/gpio/gpiolib-swnode.c static void swnode_format_propname(const char *con_id, char *propname, · line 40
Quoted 10 lines
drivers/gpio/gpiolib-swnode.c +3
-5-static int swnode_gpiochip_match_name (struct gpio_chip *chip,void *data) +static struct gpio_device *swnode_get_gpio_device (struct fwnode_handle *fwnode) { -return !strcmp (chip->label, data); -} +const struct software_node *gdev_node; +struct gpio_device *gdev; -static struct gpio_chip *swnode_get_chip (struct fwnode_handle *fwnode) -{
Not sure if you used --patience. Patches might look better.
Quoted 14 lines
drivers/gpio/gpiolib-swnode.c +4
-7-const struct software_node *chip_node; -struct gpio_chip *chip; - - chip_node =to_software_node (fwnode); -if (!chip_node || !chip_node->name) + gdev_node =to_software_node (fwnode); +if (!gdev_node || !gdev_node->name)return ERR_PTR (-EINVAL ); - chip =gpiochip_find ((void *)chip_node->name, swnode_gpiochip_match_name); -return chip ?:ERR_PTR (-EPROBE_DEFER ); + gdev =gpio_device_find_by_label ((void *)gdev_node->name); +return gdev ?:ERR_PTR (-EPROBE_DEFER ); }
...
drivers/gpio/gpiolib-swnode.c struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, · line 80
Quoted 2 lines
drivers/gpio/gpiolib-swnode.c +1
-1- desc =gpiochip_get_desc (chip, args.args[0 ]); + desc =gpiochip_get_desc (gdev->chip, args.args[0 ]);
gpio_device_get_desc() ?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 21/21] gpiolib: remove gpiochip_find()
In reply to Bartosz GolaszewskiQuoted 4 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
With all users of
gpiochip_find()converted to usinggpio_device_find(), we can now remove this function from the kernel.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFT PATCH 15/21] arm: omap1: ams-delta: stop using gpiochip_find()
In reply to Andy ShevchenkoQuoted 11 lines · Andy Shevchenko
Quoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is going away as it's not hot-unplug safe. This platform is not affected by any of the related problems as this GPIO controller cannot really go away but in order to finally remove this function, we need to convert it to usinggpio_device_find()as well.Side question, have you used --patience when preparing this series?
Yes! Thanks for bringing it to my attention.
Bart
Quoted 1 line · Bartosz Golaszewski
The GPIO subsystem does not handle hot-unplug events very well.
Yeah :/ it was never designed for this, and I've seen the discussions.
The person who made the biggest effort to make this sort-of work was actually Johan Hovold so I added him to the mail so you can include him in upcoming iterations. I think he was working with GPIO on greybus at the time. Maybe he want to take a look!
Quoted 7 lines
Before we can even get to fixing the locking, we need to address a serious abuse of the GPIO driver API - accessing struct
gpio_chipby 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. structgpio_deviceis the opaque, reference counted interface to structgpio_chip(which is the low-level implementation) and all access should pass through it.
Thanks for looking into this. As I remember I have tried to bring down this abuse over the years and IIRC it used to be even worse, it came from the fact that all GPIO drivers used to be under some arch/* tree and often loosely using the kernel GPIO API but in addition providing a custom API...
Quoted 2 lines
The end-goal is to make all
gpio_devicemanipulators check the existence ofgdev->chipand then lock it for the duration of any of the calls using SRCU.
Excellent!
Quoted 4 lines
This series starts the process by replacing
gpiochip_find()withgpio_device_find(). This is in line with otherdevice_findtype interfaces and returns a reference to the GPIO device that is guaranteed to remain valid until it is put.
I agree with the direction and I see no major problem with the patches other than some testing and cosmetics. The kernel sure as hell looks better *after* this than *before* so once you have rough confidence in the patches I think they should be merged and any issuse fixed up in-tree so we get wider audience and can continue the planned refactorings. So:
I'll try to provide some detailed reviews if something stands out.
Yours,
Linus Walleij
Re: [PATCH 01/21] gpiolib: make gpio_device_get() and gpio_device_put() public
In reply to Bartosz GolaszewskiQuoted 8 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
In order to start migrating away from accessing struct
gpio_chipby users other than their owners, let's first make the reference management functions for the opaque structgpio_devicepublic in thedriver.hheader.Signed-off-by Bartosz Golaszewski <[email protected]>
Yours,
Linus Walleij
Re: [PATCH 02/21] gpiolib: provide gpio_device_find()
In reply to Bartosz GolaszewskiQuoted 8 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is wrong and its kernel doc is misleading as the function doesn't return a reference to thegpio_chipbut just a raw pointer. The chip itself is not guaranteed to stay alive, in fact it can be deleted at any point. Also: other than GPIO drivers themselves, nobody else has any business accessinggpio_chipstructs.
Quoted 5 lines
Provide a new
gpio_device_find()function that returns a real reference to the opaquegpio_devicestructure that is guaranteed to stay alive for as long as there are active users of it.Signed-off-by Bartosz Golaszewski <[email protected]>
Yours,
Linus Walleij
Re: [PATCH 03/21] gpiolib: provide gpio_device_find_by_label()
In reply to Bartosz GolaszewskiQuoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
By far the most common way of looking up GPIO devices is using their label. Provide a helpers for that to avoid every user implementing their own matching function.
Signed-off-by Bartosz Golaszewski <[email protected]>
Yeah this is what everyone and their dog reimplements. Good to centralize this.
Yours,
Linus Walleij
Re: [PATCH 04/21] gpiolib: provide gpio_device_get_desc()
In reply to Bartosz GolaszewskiQuoted 9 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Getting the GPIO descriptor directly from the
gpio_chipstruct is dangerous as we don't take the reference to the underlying GPIO device. In order to start working towards removinggpiochip_get_desc(), let's provide a safer variant that works with an existing reference to structgpio_device.Signed-off-by Bartosz Golaszewski <[email protected]>
Andy had some good doc comments, with these addressed:
Yours,
Linus Walleij
Re: [PATCH 05/21] gpiolib: add support for scope-based management to gpio_device
In reply to Bartosz GolaszewskiQuoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
As the few users that need to get the reference to the GPIO device often release it right after inspecting its properties, let's add support for the automatic reference release to struct
gpio_device.Signed-off-by Bartosz Golaszewski <[email protected]>
Needless to say, I'm a strong advocate for scoped resource management.
Yours,
Linus Walleij
Re: [PATCH 06/21] gpiolib: provide gpiod_to_device()
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
struct
gpio_descis opaque so provide a way for users to retrieve the underlying GPIO device.Signed-off-by Bartosz Golaszewski <[email protected]>
Yours,
Linus Walleij
Re: [PATCH 07/21] gpiolib: provide gpio_device_get_base()
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Let's start adding getters for the opaque struct
gpio_device. Start with a function allowing to retrieve the base GPIO number.Signed-off-by Bartosz Golaszewski <[email protected]>
I guess you have a solid usecase for drivers needing to do this crazy thing, because I suppose you feel as much as me that this should rather be gpiolib-internal and confined to drivers/gpio/gpiolib.h?
If you add a valid reason for making this globally visible outside of drivers/[gpio|pinctrl] to the commit message I guess I can live with it because we need to think of the bigger picture:
It brings to mind the now confusing "base" inside of struct gpio_chip. We all know it should go away, but since it is never used during the lifetime of the gpio_chip - or SHOULD never be used - it should rather be an argument to [devm_]gpiochip_add_data( .... int base);...
Maybe something we should add to our TODO file.
Yours,
Linus Walleij
Re: [PATCH 09/21] gpiolib: reluctantly provide gpio_device_get_chip()
In reply to Bartosz GolaszewskiQuoted 8 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
The process of converting all unauthorized users of struct
gpio_chipto using dedicated structgpio_devicefunction will be long so in the meantime we must provide a way of retrieving the pointer to structgpio_chipfrom a GPIO device.Signed-off-by Bartosz Golaszewski <[email protected]>
Yeah, sigh. Maybe add a notice to drivers/gpio/TODO that this needs to happen long time.
Yours,
Linus Walleij
Re: [PATCH 10/21] gpiolib: replace find_chip_by_name() with gpio_device_find_by_label()
In reply to Bartosz GolaszewskiQuoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Remove all remaining uses of
find_chip_by_name()(and subsequently:gpiochip_find()) fromgpiolib.cand use the newgpio_device_find_by_label()instead.Signed-off-by Bartosz Golaszewski <[email protected]>
With Andy's comment addressed:
Yours,
Linus Walleij
Re: [PATCH 12/21] hte: allow building modules with COMPILE_TEST enabled
In reply to Bartosz GolaszewskiQuoted 5 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Allow building all HTE modules with
COMPILE_TESTKconfigoption enabled.Signed-off-by Bartosz Golaszewski <[email protected]>
This should be a separate patch should it not? Just send it separately to Dipen so he can merge it.
Yours,
Linus Walleij
Re: [PATCH 13/21] hte: tegra194: improve the GPIO-related comment
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using any of the GPIO interfaces using the global numberspace is deprecated. Make it clear in the comment.
Signed-off-by Bartosz Golaszewski <[email protected]>
Split this off and send separately to Dipen.
Yours,
Linus Walleij
Re: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
In reply to Bartosz GolaszewskiQuoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>
As Andy points out add <linux/cleanup.h>, with that fixed:
I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus Walleij
Re: [RFT PATCH 15/21] arm: omap1: ams-delta: stop using gpiochip_find()
In reply to Bartosz GolaszewskiQuoted 8 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is going away as it's not hot-unplug safe. This platform is not affected by any of the related problems as this GPIO controller cannot really go away but in order to finally remove this function, we need to convert it to usinggpio_device_find()as well.Signed-off-by Bartosz Golaszewski <[email protected]>
I was cleaning this one just some merge cycle ago, now it looks even better!
Yours,
Linus Walleij
Re: [PATCH 12/21] hte: allow building modules with COMPILE_TEST enabled
In reply to Linus WalleijQuoted 7 lines · Linus Walleij
Quoted 4 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Allow building all HTE modules with
COMPILE_TESTKconfigoption enabled.
Quoted 8 lines
Quoted 1 line
Signed-off-by Bartosz Golaszewski <[email protected]>This should be a separate patch should it not? Just send it separately to Dipen so he can merge it.
Acked-by Linus Walleij <[email protected]>Yours,
Linus Walleij
Dipen,
Can you just pick this up and the other patch addressing a comment in a HTE driver separately? Would spare a resend to the list and I'd drop it from the series.
Bart
Re: [RFT PATCH 15/21] arm: omap1: ams-delta: stop using gpiochip_find()
In reply to Bartosz GolaszewskiOops one more note:
Quoted 8 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is going away as it's not hot-unplug safe. This platform is not affected by any of the related problems as this GPIO controller cannot really go away but in order to finally remove this function, we need to convert it to usinggpio_device_find()as well.Signed-off-by Bartosz Golaszewski <[email protected]>
(...)
Quoted 1 line
+ struct
gpio_device*gdev;
(...)
Quoted 1 line
+ gdev =
gpio_device_find_by_label(OMAP_GPIO_LABEL);
This leaves a reference to the gdev right? No scoped guard?
If you leave a dangling reference intentionally I think it warrants a comment ("leaving a ref here so the device will never be free:ed").
Yours,
Linus Walleij
Re: [PATCH 16/21] gpio: of: correct notifier return codes
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
According to the comments in
linux/notifier.h, the code to return when a notifications is "not for us" isNOTIFY_DONE, notNOTIFY_OK.Signed-off-by Bartosz Golaszewski <[email protected]>
This should just be applied, right? If the notifiers already went upstream (sorry for my ignorance) then it should be a Fixes: even.
Yours,
Linus Walleij
Re: [PATCH 17/21] gpio: of: replace gpiochip_find_* with gpio_device_find_*
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We're porting all users of
gpiochip_find()to usinggpio_device_find(). Update the OF GPIO code.Signed-off-by Bartosz Golaszewski <[email protected]>
Re: [PATCH 17/21] gpio: of: replace gpiochip_find_* with gpio_device_find_*
In reply to Bartosz Golaszewski(Sorry for fatfinger reply)
Quoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We're porting all users of
gpiochip_find()to usinggpio_device_find(). Update the OF GPIO code.Signed-off-by Bartosz Golaszewski <[email protected]>
Scoped guards, nice!
Yours,
Linus Walleij
Re: [PATCH 18/21] gpio: acpi: replace gpiochip_find() with gpio_device_find()
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We're porting all users of
gpiochip_find()to usinggpio_device_find(). Update the ACPI GPIO code.Signed-off-by Bartosz Golaszewski <[email protected]>
With Andy's comment addressed:
Yours,
Linus Walleij
Re: [PATCH 19/21] gpio: swnode: replace gpiochip_find() with gpio_device_find_by_label()
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We're porting all users of
gpiochip_find()to usinggpio_device_find(). Update the swnode GPIO code.Signed-off-by Bartosz Golaszewski <[email protected]>
With Andy's comment addressed:
Yours,
Linus Walleij
Re: [PATCH 20/21] gpio: sysfs: drop the mention of gpiochip_find() from sysfs code
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We have removed all callers of
gpiochip_find()so don't mention it ingpiolib-sysfs.c.Signed-off-by Bartosz Golaszewski <[email protected]>
Yours,
Linus Walleij
Re: [PATCH 21/21] gpiolib: remove gpiochip_find()
In reply to Bartosz GolaszewskiQuoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
With all users of
gpiochip_find()converted to usinggpio_device_find(), we can now remove this function from the kernel.Signed-off-by Bartosz Golaszewski <[email protected]>
This is so much cleaner, and introducing some scoped guards along the way it's a clear win.
Yours,
Linus Walleij
Re: [PATCH 07/21] gpiolib: provide gpio_device_get_base()
In reply to Linus WalleijQuoted 26 lines · Linus Walleij
Quoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Let's start adding getters for the opaque struct
gpio_device. Start with a function allowing to retrieve the base GPIO number.Signed-off-by Bartosz Golaszewski <[email protected]>I guess you have a solid usecase for drivers needing to do this crazy thing, because I suppose you feel as much as me that this should rather be gpiolib-internal and confined to
drivers/gpio/gpiolib.h?If you add a valid reason for making this globally visible outside of drivers/[gpio|pinctrl] to the commit message I guess I can live with it because we need to think of the bigger picture:
Acked-by Linus Walleij <[email protected]>It brings to mind the now confusing "base" inside of struct
gpio_chip. We all know it should go away, but since it is never used during the lifetime of thegpio_chip- or SHOULD never be used - it should rather be an argument to [devm_]gpiochip_add_data( .... int base);...
Quoted 4 lines
Maybe something we should add to our TODO file.
Yours,
Linus Walleij
For this series it's the HTE driver that uses it and I don't have a good idea about how to change it. Dipen?
I would also love to make pinctrl not use the internal GPIOLIB header so it'll be another user, unless you can figure out a way to not use gc->base? :)
I think we're stuck with it for now.
Bart
Re: [RFT PATCH 15/21] arm: omap1: ams-delta: stop using gpiochip_find()
In reply to Linus WalleijQuoted 15 lines · Linus Walleij
Oops one more note:
Quoted 8 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is going away as it's not hot-unplug safe. This platform is not affected by any of the related problems as this GPIO controller cannot really go away but in order to finally remove this function, we need to convert it to usinggpio_device_find()as well.Signed-off-by Bartosz Golaszewski <[email protected]>(...)
Quoted 1 line
+ struct
gpio_device*gdev;
Quoted 9 lines
(...)
Quoted 1 line
+ gdev =
gpio_device_find_by_label(OMAP_GPIO_LABEL);This leaves a reference to the gdev right? No scoped guard?
If you leave a dangling reference intentionally I think it warrants a comment ("leaving a ref here so the device will never be free:ed").
It's right there in the comment. :)
Bart
Re: [RFT PATCH 15/21] arm: omap1: ams-delta: stop using gpiochip_find()
In reply to Linus WalleijDnia czwartek, 7 września 2023 09:31:01 CEST Linus Walleij pisze:
Quoted 9 lines · Bartosz Golaszewski
Quoted 8 lines
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is going away as it's not hot-unplug safe. This platform is not affected by any of the related problems as this GPIO controller cannot really go away but in order to finally remove this function, we need to convert it to usinggpio_device_find()as well.
Quoted 5 lines
Quoted 1 line
Signed-off-by Bartosz Golaszewski <[email protected]>I was cleaning this one just some merge cycle ago, now it looks even better!
Reviewed-by Linus Walleij <[email protected]>
Thanks,
Janusz
Quoted 4 lines
Yours,
Linus Walleij
Re: [RFT PATCH 11/21] platform: x86: android-tablets: don't access GPIOLIB private members
In reply to Bartosz GolaszewskiHi Bart,
Quoted 46 lines · Bartosz Golaszewski
Quoted 45 lines · Hans de Goede
Hi Bartosz,
Quoted 9 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We're slowly removing cases of abuse of the GPIOLIB public API. One of the biggest issues is looking up and accessing struct
gpio_chipwhose life-time is tied to the provider and which can disappear from under any user at any given moment. We have provided new interfaces that use the opaque structgpio_devicewhich is reference counted and will soon be thorougly protected with appropriate locking.Quoted 4 lines
Stop using old interfaces in this driver and switch to safer alternatives.
Signed-off-by Bartosz Golaszewski <[email protected]>First of all sorry for the issues this hack-ish kernel module is causing for cleaning up gpiolib APIs.
I don't know how close a look you took at the code, so first of all let me try to briefly explain what this hackish kernel module is for:
There are some x86_64/ACPI tablets which shipped with Android as factory OS. On these tablets the device-specific (BSP style) kernel has things like the touchscreen driver simply having a hardcoded I2C bus-number + I2C client address. Combined with also hardcoded GPIO numbers (using the old number base APIs) for any GPIOs it needs.
So the original Android kernels do not need the devices to be properly described in ACPI and the ACPI tables are just one big copy and paste job from some BSP which do not accurately describe the hardware at all.
x86-android-tablets.ko identifies affected models by their DMI strings and then manually instantiates things like i2c-clients for the touchscreen, accelerometer and also other stuff. Yes this is ugly but it allows mainline kernels to run pretty well on these devices since other then the messed up ACPI tables these are pretty standard x86/ACPI tablets.
Quoted 5 lines
Quoted 2 lines
I hope this explains the hacks, now on to the problems these are causing:
This makes sense! Maybe we'd need a good-old board file setting up all non-described devices using the driver model?
Right, this is pretty much exactly what the x86-android-tablets code does. Except that it does it for a bunch of boards in a single .ko / driver. There is a lot of commonality between these boards, so this allows sharing most of the code.
The driver uses DMI matching, with the match's driver_data pointing to a description of which devices to instantiate and then the shared code takes care of instantiating those.
About 90% of the data / code is __init or __initdata so both the code to instantiate the devices as well as the per board data is free-ed after module_init() has run.
<snip>
Quoted 41 lines
Quoted 41 lines
So rather then the above I think what needs to happen here (and I can hopefully make some time for that this weekend) is:
1. Have the x86-android-tablets code instantiate a "x86-android-tablets" platform-dev
2. Have the code generate agpiod_lookup_tablefor all GPIOs for which it currently usesx86_android_tablet_get_gpiod()with the .dev_id set to "x86-android-tablets"
3. Use regulargpiod_get()on the "x86-android-tablets" pdev to get the desc.I think this should solve all the issues with
x86_android_tablet_get_gpiod()poking inside
gpiolib external since now it is only using
public gpiolib APIs, right ?One question about 2. there are 2 ways to do this:
i. Have the
module_init()function loop over allx86_dev_infomembers which will result in callingx86_android_tablet_get_gpiod()and have it generate one biggpiod_lookup_tablefor all GPIOs needed in one go. At which pointx86_android_tablet_get_gpiod()goes away and can be directly replaced withgpiod_get()calls on the pdev.ii. Keep
x86_android_tablet_get_gpiod()and have it generate agpiod_lookup_tablewith just 1 entry for the GPIO which its caller wants. Register the lookup table, do thegpiod_get()and then immediately unregister the lookup table again.ii. Would be easier for me to implement, especially since there is also some custom (board specific) init code calling
x86_android_tablet_get_gpiod()which would require some special handling for i.OTOH I guess some people will consider ii. somewhat ugly, although AFAICT it is perfectly ok to use the gpiolib lookup APIs this way.
Quoted 7 lines
Quoted 3 lines
Can you please let me known if you are ok with ii, or if you would prefer me going with solution i. ?
I am fine with ii. I have recently sent a patch that does exactly that in one of the SPI drivers. It's ugly but it's better than what we have now.
Ok, I have just finished implementing this using the ii. method.
I'll post a patch-series for this for review right after this email.
After that series x86-android-tablets should no longer be a problem wrt using any private gpiolib APIs.
Regards,
Hans
Re: [RFT PATCH 11/21] platform: x86: android-tablets: don't access GPIOLIB private members
Quoted 2 lines · Hans de Goede
Quoted 1 line · Bartosz Golaszewski
On Wed, Sep 6, 2023 at 3:01 PM Hans de Goede <[email protected]> wrote:
...
Quoted 8 lines
Quoted 2 lines
This makes sense! Maybe we'd need a good-old board file setting up all non-described devices using the driver model?
Right, this is pretty much exactly what the x86-android-tablets code does. Except that it does it for a bunch of boards in a single .ko / driver. There is a lot of commonality between these boards, so this allows sharing most of the code.
Quoted 7 lines
The driver uses DMI matching, with the match's
driver_datapointing to a description of which devices to instantiate and then the shared code takes care of instantiating those.About 90% of the data / code is
__initor__initdataso both the code to instantiate the devices as well as the per board data is free-ed aftermodule_init()has run.
...which is nicely looked and isolated hack (or quirk if you prefer) that I like! Thanks, Hans, for maintaining that!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFT PATCH 15/21] arm: omap1: ams-delta: stop using gpiochip_find()
In reply to Janusz KrzysztofikQuoted 11 lines · Janusz Krzysztofik
Dnia czwartek, 7 września 2023 09:31:01 CEST Linus Walleij pisze:
Quoted 9 lines · Bartosz Golaszewski
Quoted 8 lines
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is going away as it's not hot-unplug safe. This platform is not affected by any of the related problems as this GPIO controller cannot really go away but in order to finally remove this function, we need to convert it to usinggpio_device_find()as well.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Bartosz Golaszewski <[email protected]>I was cleaning this one just some merge cycle ago, now it looks even better!
Reviewed-by Linus Walleij <[email protected]>
Janusz,
Is it fine if I take it through the GPIO tree?
Bartosz
Quoted 11 lines
Thanks,
JanuszQuoted 4 lines
Yours,
Linus Walleij
Re: [RFT PATCH 15/21] arm: omap1: ams-delta: stop using gpiochip_find()
Quoted 18 lines · Bartosz Golaszewski
Quoted 17 lines · Janusz Krzysztofik
Dnia czwartek, 7 września 2023 09:31:01 CEST Linus Walleij pisze:
Quoted 14 lines · Bartosz Golaszewski
Quoted 9 lines
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is going away as it's not hot-unplug safe. This platform is not affected by any of the related problems as this GPIO controller cannot really go away but in order to finally remove this function, we need to convert it to usinggpio_device_find()as well.Signed-off-by Bartosz Golaszewski <[email protected]>I was cleaning this one just some merge cycle ago, now it looks even better!
Reviewed-by Linus Walleij <[email protected]>
Quoted 6 lines
Quoted 2 lines
Janusz,
Is it fine if I take it through the GPIO tree?
Works for me at least:
Re: [PATCH 02/21] gpiolib: provide gpio_device_find()
In reply to Andy ShevchenkoQuoted 21 lines · Andy Shevchenko
Quoted 11 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is wrong and its kernel doc is misleading as the function doesn't return a reference to thegpio_chipbut just a raw pointer. The chip itself is not guaranteed to stay alive, in fact it can be deleted at any point. Also: other than GPIO drivers themselves, nobody else has any business accessinggpio_chipstructs.Provide a new
gpio_device_find()function that returns a real reference to the opaquegpio_devicestructure that is guaranteed to stay alive for as long as there are active users of it....
Quoted 4 lines
+/**
+ *gpio_device_find()- find a specific GPIO device
+ * @data: data to pass to match function
+ * @match: Callback function to checkgpio_chip
Quoted 7 lines
Quoted 2 lines
+ * Returns:
+ * New reference to structgpio_device.I believe this is wrong location of the Return section.
AFAIU how kernel doc uses section markers, this entire description becomes a Return(s) section. Have you tried to render man/html/pdf and see this?
Yes, it works just fine. Try for yourself: scripts/kernel-doc -rst drivers/gpio/gpiolib.c
Bart
Quoted 48 lines
Quoted 13 lines
+ * Similar to
bus_find_device(). It returns a reference to agpio_deviceas
+ * determined by a user supplied @match callback. The callback should return
+ * 0 if the device doesn't match and non-zero if it does. If the callback
+ * returns non-zero, this function will return to the caller and not iterate
+ * over any moregpio_devices.
+ *
+ * The callback takes the GPIO chip structure as argument. During the execution
+ * of the callback function the chip is protected from being freed. TODO: This
+ * actually has yet to be implemented.
+ *
+ * If the function returns non-NULL, the returned reference must be freed by
+ * the caller usinggpio_device_put().
+ */drivers/gpio/gpiolib.c struct gpio_chip *gpiochip_find(void *data, · line 1062
Quoted 4 lines
drivers/gpio/gpiolib.c +3
-0+struct gpio_device *gpio_device_find (void *data, +int (*match)(struct gpio_chip *gc, +void *data))One line?
Or maybe a type for it? (gpio_match_fn, for example)Quoted 12 lines
drivers/gpio/gpiolib.c +12
-0+{ +struct gpio_device *gdev; + +guard (spinlock_irqsave)(&gpio_lock); + +list_for_each_entry (gdev, &gpio_devices, list) { +if (gdev->chip &&match (gdev->chip, data)) +return gpio_device_get (gdev); + } + +return NULL ; +}...
include/linux/gpio/driver.h int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, · line 611
Quoted 3 lines
include/linux/gpio/driver.h +3
-0+struct gpio_device *gpio_device_find (void *data, +int (*match)(struct gpio_chip *gc, +void *data));Ditto.
--
With Best Regards,
Andy Shevchenko
Janusz Krzysztofik
maintainerRe: [RFT PATCH 15/21] arm: omap1: ams-delta: stop using gpiochip_find()
In reply to Bartosz GolaszewskiHi Bartosz,
Dnia poniedziałek, 11 września 2023 13:09:56 CEST Bartosz Golaszewski pisze:
Quoted 18 lines · Janusz Krzysztofik
Quoted 17 lines
Dnia czwartek, 7 września 2023 09:31:01 CEST Linus Walleij pisze:
Quoted 14 lines · Bartosz Golaszewski
Quoted 9 lines
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is going away as it's not hot-unplug safe. This platform is not affected by any of the related problems as this GPIO controller cannot really go away but in order to finally remove this function, we need to convert it to usinggpio_device_find()as well.Signed-off-by Bartosz Golaszewski <[email protected]>I was cleaning this one just some merge cycle ago, now it looks even better!
Reviewed-by Linus Walleij <[email protected]>
Quoted 6 lines
Quoted 2 lines
Janusz,
Is it fine if I take it through the GPIO tree?
Yes, should be fine, I believe. Tony, Aaro, any doubts?
Thanks,
Janusz
Quoted 15 lines
Bartosz
Quoted 11 lines
Thanks,
JanuszQuoted 4 lines
Yours,
Linus Walleij
Dipen Patel
maintainerRe: [PATCH 07/21] gpiolib: provide gpio_device_get_base()
In reply to Bartosz GolaszewskiQuoted 27 lines · Bartosz Golaszewski
Quoted 26 lines · Linus Walleij
Quoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Let's start adding getters for the opaque struct
gpio_device. Start with a function allowing to retrieve the base GPIO number.Signed-off-by Bartosz Golaszewski <[email protected]>I guess you have a solid usecase for drivers needing to do this crazy thing, because I suppose you feel as much as me that this should rather be gpiolib-internal and confined to
drivers/gpio/gpiolib.h?If you add a valid reason for making this globally visible outside of drivers/[gpio|pinctrl] to the commit message I guess I can live with it because we need to think of the bigger picture:
Acked-by Linus Walleij <[email protected]>It brings to mind the now confusing "base" inside of struct
gpio_chip. We all know it should go away, but since it is never used during the lifetime of thegpio_chip- or SHOULD never be used - it should rather be an argument to [devm_]gpiochip_add_data( .... int base);...
Quoted 7 lines
Quoted 4 lines
Maybe something we should add to our TODO file.
Yours,
Linus WalleijFor this series it's the HTE driver that uses it and I don't have a good idea about how to change it. Dipen?
Missed responding to this, apologies. I believe we are having similar discussion in the hte only patch. We can continue discussing there.
Quoted 8 lines
I would also love to make pinctrl not use the internal GPIOLIB header so it'll be another user, unless you can figure out a way to not use
gc->base? :)I think we're stuck with it for now.
Bart
Re: [RFT PATCH 15/21] arm: omap1: ams-delta: stop using gpiochip_find()
In reply to Bartosz GolaszewskiQuoted 73 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
gpiochip_find()is going away as it's not hot-unplug safe. This platform is not affected by any of the related problems as this GPIO controller cannot really go away but in order to finally remove this function, we need to convert it to usinggpio_device_find()as well.Signed-off-by Bartosz Golaszewski <[email protected]>--- arch/arm/mach-omap1/board-ams-delta.c | 36 +++++++++++++-------------- 1 file changed, 17 insertions(+), 19 deletions(-)arch/arm/mach-omap1/board-ams-delta.c +17
-20@@ -560,22 +560,6 @@ static struct gpiod_lookup_table *ams_delta_gpio_tables[] __initdata = { &ams_delta_nand_gpio_table, }; -/* -* Some drivers may not use GPIO lookup tables but need to be provided -* with GPIO numbers. The same applies to GPIO based IRQ lines - some -* drivers may even not use GPIO layer but expect just IRQ numbers. -* We could either define GPIO lookup tables then use them on behalf -* of those devices, or we can use GPIO driver level methods for -* identification of GPIO and IRQ numbers. For the purpose of the latter, -* defina a helper function which identifies GPIO chips by their labels. -*/ -static int gpiochip_match_by_label (struct gpio_chip *chip,void *data) -{ -char *label = data; - -return !strcmp (label, chip->label); -} -static struct gpiod_hog ams_delta_gpio_hogs[] = {GPIO_HOG (LATCH2_LABEL ,LATCH2_PIN_KEYBRD_DATAOUT ,"keybrd_dataout" ,GPIO_ACTIVE_HIGH ,GPIOD_OUT_LOW ),@@ -615,14 +599,28 @@ static void __init modem_assign_irq(struct gpio_chip *chip)*/ static void __init omap_gpio_deps_init (void ) { +struct gpio_device *gdev;struct gpio_chip *chip; - chip =gpiochip_find (OMAP_GPIO_LABEL , gpiochip_match_by_label); -if (!chip) { -pr_err ("%s: OMAP GPIO chip not found\n" , __func__); +/* +* Some drivers may not use GPIO lookup tables but need to be provided +* with GPIO numbers. The same applies to GPIO based IRQ lines - some +* drivers may even not use GPIO layer but expect just IRQ numbers. +* We could either define GPIO lookup tables then use them on behalf +* of those devices, or we can use GPIO driver level methods for +* identification of GPIO and IRQ numbers. +* +* This reference will be leaked but that's alright as this device +* never goes down. +*/ + gdev =gpio_device_find_by_label (OMAP_GPIO_LABEL ); +if (!gdev) { +pr_err ("%s: OMAP GPIO device not found\n" , __func__);return ; } + chip =gpio_device_get_chip (gdev); +/* * Start with FIQ initialization as it may have to request * and release successfully each OMAP GPIO pin in turn. --
Quoted 2 lines
2.39.2
Patch applied, thanks!
Bart
Re: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
In reply to Linus WalleijQuoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:
Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus Walleij
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of gpiochip_find() treewide, so with it we could remove it entirely for v6.7.
Bart
Dipen Patel
maintainerRe: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus Walleij
Quoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.
Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
Quoted 2 lines
Bart
Dipen Patel
maintainerRe: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
Quoted 37 lines · Dipen Patel
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus WalleijQuoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Quoted 4 lines
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
of course with your patches it would fail for the gdev instead of the chip.
Quoted 4 lines
Quoted 3 lines
Bart
Dipen Patel
maintainerRe: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
Quoted 43 lines · Dipen Patel
Quoted 37 lines · Dipen Patel
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus WalleijQuoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Quoted 4 lines
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
Quoted 4 lines
of course with your patches it would fail for the gdev instead of the chip.
Small update:
I put some debugging prints in the gpio match function in the hte-tegra194.c as below:
static int tegra_gpiochip_match(struct gpio_chip *chip, void *data)
{
+ struct device_node *node = data; + struct fwnode_handle *fw = of_node_to_fwnode(data); + if (!fw || !chip->fwnode)
+ pr_err("dipen patel: fw is null\n");
- pr_err("%s:%d\n", __func__, __LINE__);
+ pr_err("dipen patel, %s:%d: %s, %s, %s, match?:%d, fwnode name:%s\n",__func__, __LINE__, chip->label, node->name, node->full_name, (chip->fwnode ==
fw), fw->dev->init_name);
return chip->fwnode == of_node_to_fwnode(data);}
The output of the printfs looks like below:
[ 3.955194] dipen patel: fw is null -----> this message started appearing
when I added !chip->fwnode test in the if condition line.
[ 3.958864] dipen patel, tegra_gpiochip_match:689: tegra234-gpio, gpio,
gpio@c2f0000, match?:0, fwnode name:(null)
I conclude that chip->fwnode is empty. Any idea in which conditions that node would be empty?
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Bart
Dipen Patel
maintainerRe: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
Quoted 69 lines · Dipen Patel
Quoted 43 lines · Dipen Patel
Quoted 37 lines · Dipen Patel
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus WalleijQuoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Quoted 4 lines
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
Quoted 4 lines
of course with your patches it would fail for the gdev instead of the chip.
Small update:
I put some debugging prints in the gpio match function in the
hte-tegra194.cas below:static int
tegra_gpiochip_match(struct gpio_chip *chip, void *data)
{(quoted diff) +5
-1+ struct device_node *node = data; + struct fwnode_handle *fw = of_node_to_fwnode(data); + if (!fw || !chip->fwnode) + pr_err("dipen patel: fw is null\n"); - pr_err("%s:%d\n", __func__, __LINE__); + pr_err("dipen patel, %s:%d: %s, %s, %s, match?:%d, fwnode name:%s\n",
__func__,__LINE__,chip->label,node->name,node->full_name, (chip->fwnode==fw), fw->dev->init_name); return chip->fwnode == of_node_to_fwnode(data);}
The output of the printfs looks like below:
Quoted 8 lines
[ 3.955194] dipen patel: fw is null -----> this message started appearingwhen I added !chip->fwnode test in the if condition line.
[ 3.958864] dipen patel, tegra_gpiochip_match:689: tegra234-gpio, gpio,gpio@c2f0000, match?:0, fwnode name:(null)
I conclude that
chip->fwnodeis empty. Any idea in which conditions that node would be empty?
sorry for spamming, one last message before I sign off for the day....
Seems, adding below in the tegra gpio driver resolved the issue I am facing, I was able to verify your patch series.
drivers/gpio/gpio-tegra186.c +2 -0
@@ -989,6 +989,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev) offset += port->pins; } + gpio->gpio.fwnode =of_node_to_fwnode (pdev->dev.of_node); +return devm_gpiochip_add_data (&pdev->dev, &gpio->gpio, gpio); }
Now, few follow up questions:
1) is this the correct way of setting the chip fwnode in the gpio driver?
2) Or should I use something else in hte matching function instead of fwnode so to avoid adding above line in the gpio driver?
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Bart
Re: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
Quoted 98 lines · Dipen Patel
Quoted 69 lines · Dipen Patel
Quoted 43 lines · Dipen Patel
Quoted 37 lines · Dipen Patel
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus WalleijQuoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Quoted 4 lines
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
Quoted 4 lines
of course with your patches it would fail for the gdev instead of the chip.
Small update:
I put some debugging prints in the gpio match function in the
hte-tegra194.cas below:static int
tegra_gpiochip_match(struct gpio_chip *chip, void *data)
{(quoted diff) +5
-1+ struct device_node *node = data; + struct fwnode_handle *fw = of_node_to_fwnode(data); + if (!fw || !chip->fwnode) + pr_err("dipen patel: fw is null\n"); - pr_err("%s:%d\n", __func__, __LINE__); + pr_err("dipen patel, %s:%d: %s, %s, %s, match?:%d, fwnode name:%s\n",
__func__,__LINE__,chip->label,node->name,node->full_name, (chip->fwnode==fw), fw->dev->init_name); return chip->fwnode == of_node_to_fwnode(data);}
The output of the printfs looks like below:
Quoted 8 lines
[ 3.955194] dipen patel: fw is null -----> this message started appearingwhen I added !chip->fwnode test in the if condition line.
[ 3.958864] dipen patel, tegra_gpiochip_match:689: tegra234-gpio, gpio,gpio@c2f0000, match?:0, fwnode name:(null)
I conclude that
chip->fwnodeis empty. Any idea in which conditions that node would be empty?sorry for spamming, one last message before I sign off for the day....
Seems, adding below in the tegra gpio driver resolved the issue I am facing, I was able to verify your patch series.
drivers/gpio/gpio-tegra186.c +2
-0@@ -989,6 +989,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev) offset += port->pins; } + gpio->gpio.fwnode =of_node_to_fwnode (pdev->dev.of_node); +return devm_gpiochip_add_data (&pdev->dev, &gpio->gpio, gpio); }
Quoted 2 lines
Now, few follow up questions:
1) is this the correct way of setting the chip fwnode in the gpio driver?
You shouldn't need this. This driver already does:
gpio->gpio.parent = &pdev->dev;
so fwnode should be assigned in gpiochip_add_data_with_key(). Can you check why this doesn't happen?
Bart
Quoted 11 lines
2) Or should I use something else in hte matching function instead of fwnode so to avoid adding above line in the gpio driver?
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Bart
Dipen Patel
maintainerRe: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
Quoted 104 lines · Bartosz Golaszewski
Quoted 98 lines · Dipen Patel
Quoted 69 lines · Dipen Patel
Quoted 43 lines · Dipen Patel
Quoted 37 lines · Dipen Patel
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus WalleijQuoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Quoted 4 lines
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
Quoted 4 lines
of course with your patches it would fail for the gdev instead of the chip.
Small update:
I put some debugging prints in the gpio match function in the
hte-tegra194.cas below:static int
tegra_gpiochip_match(struct gpio_chip *chip, void *data)
{(quoted diff) +5
-1+ struct device_node *node = data; + struct fwnode_handle *fw = of_node_to_fwnode(data); + if (!fw || !chip->fwnode) + pr_err("dipen patel: fw is null\n"); - pr_err("%s:%d\n", __func__, __LINE__); + pr_err("dipen patel, %s:%d: %s, %s, %s, match?:%d, fwnode name:%s\n",
__func__,__LINE__,chip->label,node->name,node->full_name, (chip->fwnode==fw), fw->dev->init_name); return chip->fwnode == of_node_to_fwnode(data);}
The output of the printfs looks like below:
Quoted 8 lines
[ 3.955194] dipen patel: fw is null -----> this message started appearingwhen I added !chip->fwnode test in the if condition line.
[ 3.958864] dipen patel, tegra_gpiochip_match:689: tegra234-gpio, gpio,gpio@c2f0000, match?:0, fwnode name:(null)
I conclude that
chip->fwnodeis empty. Any idea in which conditions that node would be empty?sorry for spamming, one last message before I sign off for the day....
Seems, adding below in the tegra gpio driver resolved the issue I am facing, I was able to verify your patch series.
drivers/gpio/gpio-tegra186.c +2
-0@@ -989,6 +989,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev) offset += port->pins; } + gpio->gpio.fwnode =of_node_to_fwnode (pdev->dev.of_node); +return devm_gpiochip_add_data (&pdev->dev, &gpio->gpio, gpio); }Quoted 2 lines
Now, few follow up questions:
1) is this the correct way of setting the chip fwnode in the gpio driver?You shouldn't need this. This driver already does:
Quoted 4 lines
gpio->gpio.parent = &pdev->dev;so fwnode should be assigned in
gpiochip_add_data_with_key(). Can you check why this doesn't happen?
I do not see anywhere chip->fwnode being set in the gpiochip_add_* function. The only reference I see is here [1]. Does it mean I need to change my match function from:
chip->fwnode == of_node_to_fwnode(data)
to:dev_fwnode(chip->parent) == of_node_to_fwnode(data)?
Quoted 14 lines
Bart
Quoted 11 lines
2) Or should I use something else in hte matching function instead of fwnode so to avoid adding above line in the gpio driver?
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Bart
Re: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
Quoted 111 lines · Dipen Patel
Quoted 104 lines · Bartosz Golaszewski
Quoted 98 lines · Dipen Patel
Quoted 69 lines · Dipen Patel
Quoted 43 lines · Dipen Patel
Quoted 37 lines · Dipen Patel
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus WalleijQuoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Quoted 4 lines
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
Quoted 4 lines
of course with your patches it would fail for the gdev instead of the chip.
Small update:
I put some debugging prints in the gpio match function in the
hte-tegra194.cas below:static int
tegra_gpiochip_match(struct gpio_chip *chip, void *data)
{(quoted diff) +5
-1+ struct device_node *node = data; + struct fwnode_handle *fw = of_node_to_fwnode(data); + if (!fw || !chip->fwnode) + pr_err("dipen patel: fw is null\n"); - pr_err("%s:%d\n", __func__, __LINE__); + pr_err("dipen patel, %s:%d: %s, %s, %s, match?:%d, fwnode name:%s\n",
__func__,__LINE__,chip->label,node->name,node->full_name, (chip->fwnode==fw), fw->dev->init_name); return chip->fwnode == of_node_to_fwnode(data);}
The output of the printfs looks like below:
Quoted 8 lines
[ 3.955194] dipen patel: fw is null -----> this message started appearingwhen I added !chip->fwnode test in the if condition line.
[ 3.958864] dipen patel, tegra_gpiochip_match:689: tegra234-gpio, gpio,gpio@c2f0000, match?:0, fwnode name:(null)
I conclude that
chip->fwnodeis empty. Any idea in which conditions that node would be empty?sorry for spamming, one last message before I sign off for the day....
Seems, adding below in the tegra gpio driver resolved the issue I am facing, I was able to verify your patch series.
drivers/gpio/gpio-tegra186.c +2
-0@@ -989,6 +989,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev) offset += port->pins; } + gpio->gpio.fwnode =of_node_to_fwnode (pdev->dev.of_node); +return devm_gpiochip_add_data (&pdev->dev, &gpio->gpio, gpio); }Quoted 2 lines
Now, few follow up questions:
1) is this the correct way of setting the chip fwnode in the gpio driver?You shouldn't need this. This driver already does:
Quoted 4 lines
gpio->gpio.parent = &pdev->dev;so fwnode should be assigned in
gpiochip_add_data_with_key(). Can you check why this doesn't happen?
Quoted 8 lines
I do not see anywhere
chip->fwnodebeing set in the gpiochip_add_* function. The only reference I see is here [1]. Does it mean I need to change my match function from:
chip->fwnode==of_node_to_fwnode(data)to:
dev_fwnode(chip->parent)==of_node_to_fwnode(data)?
No! chip->fwnode is only used to let GPIOLIB know which fwnode to assign to the GPIO device (struct gpio_device).
Bart
Quoted 19 lines
Quoted 14 lines
Bart
Quoted 11 lines
2) Or should I use something else in hte matching function instead of fwnode so to avoid adding above line in the gpio driver?
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Bart
Dipen Patel
maintainerRe: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
Quoted 116 lines · Bartosz Golaszewski
Quoted 115 lines · Dipen Patel
Quoted 104 lines · Bartosz Golaszewski
Quoted 98 lines · Dipen Patel
Quoted 69 lines · Dipen Patel
Quoted 43 lines · Dipen Patel
Quoted 37 lines · Dipen Patel
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus WalleijQuoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Quoted 4 lines
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
Quoted 4 lines
of course with your patches it would fail for the gdev instead of the chip.
Small update:
I put some debugging prints in the gpio match function in the
hte-tegra194.cas below:static int
tegra_gpiochip_match(struct gpio_chip *chip, void *data)
{(quoted diff) +5
-1+ struct device_node *node = data; + struct fwnode_handle *fw = of_node_to_fwnode(data); + if (!fw || !chip->fwnode) + pr_err("dipen patel: fw is null\n"); - pr_err("%s:%d\n", __func__, __LINE__); + pr_err("dipen patel, %s:%d: %s, %s, %s, match?:%d, fwnode name:%s\n",
__func__,__LINE__,chip->label,node->name,node->full_name, (chip->fwnode==fw), fw->dev->init_name); return chip->fwnode == of_node_to_fwnode(data);}
The output of the printfs looks like below:
Quoted 8 lines
[ 3.955194] dipen patel: fw is null -----> this message started appearingwhen I added !chip->fwnode test in the if condition line.
[ 3.958864] dipen patel, tegra_gpiochip_match:689: tegra234-gpio, gpio,gpio@c2f0000, match?:0, fwnode name:(null)
I conclude that
chip->fwnodeis empty. Any idea in which conditions that node would be empty?sorry for spamming, one last message before I sign off for the day....
Seems, adding below in the tegra gpio driver resolved the issue I am facing, I was able to verify your patch series.
drivers/gpio/gpio-tegra186.c +2
-0@@ -989,6 +989,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev) offset += port->pins; } + gpio->gpio.fwnode =of_node_to_fwnode (pdev->dev.of_node); +return devm_gpiochip_add_data (&pdev->dev, &gpio->gpio, gpio); }Quoted 2 lines
Now, few follow up questions:
1) is this the correct way of setting the chip fwnode in the gpio driver?You shouldn't need this. This driver already does:
Quoted 4 lines
gpio->gpio.parent = &pdev->dev;so fwnode should be assigned in
gpiochip_add_data_with_key(). Can you check why this doesn't happen?I do not see anywhere
chip->fwnodebeing set in the gpiochip_add_* function. The only reference I see is here [1]. Does it mean I need to change my match function from:
Quoted 7 lines
Quoted 4 lines
chip->fwnode==of_node_to_fwnode(data)to:
dev_fwnode(chip->parent)==of_node_to_fwnode(data)?No!
chip->fwnodeis only used to let GPIOLIB know which fwnode to assign to the GPIO device (structgpio_device).
What do you suggest I should use for the match as I do not see chip->fwnode being set?
Quoted 22 lines
Bart
Quoted 19 lines
Quoted 14 lines
Bart
Quoted 11 lines
2) Or should I use something else in hte matching function instead of fwnode so to avoid adding above line in the gpio driver?
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Bart
Re: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
Quoted 120 lines · Dipen Patel
Quoted 118 lines · Bartosz Golaszewski
Quoted 117 lines · Dipen Patel
Quoted 104 lines · Bartosz Golaszewski
Quoted 98 lines · Dipen Patel
Quoted 69 lines · Dipen Patel
Quoted 43 lines · Dipen Patel
Quoted 37 lines · Dipen Patel
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus WalleijQuoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Quoted 4 lines
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
Quoted 4 lines
of course with your patches it would fail for the gdev instead of the chip.
Small update:
I put some debugging prints in the gpio match function in the
hte-tegra194.cas below:static int
tegra_gpiochip_match(struct gpio_chip *chip, void *data)
{(quoted diff) +5
-1+ struct device_node *node = data; + struct fwnode_handle *fw = of_node_to_fwnode(data); + if (!fw || !chip->fwnode) + pr_err("dipen patel: fw is null\n"); - pr_err("%s:%d\n", __func__, __LINE__); + pr_err("dipen patel, %s:%d: %s, %s, %s, match?:%d, fwnode name:%s\n",
__func__,__LINE__,chip->label,node->name,node->full_name, (chip->fwnode==fw), fw->dev->init_name); return chip->fwnode == of_node_to_fwnode(data);}
The output of the printfs looks like below:
Quoted 8 lines
[ 3.955194] dipen patel: fw is null -----> this message started appearingwhen I added !chip->fwnode test in the if condition line.
[ 3.958864] dipen patel, tegra_gpiochip_match:689: tegra234-gpio, gpio,gpio@c2f0000, match?:0, fwnode name:(null)
I conclude that
chip->fwnodeis empty. Any idea in which conditions that node would be empty?sorry for spamming, one last message before I sign off for the day....
Seems, adding below in the tegra gpio driver resolved the issue I am facing, I was able to verify your patch series.
drivers/gpio/gpio-tegra186.c +2
-0@@ -989,6 +989,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev) offset += port->pins; } + gpio->gpio.fwnode =of_node_to_fwnode (pdev->dev.of_node); +return devm_gpiochip_add_data (&pdev->dev, &gpio->gpio, gpio); }Quoted 2 lines
Now, few follow up questions:
1) is this the correct way of setting the chip fwnode in the gpio driver?You shouldn't need this. This driver already does:
Quoted 4 lines
gpio->gpio.parent = &pdev->dev;so fwnode should be assigned in
gpiochip_add_data_with_key(). Can you check why this doesn't happen?I do not see anywhere
chip->fwnodebeing set in the gpiochip_add_* function. The only reference I see is here [1]. Does it mean I need to change my match function from:
chip->fwnode==of_node_to_fwnode(data)
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
to:
dev_fwnode(chip->parent)==of_node_to_fwnode(data)?No!
chip->fwnodeis only used to let GPIOLIB know which fwnode to assign to the GPIO device (structgpio_device).What do you suggest I should use for the match as I do not see
chip->fwnodebeing set?
Andy, Linus,
Do you think it makes sense to make gpiochip_add_data_with_key() assign the chip's fwnode if it's not set by the caller (and instead taken from the parent device) for this particular use-case?
I think it's fine but wanted to run it by you.
Bart
Quoted 23 lines
Quoted 22 lines
Bart
Quoted 19 lines
Quoted 14 lines
Bart
Quoted 11 lines
2) Or should I use something else in hte matching function instead of fwnode so to avoid adding above line in the gpio driver?
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Bart
Re: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
In reply to Dipen PatelQuoted 120 lines · Dipen Patel
Quoted 118 lines · Bartosz Golaszewski
Quoted 117 lines · Dipen Patel
Quoted 104 lines · Bartosz Golaszewski
Quoted 98 lines · Dipen Patel
Quoted 69 lines · Dipen Patel
Quoted 43 lines · Dipen Patel
Quoted 37 lines · Dipen Patel
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus WalleijQuoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Quoted 4 lines
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
Quoted 4 lines
of course with your patches it would fail for the gdev instead of the chip.
Small update:
I put some debugging prints in the gpio match function in the
hte-tegra194.cas below:static int
tegra_gpiochip_match(struct gpio_chip *chip, void *data)
{(quoted diff) +5
-1+ struct device_node *node = data; + struct fwnode_handle *fw = of_node_to_fwnode(data); + if (!fw || !chip->fwnode) + pr_err("dipen patel: fw is null\n"); - pr_err("%s:%d\n", __func__, __LINE__); + pr_err("dipen patel, %s:%d: %s, %s, %s, match?:%d, fwnode name:%s\n",
__func__,__LINE__,chip->label,node->name,node->full_name, (chip->fwnode==fw), fw->dev->init_name); return chip->fwnode == of_node_to_fwnode(data);}
The output of the printfs looks like below:
Quoted 8 lines
[ 3.955194] dipen patel: fw is null -----> this message started appearingwhen I added !chip->fwnode test in the if condition line.
[ 3.958864] dipen patel, tegra_gpiochip_match:689: tegra234-gpio, gpio,gpio@c2f0000, match?:0, fwnode name:(null)
I conclude that
chip->fwnodeis empty. Any idea in which conditions that node would be empty?sorry for spamming, one last message before I sign off for the day....
Seems, adding below in the tegra gpio driver resolved the issue I am facing, I was able to verify your patch series.
drivers/gpio/gpio-tegra186.c +2
-0@@ -989,6 +989,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev) offset += port->pins; } + gpio->gpio.fwnode =of_node_to_fwnode (pdev->dev.of_node); +return devm_gpiochip_add_data (&pdev->dev, &gpio->gpio, gpio); }Quoted 2 lines
Now, few follow up questions:
1) is this the correct way of setting the chip fwnode in the gpio driver?You shouldn't need this. This driver already does:
Quoted 4 lines
gpio->gpio.parent = &pdev->dev;so fwnode should be assigned in
gpiochip_add_data_with_key(). Can you check why this doesn't happen?I do not see anywhere
chip->fwnodebeing set in the gpiochip_add_* function. The only reference I see is here [1]. Does it mean I need to change my match function from:
chip->fwnode==of_node_to_fwnode(data)
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
to:
dev_fwnode(chip->parent)==of_node_to_fwnode(data)?No!
chip->fwnodeis only used to let GPIOLIB know which fwnode to assign to the GPIO device (structgpio_device).What do you suggest I should use for the match as I do not see
chip->fwnodebeing set?
This is most likely going to be a longer discussion. I suggest that in the meantime you just assign the gc->fwnode pointer explicitly from the platform device in the tegra GPIO driver and use it in the lookup function. Note that this is NOT wrong or a hack. It's just that most devices don't need to be looked up using gpio_device_find().
Bart
Quoted 23 lines
Quoted 22 lines
Bart
Quoted 19 lines
Quoted 14 lines
Bart
Quoted 11 lines
2) Or should I use something else in hte matching function instead of fwnode so to avoid adding above line in the gpio driver?
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Bart
Dipen Patel
maintainerRe: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
Quoted 130 lines · Bartosz Golaszewski
Quoted 120 lines · Dipen Patel
Quoted 118 lines · Bartosz Golaszewski
Quoted 117 lines · Dipen Patel
Quoted 104 lines · Bartosz Golaszewski
Quoted 98 lines · Dipen Patel
Quoted 69 lines · Dipen Patel
Quoted 43 lines · Dipen Patel
Quoted 37 lines · Dipen Patel
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct
gpio_chipis not safe as it will disappear if the underlying driver is unbound for any reason. Switch to using reference counted structgpio_deviceand its dedicated accessors.Signed-off-by Bartosz Golaszewski <[email protected]>As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus WalleijQuoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Quoted 4 lines
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
Quoted 4 lines
of course with your patches it would fail for the gdev instead of the chip.
Small update:
I put some debugging prints in the gpio match function in the
hte-tegra194.cas below:static int
tegra_gpiochip_match(struct gpio_chip *chip, void *data)
{(quoted diff) +5
-1+ struct device_node *node = data; + struct fwnode_handle *fw = of_node_to_fwnode(data); + if (!fw || !chip->fwnode) + pr_err("dipen patel: fw is null\n"); - pr_err("%s:%d\n", __func__, __LINE__); + pr_err("dipen patel, %s:%d: %s, %s, %s, match?:%d, fwnode name:%s\n",
__func__,__LINE__,chip->label,node->name,node->full_name, (chip->fwnode==fw), fw->dev->init_name); return chip->fwnode == of_node_to_fwnode(data);}
The output of the printfs looks like below:
Quoted 8 lines
[ 3.955194] dipen patel: fw is null -----> this message started appearingwhen I added !chip->fwnode test in the if condition line.
[ 3.958864] dipen patel, tegra_gpiochip_match:689: tegra234-gpio, gpio,gpio@c2f0000, match?:0, fwnode name:(null)
I conclude that
chip->fwnodeis empty. Any idea in which conditions that node would be empty?sorry for spamming, one last message before I sign off for the day....
Seems, adding below in the tegra gpio driver resolved the issue I am facing, I was able to verify your patch series.
drivers/gpio/gpio-tegra186.c +2
-0@@ -989,6 +989,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev) offset += port->pins; } + gpio->gpio.fwnode =of_node_to_fwnode (pdev->dev.of_node); +return devm_gpiochip_add_data (&pdev->dev, &gpio->gpio, gpio); }Quoted 2 lines
Now, few follow up questions:
1) is this the correct way of setting the chip fwnode in the gpio driver?You shouldn't need this. This driver already does:
Quoted 4 lines
gpio->gpio.parent = &pdev->dev;so fwnode should be assigned in
gpiochip_add_data_with_key(). Can you check why this doesn't happen?I do not see anywhere
chip->fwnodebeing set in the gpiochip_add_* function. The only reference I see is here [1]. Does it mean I need to change my match function from:
chip->fwnode==of_node_to_fwnode(data)Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
to:
dev_fwnode(chip->parent)==of_node_to_fwnode(data)?No!
chip->fwnodeis only used to let GPIOLIB know which fwnode to assign to the GPIO device (structgpio_device).What do you suggest I should use for the match as I do not see
chip->fwnodebeing set?
Quoted 5 lines
This is most likely going to be a longer discussion. I suggest that in the meantime you just assign the
gc->fwnodepointer explicitly from the platform device in the tegra GPIO driver and use it in the lookup function. Note that this is NOT wrong or a hack. It's just that most devices don't need to be looked up usinggpio_device_find().
Sure, at the same time, I am also find to use any other method/s.
Quoted 26 lines
Bart
Quoted 23 lines
Quoted 22 lines
Bart
Quoted 19 lines
Quoted 14 lines
Bart
Quoted 11 lines
2) Or should I use something else in hte matching function instead of fwnode so to avoid adding above line in the gpio driver?
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Bart
Re: [RFT PATCH 14/21] hte: tegra194: don't access struct gpio_chip
Quoted 131 lines · Dipen Patel
Quoted 130 lines · Bartosz Golaszewski
Quoted 128 lines · Dipen Patel
Quoted 116 lines · Bartosz Golaszewski
Quoted 115 lines · Dipen Patel
Quoted 104 lines · Bartosz Golaszewski
Quoted 98 lines · Dipen Patel
Quoted 69 lines · Dipen Patel
Quoted 43 lines · Dipen Patel
Quoted 37 lines · Dipen Patel
Quoted 22 lines · Bartosz Golaszewski
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Using struct gpio_chip is not safe as it will disappear if the
underlying driver is unbound for any reason. Switch to using reference
counted struct gpio_device and its dedicated accessors.Signed-off-by: Bartosz Golaszewski <[email protected]>
As Andy points out add <
linux/cleanup.h>, with that fixed:Quoted 8 lines
Reviewed-by Linus Walleij <[email protected]>I think this can be merged into the gpio tree after leaving some slack for the HTE maintainer to look at it, things look so much better after this.
Yours,
Linus WalleijQuoted 6 lines
Dipen,
if you could give this patch a test and possibly ack it for me to take it through the GPIO tree (or go the immutable tag from HTE route) then it would be great. This is the last user of
gpiochip_find()treewide, so with it we could remove it entirely for v6.7.Progress so far for the RFT...
I tried applying the patch series on 6.6-rc1 and it did not apply cleanly, some patches I needed to manually apply and correct. With all this, it failed compilation at some spi/spi-bcm2835 driver. I disabled that and was able to compile. I thought I should let you know this part.
Quoted 4 lines
Now, I tried to test the hte and it seems to fail finding the gpio device, roughly around this place [1]. I thought it would be your patch series so tried to just use 6.6rc1 without your patches and it still failed at the same place. I have to trace back now from which kernel version it broke.
Quoted 4 lines
of course with your patches it would fail for the gdev instead of the chip.
Small update:
I put some debugging prints in the gpio match function in the
hte-tegra194.cas below:static int
tegra_gpiochip_match(struct gpio_chip *chip, void *data)
{(quoted diff) +5
-1+ struct device_node *node = data; + struct fwnode_handle *fw = of_node_to_fwnode(data); + if (!fw || !chip->fwnode) + pr_err("dipen patel: fw is null\n"); - pr_err("%s:%d\n", __func__, __LINE__); + pr_err("dipen patel, %s:%d: %s, %s, %s, match?:%d, fwnode name:%s\n",
__func__,__LINE__,chip->label,node->name,node->full_name, (chip->fwnode==fw), fw->dev->init_name); return chip->fwnode == of_node_to_fwnode(data);}
The output of the printfs looks like below:
Quoted 8 lines
[ 3.955194] dipen patel: fw is null -----> this message started appearingwhen I added !chip->fwnode test in the if condition line.
[ 3.958864] dipen patel, tegra_gpiochip_match:689: tegra234-gpio, gpio,gpio@c2f0000, match?:0, fwnode name:(null)
I conclude that
chip->fwnodeis empty. Any idea in which conditions that node would be empty?sorry for spamming, one last message before I sign off for the day....
Seems, adding below in the tegra gpio driver resolved the issue I am facing, I was able to verify your patch series.
drivers/gpio/gpio-tegra186.c +2
-0@@ -989,6 +989,8 @@ static int tegra186_gpio_probe(struct platform_device *pdev) offset += port->pins; } + gpio->gpio.fwnode =of_node_to_fwnode (pdev->dev.of_node); +return devm_gpiochip_add_data (&pdev->dev, &gpio->gpio, gpio); }Quoted 2 lines
Now, few follow up questions:
1) is this the correct way of setting the chip fwnode in the gpio driver?You shouldn't need this. This driver already does:
Quoted 4 lines
gpio->gpio.parent = &pdev->dev;so fwnode should be assigned in
gpiochip_add_data_with_key(). Can you check why this doesn't happen?I do not see anywhere
chip->fwnodebeing set in the gpiochip_add_* function. The only reference I see is here [1]. Does it mean I need to change my match function from:Quoted 7 lines
Quoted 4 lines
chip->fwnode==of_node_to_fwnode(data)to:
dev_fwnode(chip->parent)==of_node_to_fwnode(data)?No!
chip->fwnodeis only used to let GPIOLIB know which fwnode to assign to the GPIO device (structgpio_device).What do you suggest I should use for the match as I do not see
chip->fwnodebeing set?
Quoted 7 lines
Quoted 5 lines
This is most likely going to be a longer discussion. I suggest that in the meantime you just assign the
gc->fwnodepointer explicitly from the platform device in the tegra GPIO driver and use it in the lookup function. Note that this is NOT wrong or a hack. It's just that most devices don't need to be looked up usinggpio_device_find().Sure, at the same time, I am also find to use any other method/s.
(Correction) I am also fine*
With patch
https://patchwork.ozlabs.org/project/linux-gpio/patch/[email protected]/
Quoted 27 lines
Quoted 26 lines
Bart
Quoted 23 lines
Quoted 22 lines
Bart
Quoted 19 lines
Quoted 14 lines
Bart
Quoted 11 lines
2) Or should I use something else in hte matching function instead of fwnode so to avoid adding above line in the gpio driver?
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Bart
Re: [PATCH 19/21] gpio: swnode: replace gpiochip_find() with gpio_device_find_by_label()
In reply to Bartosz GolaszewskiHi Bartosz,
Le mardi 05 septembre 2023 à 20:53 +0200, Bartosz Golaszewski a écrit :
Quoted 70 lines
From: Bartosz Golaszewski <[email protected]>
We're porting all users of
gpiochip_find()to usinggpio_device_find().
Update the swnode GPIO code.Signed-off-by Bartosz Golaszewski <[email protected]>---
drivers/gpio/gpiolib-swnode.c | 29 ++++++++++++-----------------1 file changed, 12 insertions(+), 17 deletions(-)drivers/gpio/gpiolib- renamed from drivers/gpio/gpiolib-swnode.c +0
-0
swnode.c
indexb5a6eaf3729b..56c8519be538100644drivers/gpio/gpiolib-swnode.c +0
-0@@ -31,31 +31,26 @@ static void swnode_format_propname(const char *con_id, char *propname, strscpy(propname, "gpios", max_size); }
-static intswnode_gpiochip_match_name(struct gpio_chip *chip, void *data)
+static structgpio_device*swnode_get_gpio_device(structfwnode_handle*fwnode)
{drivers/gpio/gpiolib-swnode.c +2
-2-return !strcmp (chip->label, data); -} +const struct software_node *gdev_node; +struct gpio_device *gdev;
-static structgpio_chip*swnode_get_chip(structfwnode_handle*fwnode)drivers/gpio/gpiolib-swnode.c +2
-6-{ -const struct software_node *chip_node; -struct gpio_chip *chip; - - chip_node =to_software_node (fwnode); -if (!chip_node || !chip_node->name) + gdev_node =to_software_node (fwnode); +if (!gdev_node || !gdev_node->name)return
ERR_PTR(-EINVAL);drivers/gpio/gpiolib-swnode.c +0
-1- chip = gpiochip_find((void *)chip_node->name,
swnode_gpiochip_match_name);drivers/gpio/gpiolib-swnode.c +2
-1-return chip ?:ERR_PTR (-EPROBE_DEFER ); + gdev =gpio_device_find_by_label ((void *)gdev_node->name); +return gdev ?:ERR_PTR (-EPROBE_DEFER );}
structgpio_desc*swnode_find_gpio(structfwnode_handle*fwnode, const char*con_id, unsigned int idx,
unsigned long *flags) {drivers/gpio/gpiolib-swnode.c +1
-0+ struct gpio_device *gdev __free(gpio_device_put) = NULL;const struct
software_node*swnode;
structfwnode_reference_argsargs;drivers/gpio/gpiolib-swnode.c +0
-1-struct gpio_chip *chip;struct
gpio_desc*desc;
char propname[32]; /* 32 is max size of property name */ int error;drivers/gpio/gpiolib-swnode.c +0
-0@@ -77,12 +72,12 @@ struct gpio_desc *swnode_find_gpio(structfwnode_handle *fwnode, return ERR_PTR(error); }drivers/gpio/gpiolib-swnode.c +1
-1- chip =swnode_get_chip (args.fwnode); + gdev =swnode_get_gpio_device (args.fwnode);
fwnode_handle_put(args.fwnode);
drivers/gpio/gpiolib-swnode.c struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, · line 78
Quoted 4 lines
drivers/gpio/gpiolib-swnode.c +2
-2-if (IS_ERR (chip)) -return ERR_CAST (chip); +if (IS_ERR (gdev)) +return ERR_CAST (gdev);
I'm a bit late to the party, sorry.
I'm looking at how __free() should be used to use it in my own patchset, and I was wondering if this code actually works.
What happens if swnode_get_gpio_device() returns an error pointer? Won't that cause a call to gpio_device_put() with the invalid pointer?
Cheers,
-Paul
Quoted 7 lines
drivers/gpio/gpiolib-swnode.c +1
-1- desc =gpiochip_get_desc (chip, args.args[0 ]); + desc =gpiochip_get_desc (gdev->chip, args.args[0 ]);*flags = args.args[1]; /* We expect native GPIO flags */
pr_debug("%s: parsed '%s' property of node '%pfwP[%d]' - status (%d)\n",
Re: [PATCH 19/21] gpio: swnode: replace gpiochip_find() with gpio_device_find_by_label()
Quoted 81 lines · Paul Cercueil
Hi Bartosz,
Quoted 64 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We're porting all users of
gpiochip_find()to usinggpio_device_find().
Update the swnode GPIO code.Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/gpio/gpiolib-swnode.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-)drivers/gpio/gpiolib- renamed from drivers/gpio/gpiolib-swnode.c +0
-0
swnode.c
indexb5a6eaf3729b..56c8519be538100644drivers/gpio/gpiolib-swnode.c +8
-13@@ -31,31 +31,26 @@ static void swnode_format_propname(const char *con_id, char *propname,strscpy (propname,"gpios" , max_size); } -static int swnode_gpiochip_match_name (struct gpio_chip *chip,void *data) +static struct gpio_device *swnode_get_gpio_device (struct fwnode_handle *fwnode) { -return !strcmp (chip->label, data); -} +const struct software_node *gdev_node; +struct gpio_device *gdev; -static struct gpio_chip *swnode_get_chip (struct fwnode_handle *fwnode) -{ -const struct software_node *chip_node; -struct gpio_chip *chip; - - chip_node =to_software_node (fwnode); -if (!chip_node || !chip_node->name) + gdev_node =to_software_node (fwnode); +if (!gdev_node || !gdev_node->name)return ERR_PTR (-EINVAL ); - chip =gpiochip_find ((void *)chip_node->name, swnode_gpiochip_match_name); -return chip ?:ERR_PTR (-EPROBE_DEFER ); + gdev =gpio_device_find_by_label ((void *)gdev_node->name); +return gdev ?:ERR_PTR (-EPROBE_DEFER ); }struct gpio_desc *swnode_find_gpio (struct fwnode_handle *fwnode,const char *con_id,unsigned int idx,unsigned long *flags) { + struct gpio_device *gdev __free(gpio_device_put) = NULL;const struct software_node *swnode;struct fwnode_reference_args args; -struct gpio_chip *chip;struct gpio_desc *desc;char propname[32 ];/* 32 is max size of property name */ int error;@@ -77,12 +72,12 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode,drivers/gpio/gpiolib-swnode.c struct gpio_desc *swnode_find_gpio(struct · line 79
Quoted 10 lines
drivers/gpio/gpiolib-swnode.c +3
-3return ERR_PTR (error); } - chip =swnode_get_chip (args.fwnode); + gdev =swnode_get_gpio_device (args.fwnode);fwnode_handle_put (args.fwnode); -if (IS_ERR (chip)) -return ERR_CAST (chip); +if (IS_ERR (gdev)) +return ERR_CAST (gdev);I'm a bit late to the party, sorry.
Quoted 9 lines
I'm looking at how
__free()should be used to use it in my own patchset, and I was wondering if this code actually works.What happens if
swnode_get_gpio_device()returns an error pointer? Won't that cause a call togpio_device_put()with the invalid pointer?Cheers,
-Paul
No. because the __free() callback is defined as:
DEFINE_FREE(gpio_device_put, struct gpio_device *,
if (!IS_ERR_OR_NULL(_T)) gpio_device_put(_T))
Bart
Quoted 8 lines
Quoted 7 lines
drivers/gpio/gpiolib-swnode.c +1
-1- desc =gpiochip_get_desc (chip, args.args[0 ]); + desc =gpiochip_get_desc (gdev->chip, args.args[0 ]); *flags = args.args[1 ];/* We expect native GPIO flags */ pr_debug("%s: parsed '%s' property of node '%pfwP[%d]' -status (%d)\n",
Re: [PATCH 19/21] gpio: swnode: replace gpiochip_find() with gpio_device_find_by_label()
Le mercredi 24 janvier 2024 à 16:04 +0100, Bartosz Golaszewski a écrit :
Quoted 94 lines
Quoted 92 lines · Paul Cercueil
Hi Bartosz,
Le mardi 05 septembre 2023 à 20:53 +0200, Bartosz Golaszewski a écrit :
Quoted 67 lines
From: Bartosz Golaszewski <[email protected]>
We're porting all users of
gpiochip_find()to usinggpio_device_find().
Update the swnode GPIO code.Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/gpio/gpiolib-swnode.c | 29 ++++++++++++-----------------1 file changed, 12 insertions(+), 17 deletions(-)drivers/gpio/gpiolib- renamed from drivers/gpio/gpiolib-swnode.c +0
-0
swnode.c
indexb5a6eaf3729b..56c8519be538100644drivers/gpio/gpiolib-swnode.c +0
-1@@ -31,31 +31,26 @@ static void swnode_format_propname(const char *con_id, char *propname, strscpy(propname, "gpios", max_size); } -static int swnode_gpiochip_match_name(struct gpio_chip *chip,void
*data)
+static structgpio_device*swnode_get_gpio_device(structfwnode_handle*fwnode)
{
- return !strcmp(chip->label, data);drivers/gpio/gpiolib-swnode.c +2
-2-} + const struct software_node *gdev_node; + struct gpio_device *gdev; -static struct gpio_chip *swnode_get_chip(struct fwnode_handle*fwnode)
drivers/gpio/gpiolib-swnode.c +2
-6-{ - const struct software_node *chip_node; - struct gpio_chip *chip; - - chip_node = to_software_node(fwnode); - if (!chip_node || !chip_node->name) + gdev_node = to_software_node(fwnode); + if (!gdev_node || !gdev_node->name)return
ERR_PTR(-EINVAL);- chip =
gpiochip_find((void *)chip_node->name, swnode_gpiochip_match_name);
- return chip ?:ERR_PTR(-EPROBE_DEFER);
+ gdev =gpio_device_find_by_label((void *)gdev_node->name); + return gdev ?:ERR_PTR(-EPROBE_DEFER);
}struct
gpio_desc*swnode_find_gpio(structfwnode_handle*fwnode, const char*con_id, unsigned int idx,
unsigned long *flags) {
+ structgpio_device*gdev__free(gpio_device_put)= NULL; const structsoftware_node*swnode;
structfwnode_reference_argsargs;
- structgpio_chip*chip;
structgpio_desc*desc;
char propname[32]; /* 32 is max size of property name */ int error;drivers/gpio/gpiolib-swnode.c +0
-0@@ -77,12 +72,12 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode,drivers/gpio/gpiolib-swnode.c struct gpio_desc *swnode_find_gpio(struct · line 79
Quoted 10 lines
drivers/gpio/gpiolib-swnode.c +3
-3return ERR_PTR(error); } - chip = swnode_get_chip(args.fwnode); + gdev = swnode_get_gpio_device(args.fwnode); fwnode_handle_put(args.fwnode); - if (IS_ERR(chip)) - return ERR_CAST(chip); + if (IS_ERR(gdev)) + return ERR_CAST(gdev);I'm a bit late to the party, sorry.
I'm looking at how
__free()should be used to use it in my own patchset, and I was wondering if this code actually works.What happens if
swnode_get_gpio_device()returns an error pointer? Won't that cause a call togpio_device_put()with the invalid pointer?
Quoted 8 lines
Quoted 3 lines
Cheers,
-PaulNo. because the
__free()callback is defined as:
DEFINE_FREE(gpio_device_put, struct gpio_device *, if (!IS_ERR_OR_NULL(_T)) gpio_device_put(_T))
Ok. I missed this.
I would argue that it's still not right though - it should probably use IS_ERR() instead. gpio_device_put() only happens to accept NULL pointers because the "dev" field is at the very beginning of the "gpio_device" struct. I'm not sure this works with e.g. CONFIG_RANDSTRUCT_FULL.
Quoted 1 line
Bart
Cheers,
-Paul
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/gpio/gpiolib-swnode.c +1
-1- desc = gpiochip_get_desc(chip, args.args[0]); + desc = gpiochip_get_desc(gdev->chip, args.args[0]); *flags = args.args[1]; /* We expect native GPIO flags */pr_debug("%s: parsed '%s' property of node '%pfwP[%d]' - status (%d)\n",
Re: [PATCH 19/21] gpio: swnode: replace gpiochip_find() with gpio_device_find_by_label()
In reply to Bartosz GolaszewskiLe mercredi 24 janvier 2024 à 16:04 +0100, Bartosz Golaszewski a écrit :
Quoted 94 lines
Quoted 92 lines · Paul Cercueil
Hi Bartosz,
Le mardi 05 septembre 2023 à 20:53 +0200, Bartosz Golaszewski a écrit :
Quoted 67 lines
From: Bartosz Golaszewski <[email protected]>
We're porting all users of
gpiochip_find()to usinggpio_device_find().
Update the swnode GPIO code.Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/gpio/gpiolib-swnode.c | 29 ++++++++++++-----------------1 file changed, 12 insertions(+), 17 deletions(-)drivers/gpio/gpiolib- renamed from drivers/gpio/gpiolib-swnode.c +0
-0
swnode.c
indexb5a6eaf3729b..56c8519be538100644drivers/gpio/gpiolib-swnode.c +0
-1@@ -31,31 +31,26 @@ static void swnode_format_propname(const char *con_id, char *propname, strscpy(propname, "gpios", max_size); } -static int swnode_gpiochip_match_name(struct gpio_chip *chip,void
*data)
+static structgpio_device*swnode_get_gpio_device(structfwnode_handle*fwnode)
{
- return !strcmp(chip->label, data);drivers/gpio/gpiolib-swnode.c +2
-2-} + const struct software_node *gdev_node; + struct gpio_device *gdev; -static struct gpio_chip *swnode_get_chip(struct fwnode_handle*fwnode)
drivers/gpio/gpiolib-swnode.c +2
-6-{ - const struct software_node *chip_node; - struct gpio_chip *chip; - - chip_node = to_software_node(fwnode); - if (!chip_node || !chip_node->name) + gdev_node = to_software_node(fwnode); + if (!gdev_node || !gdev_node->name)return
ERR_PTR(-EINVAL);- chip =
gpiochip_find((void *)chip_node->name, swnode_gpiochip_match_name);
- return chip ?:ERR_PTR(-EPROBE_DEFER);
+ gdev =gpio_device_find_by_label((void *)gdev_node->name); + return gdev ?:ERR_PTR(-EPROBE_DEFER);
}struct
gpio_desc*swnode_find_gpio(structfwnode_handle*fwnode, const char*con_id, unsigned int idx,
unsigned long *flags) {
+ structgpio_device*gdev__free(gpio_device_put)= NULL; const structsoftware_node*swnode;
structfwnode_reference_argsargs;
- structgpio_chip*chip;
structgpio_desc*desc;
char propname[32]; /* 32 is max size of property name */ int error;drivers/gpio/gpiolib-swnode.c +0
-0@@ -77,12 +72,12 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode,drivers/gpio/gpiolib-swnode.c struct gpio_desc *swnode_find_gpio(struct · line 79
Quoted 10 lines
drivers/gpio/gpiolib-swnode.c +3
-3return ERR_PTR(error); } - chip = swnode_get_chip(args.fwnode); + gdev = swnode_get_gpio_device(args.fwnode); fwnode_handle_put(args.fwnode); - if (IS_ERR(chip)) - return ERR_CAST(chip); + if (IS_ERR(gdev)) + return ERR_CAST(gdev);I'm a bit late to the party, sorry.
I'm looking at how
__free()should be used to use it in my own patchset, and I was wondering if this code actually works.What happens if
swnode_get_gpio_device()returns an error pointer? Won't that cause a call togpio_device_put()with the invalid pointer?
Quoted 8 lines
Quoted 3 lines
Cheers,
-PaulNo. because the
__free()callback is defined as:
DEFINE_FREE(gpio_device_put, struct gpio_device *, if (!IS_ERR_OR_NULL(_T)) gpio_device_put(_T))
Disregard my previous email, I'm stupid. This actually checks that the pointer is non-null.
Cheers,
-Paul
Quoted 11 lines
Bart
Quoted 8 lines
Quoted 7 lines
drivers/gpio/gpiolib-swnode.c +1
-1- desc = gpiochip_get_desc(chip, args.args[0]); + desc = gpiochip_get_desc(gdev->chip, args.args[0]); *flags = args.args[1]; /* We expect native GPIO flags */pr_debug("%s: parsed '%s' property of node '%pfwP[%d]' - status (%d)\n",