2023-10-11 13:02:41

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 3/3] i2c: mux: gpio: don't fiddle with GPIOLIB internals

From: Bartosz Golaszewski <[email protected]>

Use the relevant API functions to retrieve the address of the
underlying struct device instead of accessing GPIOLIB private structures
manually.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/i2c/muxes/i2c-mux-gpio.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
index 5d5cbe0130cd..48a872a8196b 100644
--- a/drivers/i2c/muxes/i2c-mux-gpio.c
+++ b/drivers/i2c/muxes/i2c-mux-gpio.c
@@ -14,8 +14,7 @@
#include <linux/slab.h>
#include <linux/bits.h>
#include <linux/gpio/consumer.h>
-/* FIXME: stop poking around inside gpiolib */
-#include "../../gpio/gpiolib.h"
+#include <linux/gpio/driver.h>

struct gpiomux {
struct i2c_mux_gpio_platform_data data;
@@ -176,7 +175,8 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
}

for (i = 0; i < ngpios; i++) {
- struct device *gpio_dev;
+ struct gpio_device *gdev;
+ struct device *dev;
struct gpio_desc *gpiod;
enum gpiod_flags flag;

@@ -195,9 +195,9 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
if (!muxc->mux_locked)
continue;

- /* FIXME: find a proper way to access the GPIO device */
- gpio_dev = &gpiod->gdev->dev;
- muxc->mux_locked = i2c_root_adapter(gpio_dev) == root;
+ gdev = gpiod_to_gpio_device(gpiod);
+ dev = gpio_device_to_device(gdev);
+ muxc->mux_locked = i2c_root_adapter(dev) == root;
}

if (muxc->mux_locked)
--
2.39.2


2023-10-11 14:59:33

by Peter Rosin

[permalink] [raw]
Subject: Re: [PATCH 3/3] i2c: mux: gpio: don't fiddle with GPIOLIB internals

Hi!

2023-10-11 at 15:02, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <[email protected]>
>
> Use the relevant API functions to retrieve the address of the
> underlying struct device instead of accessing GPIOLIB private structures
> manually.
>
> Signed-off-by: Bartosz Golaszewski <[email protected]>
> ---
> drivers/i2c/muxes/i2c-mux-gpio.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
> index 5d5cbe0130cd..48a872a8196b 100644
> --- a/drivers/i2c/muxes/i2c-mux-gpio.c
> +++ b/drivers/i2c/muxes/i2c-mux-gpio.c
> @@ -14,8 +14,7 @@
> #include <linux/slab.h>
> #include <linux/bits.h>
> #include <linux/gpio/consumer.h>
> -/* FIXME: stop poking around inside gpiolib */
> -#include "../../gpio/gpiolib.h"
> +#include <linux/gpio/driver.h>
>
> struct gpiomux {
> struct i2c_mux_gpio_platform_data data;
> @@ -176,7 +175,8 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
> }
>
> for (i = 0; i < ngpios; i++) {
> - struct device *gpio_dev;
> + struct gpio_device *gdev;
> + struct device *dev;
> struct gpio_desc *gpiod;
> enum gpiod_flags flag;
>
> @@ -195,9 +195,9 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
> if (!muxc->mux_locked)
> continue;
>
> - /* FIXME: find a proper way to access the GPIO device */
> - gpio_dev = &gpiod->gdev->dev;
> - muxc->mux_locked = i2c_root_adapter(gpio_dev) == root;
> + gdev = gpiod_to_gpio_device(gpiod);
> + dev = gpio_device_to_device(gdev);
> + muxc->mux_locked = i2c_root_adapter(dev) == root;
> }
>
> if (muxc->mux_locked)

Very nice to see that wart gone! The only small question I have
is if these helpers are needed elsewhere, or if a more "direct"
gpiod_to_device() would have been sufficient? That said, I have
zero problem with this new code as-is, and that detail is of
course squarely in gpio-land.

Acked-by: Peter Rosin <[email protected]>

Cheers,
Peter

2023-10-11 15:03:43

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH 3/3] i2c: mux: gpio: don't fiddle with GPIOLIB internals

On Wed, Oct 11, 2023 at 4:59 PM Peter Rosin <[email protected]> wrote:
>
> Hi!
>
> 2023-10-11 at 15:02, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <[email protected]>
> >
> > Use the relevant API functions to retrieve the address of the
> > underlying struct device instead of accessing GPIOLIB private structures
> > manually.
> >
> > Signed-off-by: Bartosz Golaszewski <[email protected]>
> > ---
> > drivers/i2c/muxes/i2c-mux-gpio.c | 12 ++++++------
> > 1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
> > index 5d5cbe0130cd..48a872a8196b 100644
> > --- a/drivers/i2c/muxes/i2c-mux-gpio.c
> > +++ b/drivers/i2c/muxes/i2c-mux-gpio.c
> > @@ -14,8 +14,7 @@
> > #include <linux/slab.h>
> > #include <linux/bits.h>
> > #include <linux/gpio/consumer.h>
> > -/* FIXME: stop poking around inside gpiolib */
> > -#include "../../gpio/gpiolib.h"
> > +#include <linux/gpio/driver.h>
> >
> > struct gpiomux {
> > struct i2c_mux_gpio_platform_data data;
> > @@ -176,7 +175,8 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
> > }
> >
> > for (i = 0; i < ngpios; i++) {
> > - struct device *gpio_dev;
> > + struct gpio_device *gdev;
> > + struct device *dev;
> > struct gpio_desc *gpiod;
> > enum gpiod_flags flag;
> >
> > @@ -195,9 +195,9 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
> > if (!muxc->mux_locked)
> > continue;
> >
> > - /* FIXME: find a proper way to access the GPIO device */
> > - gpio_dev = &gpiod->gdev->dev;
> > - muxc->mux_locked = i2c_root_adapter(gpio_dev) == root;
> > + gdev = gpiod_to_gpio_device(gpiod);
> > + dev = gpio_device_to_device(gdev);
> > + muxc->mux_locked = i2c_root_adapter(dev) == root;
> > }
> >
> > if (muxc->mux_locked)
>
> Very nice to see that wart gone! The only small question I have
> is if these helpers are needed elsewhere, or if a more "direct"
> gpiod_to_device() would have been sufficient? That said, I have
> zero problem with this new code as-is, and that detail is of
> course squarely in gpio-land.
>
> Acked-by: Peter Rosin <[email protected]>

gpiod_to_gpio_device() will be used in at least 10 other places. I
haven't identified any other potential user for
gpio_device_to_device() yet but I haven't looked hard yet either.

Bart

>
> Cheers,
> Peter

2023-10-11 15:19:23

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 3/3] i2c: mux: gpio: don't fiddle with GPIOLIB internals

On Wed, Oct 11, 2023 at 5:59 PM Peter Rosin <[email protected]> wrote:
> 2023-10-11 at 15:02, Bartosz Golaszewski wrote:

> > Use the relevant API functions to retrieve the address of the
> > underlying struct device instead of accessing GPIOLIB private structures
> > manually.

> Very nice to see that wart gone! The only small question I have
> is if these helpers are needed elsewhere, or if a more "direct"
> gpiod_to_device() would have been sufficient?

Same concern is here. But I'm fine with the code.

--
With Best Regards,
Andy Shevchenko

2023-10-11 16:42:01

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 3/3] i2c: mux: gpio: don't fiddle with GPIOLIB internals

Hi Bartosz,

> > > -/* FIXME: stop poking around inside gpiolib */
> > > -#include "../../gpio/gpiolib.h"
> > > +#include <linux/gpio/driver.h>

Hooray! \o/

> gpiod_to_gpio_device() will be used in at least 10 other places. I
> haven't identified any other potential user for
> gpio_device_to_device() yet but I haven't looked hard yet either.

Same here. Looked a little bit, found nothing.

Acked-by: Wolfram Sang <[email protected]>


Attachments:
(No filename) (451.00 B)
signature.asc (849.00 B)
Download all attachments