Skip to contentSkip to conversation

gpiolib: unduplicate the pointer used for storing GPIO chip data

PATCH In review Bartosz Golaszewski 2 participants 2 messages Jul 17 – Jul 20 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: unduplicate the pointer used for storing GPIO chip data

We currently carry a dedicated pointer inside struct gpio_device for storing the driver data. However: struct gpio_device already embeds a struct device which is not accessed by anyone other than GPIO core and also has a dedicated driver data pointer which is currently unused. Convert gpiochip_set/get_data() to calling dev_set/get_drvdata() on the GPIO device's struct device and remove the duplicated pointer from struct gpio_device.

---
 drivers/gpio/gpiolib.c | 4 ++--
 drivers/gpio/gpiolib.h | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib.c +2 -2
index c433a095907fe6ea0fb0a3e1234bcf1f37042cde..723953f909c6159218cad73ecb3ca0dc9acb4c29 100644
@@ -1103,7 +1103,7 @@ static void gpiochip_setup_devs(void)
 
 static void gpiochip_set_data(struct gpio_chip *gc, void *data)
 {
-	gc->gpiodev->data = data;
+	dev_set_drvdata(&gc->gpiodev->dev, data);
 }
 
 /**
@@ -1115,7 +1115,7 @@ static void gpiochip_set_data(struct gpio_chip *gc, void *data)
  */
 void *gpiochip_get_data(struct gpio_chip *gc)
 {
-	return gc->gpiodev->data;
+	return dev_get_drvdata(&gc->gpiodev->dev);
 }
 EXPORT_SYMBOL_GPL(gpiochip_get_data);
 
drivers/gpio/gpiolib.h +0 -2
index 650a702741dfb938fbdf11db65a46ac85b6af512..cdf64785280e95e43f8d8b3645b93fb970347238 100644
@@ -45,7 +45,6 @@ struct fwnode_handle;
  * at device creation time.
  * @label: a descriptive name for the GPIO device, such as the part number
  * or name of the IP component in a System on Chip.
- * @data: per-instance data assigned by the driver
  * @list: links gpio_device:s together for traversal
  * @line_state_notifier: used to notify subscribers about lines being
  *                       requested, released or reconfigured
@@ -75,7 +74,6 @@ struct gpio_device {
 	u16			ngpio;
 	bool			can_sleep;
 	const char		*label;
-	void			*data;
 	struct list_head        list;
 	struct raw_notifier_head line_state_notifier;
 	rwlock_t		line_state_lock;

---
base-commit: 1a1757b76427f6201bfe0bf1bea9f7574f332a93
change-id: 20260717-gpio-dev-drvdata-005219c06a25

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>
#1 lore raw
Quoted 10 lines · Bartosz Golaszewski

We currently carry a dedicated pointer inside struct gpio_device for storing the driver data. However: struct gpio_device already embeds a struct device which is not accessed by anyone other than GPIO core and also has a dedicated driver data pointer which is currently unused. Convert gpiochip_set/get_data() to calling dev_set/get_drvdata() on the GPIO device's struct device and remove the duplicated pointer from struct gpio_device.

---

Sashiko is right, this will break sysfs unbinding so let's drop this.

Bart