Skip to contentSkip to conversation

gpiolib: cleanups WRT GPIO device handling

PATCH In review Andy Shevchenko 3 participants 13 messages Mar 7, 2023 – Mar 15, 2023 GPIO

lore
Share & tools
lore
#0 lore raw

cover gpiolib: cleanups WRT GPIO device handling

A few cleanups to GPIO device handling in the library code.

Andy Shevchenko (3):
gpiolib: Access device's fwnode via dev_fwnode()
gpiolib: Get rid of gpio_bus_match() forward declaration
gpiolib: Move gpiodevice_*() to gpiodev namespace

 drivers/gpio/gpiolib.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
Signature · 1 line
2.39.1
#1 lore raw

PATCH 1/3 gpiolib: Access device's fwnode via dev_fwnode()

GPIO device's fwnode should be accessed via dev_fwnode(). Make sure that gpiochip_setup_dev() follows that.

---
 drivers/gpio/gpiolib.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +3 -2
index b554ad435245..c7f35f0e7d15 100644
@@ -589,14 +589,15 @@ static void gpiodevice_release(struct device *dev)
 
 static int gpiochip_setup_dev(struct gpio_device *gdev)
 {
+	struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev);
 	int ret;
 
 	/*
 	 * If fwnode doesn't belong to another device, it's safe to clear its
 	 * initialized flag.
 	 */
-	if (gdev->dev.fwnode && !gdev->dev.fwnode->dev)
-		fwnode_dev_initialized(gdev->dev.fwnode, false);
+	if (fwnode && !fwnode->dev)
+		fwnode_dev_initialized(fwnode, false);
 
 	ret = gcdev_register(gdev, gpio_devt);
 	if (ret)
Signature · 1 line
2.39.1
#3 lore raw

PATCH 2/3 gpiolib: Get rid of gpio_bus_match() forward declaration

In reply to Andy Shevchenko

There is nothing specific about gpio_bus_match(), so we may simply move it to the top of the file and get rid of forward declaration.

---
 drivers/gpio/gpiolib.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/gpio/gpiolib.c +14 -15
index c7f35f0e7d15..a44a1b0f2766 100644
@@ -62,7 +62,20 @@
 static DEFINE_IDA(gpio_ida);
 static dev_t gpio_devt;
 #define GPIO_DEV_MAX 256 /* 256 GPIO chip devices supported */
-static int gpio_bus_match(struct device *dev, struct device_driver *drv);
+
+static int gpio_bus_match(struct device *dev, struct device_driver *drv)
+{
+	struct fwnode_handle *fwnode = dev_fwnode(dev);
+
+	/*
+	 * Only match if the fwnode doesn't already have a proper struct device
+	 * created for it.
+	 */
+	if (fwnode && fwnode->dev != dev)
+		return 0;
+	return 1;
+}
+
 static struct bus_type gpio_bus_type = {
 	.name = "gpio",
 	.match = gpio_bus_match,
@@ -4417,20 +4430,6 @@ void gpiod_put_array(struct gpio_descs *descs)
 }
 EXPORT_SYMBOL_GPL(gpiod_put_array);
 
-
-static int gpio_bus_match(struct device *dev, struct device_driver *drv)
-{
-	struct fwnode_handle *fwnode = dev_fwnode(dev);
-
-	/*
-	 * Only match if the fwnode doesn't already have a proper struct device
-	 * created for it.
-	 */
-	if (fwnode && fwnode->dev != dev)
-		return 0;
-	return 1;
-}
-
 static int gpio_stub_drv_probe(struct device *dev)
 {
 	/*
Signature · 1 line
2.39.1
#5 lore raw

PATCH 3/3 gpiolib: Move gpiodevice_*() to gpiodev namespace

In reply to Andy Shevchenko

The functions that operates on the same device object would have the same namespace for better code understanding and maintenance.

---
 drivers/gpio/gpiolib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +2 -2
index a44a1b0f2766..45f79aee451a 100644
@@ -573,7 +573,7 @@ bool gpiochip_line_is_valid(const struct gpio_chip *gc,
 }
 EXPORT_SYMBOL_GPL(gpiochip_line_is_valid);
 
-static void gpiodevice_release(struct device *dev)
+static void gpiodev_release(struct device *dev)
 {
 	struct gpio_device *gdev = to_gpio_device(dev);
 	unsigned long flags;
@@ -617,7 +617,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
 		return ret;
 
 	/* From this point, the .release() function cleans up gpio_device */
-	gdev->dev.release = gpiodevice_release;
+	gdev->dev.release = gpiodev_release;
 
 	ret = gpiochip_sysfs_register(gdev);
 	if (ret)
Signature · 1 line
2.39.1
#6 lore raw

Re: [PATCH v1 3/3] gpiolib: Move gpiodevice_*() to gpiodev namespace

Quoted 33 lines · Andy Shevchenko

The functions that operates on the same device object would have the same namespace for better code understanding and maintenance.

---
 drivers/gpio/gpiolib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +2 -3
index a44a1b0f2766..45f79aee451a 100644
@@ -573,7 +573,7 @@ bool gpiochip_line_is_valid(const struct gpio_chip *gc,
 }
 EXPORT_SYMBOL_GPL(gpiochip_line_is_valid);
 
-static void gpiodevice_release(struct device *dev)
+static void gpiodev_release(struct device *dev)
 {
        struct gpio_device *gdev = to_gpio_device(dev);
        unsigned long flags;
@@ -617,7 +617,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
                return ret;
 
        /* From this point, the .release() function cleans up gpio_device */
-       gdev->dev.release = gpiodevice_release;
+       gdev->dev.release = gpiodev_release;
 
        ret = gpiochip_sysfs_register(gdev);
        if (ret)
--
Quoted 2 lines

2.39.1

But the only other function that's in the gpiodev_ namespace operates on struct gpio_device so that change doesn't make much sense to me.

Bart

#7 lore raw

Re: [PATCH v1 3/3] gpiolib: Move gpiodevice_*() to gpiodev namespace

Quoted 6 lines · Bartosz Golaszewski
Quoted 4 lines · Andy Shevchenko

The functions that operates on the same device object would have the same namespace for better code understanding and maintenance.

...

Quoted 12 lines
Quoted 12 lines
drivers/gpio/gpiolib.c +2 -2
-static void gpiodevice_release(struct device *dev)
+static void gpiodev_release(struct device *dev)
 {
        struct gpio_device *gdev = to_gpio_device(dev);
        unsigned long flags;
@@ -617,7 +617,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
                return ret;
 
        /* From this point, the .release() function cleans up gpio_device */
-       gdev->dev.release = gpiodevice_release;
+       gdev->dev.release = gpiodev_release;
 
Quoted 5 lines

drivers/gpio/gpiolib.c static int gpiochip_setup_dev(struct gpio_device *gdev) · line 623

Quoted 2 lines
drivers/gpio/gpiolib.c +0 -0
        ret = gpiochip_sysfs_register(gdev);
        if (ret)

But the only other function that's in the gpiodev_ namespace operates on struct gpio_device so that change doesn't make much sense to me.

I'm not sure I understood the comment.
After this change we will have

static int gpiodev_add_to_list(struct gpio_device *gdev) static void gpiodev_release(struct device *dev)

There are also gpio_device_*() I have noticed, so may be these should be actually in that namespace?

And we have

static int gpiochip_setup_dev(struct gpio_device *gdev)
static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev)

That said, what do you think is the best to make this more consistent?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: [PATCH v1 3/3] gpiolib: Move gpiodevice_*() to gpiodev namespace

Quoted 29 lines · Andy Shevchenko
Quoted 6 lines · Bartosz Golaszewski
Quoted 4 lines · Andy Shevchenko

The functions that operates on the same device object would have the same namespace for better code understanding and maintenance.

...

Quoted 12 lines
Quoted 12 lines
drivers/gpio/gpiolib.c +2 -2
-static void gpiodevice_release(struct device *dev)
+static void gpiodev_release(struct device *dev)
 {
        struct gpio_device *gdev = to_gpio_device(dev);
        unsigned long flags;
@@ -617,7 +617,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
                return ret;
 
        /* From this point, the .release() function cleans up gpio_device */
-       gdev->dev.release = gpiodevice_release;
+       gdev->dev.release = gpiodev_release;
 
Quoted 5 lines

drivers/gpio/gpiolib.c static int gpiochip_setup_dev(struct gpio_device *gdev) · line 623

Quoted 2 lines
drivers/gpio/gpiolib.c +0 -0
        ret = gpiochip_sysfs_register(gdev);
        if (ret)

But the only other function that's in the gpiodev_ namespace operates on struct gpio_device so that change doesn't make much sense to me.

Quoted 6 lines

I'm not sure I understood the comment.
After this change we will have

static int gpiodev_add_to_list(struct gpio_device *gdev) static void gpiodev_release(struct device *dev)

Do you want to use the same prefix for both because struct device in the latter is embedded in struct gpio_device in the former?

Bart

Quoted 15 lines

There are also gpio_device_*() I have noticed, so may be these should be actually in that namespace?

And we have

static int gpiochip_setup_dev(struct gpio_device *gdev)
static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev)

That said, what do you think is the best to make this more consistent?

--
With Best Regards,
Andy Shevchenko

#9 lore raw

Re: [PATCH v1 3/3] gpiolib: Move gpiodevice_*() to gpiodev namespace

Quoted 9 lines · Bartosz Golaszewski
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Bartosz Golaszewski
Quoted 4 lines · Andy Shevchenko

The functions that operates on the same device object would have the same namespace for better code understanding and maintenance.

...

Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpio/gpiolib.c +2 -2
-static void gpiodevice_release(struct device *dev)
+static void gpiodev_release(struct device *dev)
 {
        struct gpio_device *gdev = to_gpio_device(dev);
        unsigned long flags;
@@ -617,7 +617,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
                return ret;
 
        /* From this point, the .release() function cleans up gpio_device */
-       gdev->dev.release = gpiodevice_release;
+       gdev->dev.release = gpiodev_release;
 
Quoted 5 lines

drivers/gpio/gpiolib.c static int gpiochip_setup_dev(struct gpio_device *gdev) · line 623

Quoted 2 lines
drivers/gpio/gpiolib.c +0 -0
        ret = gpiochip_sysfs_register(gdev);
        if (ret)

But the only other function that's in the gpiodev_ namespace operates on struct gpio_device so that change doesn't make much sense to me.

I'm not sure I understood the comment.
After this change we will have

Quoted 6 lines
Quoted 3 lines

static int gpiodev_add_to_list(struct gpio_device *gdev) static void gpiodev_release(struct device *dev)

Do you want to use the same prefix for both because struct device in the latter is embedded in struct gpio_device in the former?

Yes, the logic to have logically grouped namespace for these APIs. Meaning on what they are taking as an effective object to proceed with.

Quoted 9 lines
Quoted 9 lines

There are also gpio_device_*() I have noticed, so may be these should be actually in that namespace?

And we have

static int gpiochip_setup_dev(struct gpio_device *gdev)
static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev)

That said, what do you think is the best to make this more consistent?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw

Re: [PATCH v1 3/3] gpiolib: Move gpiodevice_*() to gpiodev namespace

Quoted 39 lines · Andy Shevchenko
Quoted 9 lines · Bartosz Golaszewski
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Bartosz Golaszewski
Quoted 4 lines · Andy Shevchenko

The functions that operates on the same device object would have the same namespace for better code understanding and maintenance.

...

Quoted 25 lines
Quoted 24 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpio/gpiolib.c +2 -2
-static void gpiodevice_release(struct device *dev)
+static void gpiodev_release(struct device *dev)
 {
        struct gpio_device *gdev = to_gpio_device(dev);
        unsigned long flags;
@@ -617,7 +617,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
                return ret;
 
        /* From this point, the .release() function cleans up gpio_device */
-       gdev->dev.release = gpiodevice_release;
+       gdev->dev.release = gpiodev_release;
 
Quoted 5 lines

drivers/gpio/gpiolib.c static int gpiochip_setup_dev(struct gpio_device *gdev) · line 623

Quoted 2 lines
drivers/gpio/gpiolib.c +0 -0
        ret = gpiochip_sysfs_register(gdev);
        if (ret)

But the only other function that's in the gpiodev_ namespace operates on struct gpio_device so that change doesn't make much sense to me.

I'm not sure I understood the comment.
After this change we will have

static int gpiodev_add_to_list(struct gpio_device *gdev) static void gpiodev_release(struct device *dev)

Quoted 7 lines
Quoted 2 lines

Do you want to use the same prefix for both because struct device in the latter is embedded in struct gpio_device in the former?

Yes, the logic to have logically grouped namespace for these APIs. Meaning on what they are taking as an effective object to proceed with.

I don't have a better idea so applied it.

Bart

Quoted 15 lines
Quoted 9 lines
Quoted 9 lines

There are also gpio_device_*() I have noticed, so may be these should be actually in that namespace?

And we have

static int gpiochip_setup_dev(struct gpio_device *gdev)
static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev)

That said, what do you think is the best to make this more consistent?

--
With Best Regards,
Andy Shevchenko

#11 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

A few cleanups to GPIO device handling in the library code.

Andy Shevchenko (3):
gpiolib: Access device's fwnode via dev_fwnode()
gpiolib: Get rid of gpio_bus_match() forward declaration
gpiolib: Move gpiodevice_*() to gpiodev namespace

Quoted 6 lines
 drivers/gpio/gpiolib.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

--
2.39.1

I applied the first two patches, for the third I have a comment.

Bart

#12 lore raw
Quoted 11 lines · Bartosz Golaszewski
Quoted 7 lines · Andy Shevchenko

A few cleanups to GPIO device handling in the library code.

Andy Shevchenko (3):
gpiolib: Access device's fwnode via dev_fwnode()
gpiolib: Get rid of gpio_bus_match() forward declaration
gpiolib: Move gpiodevice_*() to gpiodev namespace

I applied the first two patches, for the third I have a comment.

Thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko