[01/10] leds: pca953x: Use of_device_get_match_data()
diff mbox series

Message ID 20191004214334.149976-2-swboyd@chromium.org
State New
Headers show
Series
  • Stop NULLifying match pointer in of_match_device()
Related show

Commit Message

Stephen Boyd Oct. 4, 2019, 9:43 p.m. UTC
This driver can use the of_device_get_match_data() API to simplify the
code. Replace calls to of_match_device() with this newer API under the
assumption that where it is called will be when we know the device is
backed by a DT node. This nicely avoids referencing the match table when
it is undefined with configurations where CONFIG_OF=n.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Riku Voipio <riku.voipio@iki.fi>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Dan Murphy <dmurphy@ti.com>
Cc: <linux-leds@vger.kernel.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---

Please ack or pick for immediate merge so the last patch can be merged.

 drivers/leds/leds-pca9532.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

Comments

Jacek Anaszewski Oct. 6, 2019, 12:15 p.m. UTC | #1
On 10/4/19 11:43 PM, Stephen Boyd wrote:
> This driver can use the of_device_get_match_data() API to simplify the
> code. Replace calls to of_match_device() with this newer API under the
> assumption that where it is called will be when we know the device is
> backed by a DT node. This nicely avoids referencing the match table when
> it is undefined with configurations where CONFIG_OF=n.
> 
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Riku Voipio <riku.voipio@iki.fi>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Dan Murphy <dmurphy@ti.com>
> Cc: <linux-leds@vger.kernel.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
> 
> Please ack or pick for immediate merge so the last patch can be merged.
> 
>  drivers/leds/leds-pca9532.c | 14 ++------------
>  1 file changed, 2 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
> index c7c7199e8ebd..7d515d5e57bd 100644
> --- a/drivers/leds/leds-pca9532.c
> +++ b/drivers/leds/leds-pca9532.c
> @@ -467,16 +467,11 @@ pca9532_of_populate_pdata(struct device *dev, struct device_node *np)
>  {
>  	struct pca9532_platform_data *pdata;
>  	struct device_node *child;
> -	const struct of_device_id *match;
>  	int devid, maxleds;
>  	int i = 0;
>  	const char *state;
>  
> -	match = of_match_device(of_pca9532_leds_match, dev);
> -	if (!match)
> -		return ERR_PTR(-ENODEV);
> -
> -	devid = (int)(uintptr_t)match->data;
> +	devid = (int)(uintptr_t)of_device_get_match_data(dev);
>  	maxleds = pca9532_chip_info_tbl[devid].num_leds;
>  
>  	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
> @@ -509,7 +504,6 @@ static int pca9532_probe(struct i2c_client *client,
>  	const struct i2c_device_id *id)
>  {
>  	int devid;
> -	const struct of_device_id *of_id;
>  	struct pca9532_data *data = i2c_get_clientdata(client);
>  	struct pca9532_platform_data *pca9532_pdata =
>  			dev_get_platdata(&client->dev);
> @@ -525,11 +519,7 @@ static int pca9532_probe(struct i2c_client *client,
>  			dev_err(&client->dev, "no platform data\n");
>  			return -EINVAL;
>  		}
> -		of_id = of_match_device(of_pca9532_leds_match,
> -				&client->dev);
> -		if (unlikely(!of_id))
> -			return -EINVAL;
> -		devid = (int)(uintptr_t) of_id->data;
> +		devid = (int)(uintptr_t)of_device_get_match_data(&client->dev);
>  	} else {
>  		devid = id->driver_data;
>  	}
> 

Acked-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Geert Uytterhoeven Oct. 7, 2019, 8:01 a.m. UTC | #2
On Fri, Oct 4, 2019 at 11:43 PM Stephen Boyd <swboyd@chromium.org> wrote:
> This driver can use the of_device_get_match_data() API to simplify the
> code. Replace calls to of_match_device() with this newer API under the
> assumption that where it is called will be when we know the device is
> backed by a DT node. This nicely avoids referencing the match table when
> it is undefined with configurations where CONFIG_OF=n.
>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Riku Voipio <riku.voipio@iki.fi>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Dan Murphy <dmurphy@ti.com>
> Cc: <linux-leds@vger.kernel.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert
Pavel Machek Oct. 13, 2019, 12:10 p.m. UTC | #3
On Fri 2019-10-04 14:43:25, Stephen Boyd wrote:
> This driver can use the of_device_get_match_data() API to simplify the
> code. Replace calls to of_match_device() with this newer API under the
> assumption that where it is called will be when we know the device is
> backed by a DT node. This nicely avoids referencing the match table when
> it is undefined with configurations where CONFIG_OF=n.

Thanks, applied.

								Pavel

> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Riku Voipio <riku.voipio@iki.fi>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Dan Murphy <dmurphy@ti.com>
> Cc: <linux-leds@vger.kernel.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
> 
> Please ack or pick for immediate merge so the last patch can be merged.
> 
>  drivers/leds/leds-pca9532.c | 14 ++------------
>  1 file changed, 2 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
> index c7c7199e8ebd..7d515d5e57bd 100644
> --- a/drivers/leds/leds-pca9532.c
> +++ b/drivers/leds/leds-pca9532.c
> @@ -467,16 +467,11 @@ pca9532_of_populate_pdata(struct device *dev, struct device_node *np)
>  {
>  	struct pca9532_platform_data *pdata;
>  	struct device_node *child;
> -	const struct of_device_id *match;
>  	int devid, maxleds;
>  	int i = 0;
>  	const char *state;
>  
> -	match = of_match_device(of_pca9532_leds_match, dev);
> -	if (!match)
> -		return ERR_PTR(-ENODEV);
> -
> -	devid = (int)(uintptr_t)match->data;
> +	devid = (int)(uintptr_t)of_device_get_match_data(dev);
>  	maxleds = pca9532_chip_info_tbl[devid].num_leds;
>  
>  	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
> @@ -509,7 +504,6 @@ static int pca9532_probe(struct i2c_client *client,
>  	const struct i2c_device_id *id)
>  {
>  	int devid;
> -	const struct of_device_id *of_id;
>  	struct pca9532_data *data = i2c_get_clientdata(client);
>  	struct pca9532_platform_data *pca9532_pdata =
>  			dev_get_platdata(&client->dev);
> @@ -525,11 +519,7 @@ static int pca9532_probe(struct i2c_client *client,
>  			dev_err(&client->dev, "no platform data\n");
>  			return -EINVAL;
>  		}
> -		of_id = of_match_device(of_pca9532_leds_match,
> -				&client->dev);
> -		if (unlikely(!of_id))
> -			return -EINVAL;
> -		devid = (int)(uintptr_t) of_id->data;
> +		devid = (int)(uintptr_t)of_device_get_match_data(&client->dev);
>  	} else {
>  		devid = id->driver_data;
>  	}
Andy Shevchenko Oct. 14, 2019, 5:50 p.m. UTC | #4
On Sat, Oct 5, 2019 at 12:47 AM Stephen Boyd <swboyd@chromium.org> wrote:
>
> This driver can use the of_device_get_match_data() API to simplify the
> code. Replace calls to of_match_device() with this newer API under the
> assumption that where it is called will be when we know the device is
> backed by a DT node. This nicely avoids referencing the match table when
> it is undefined with configurations where CONFIG_OF=n.

> +       devid = (int)(uintptr_t)of_device_get_match_data(dev);

> +               devid = (int)(uintptr_t)of_device_get_match_data(&client->dev);

This still leaves it OF-centric.
Better to use device_get_match_data().

Also, I'm thinking that following may help to clean a lot of the i2c
client drivers

static inline // perhaps no
const void *i2c_device_get_match_data(struct i2c_client *client, const
struct i2c_device_id *id)
{
  if (id)
    return (const void *)id->driver_data;
  return device_get_match_data(&client->dev);
}
Stephen Boyd Oct. 14, 2019, 8:54 p.m. UTC | #5
Quoting Andy Shevchenko (2019-10-14 10:50:06)
> On Sat, Oct 5, 2019 at 12:47 AM Stephen Boyd <swboyd@chromium.org> wrote:
> >
> > This driver can use the of_device_get_match_data() API to simplify the
> > code. Replace calls to of_match_device() with this newer API under the
> > assumption that where it is called will be when we know the device is
> > backed by a DT node. This nicely avoids referencing the match table when
> > it is undefined with configurations where CONFIG_OF=n.
> 
> > +       devid = (int)(uintptr_t)of_device_get_match_data(dev);
> 
> > +               devid = (int)(uintptr_t)of_device_get_match_data(&client->dev);
> 
> This still leaves it OF-centric.
> Better to use device_get_match_data().
> 
> Also, I'm thinking that following may help to clean a lot of the i2c
> client drivers
> 
> static inline // perhaps no
> const void *i2c_device_get_match_data(struct i2c_client *client, const
> struct i2c_device_id *id)
> {
>   if (id)
>     return (const void *)id->driver_data;
>   return device_get_match_data(&client->dev);
> }
> 

Looks alright to me. Maybe device_get_match_data() can look at the bus
and call some bus op if the firmware match isn't present? Then we can
replace a bunch of these calls with device_get_match_data() and it will
"do the right thing" regardless of what bus or firmware the device is
running on.
Andy Shevchenko Oct. 15, 2019, 9:02 a.m. UTC | #6
On Mon, Oct 14, 2019 at 11:54 PM Stephen Boyd <swboyd@chromium.org> wrote:
> Quoting Andy Shevchenko (2019-10-14 10:50:06)
> > On Sat, Oct 5, 2019 at 12:47 AM Stephen Boyd <swboyd@chromium.org> wrote:
> > >
> > > This driver can use the of_device_get_match_data() API to simplify the
> > > code. Replace calls to of_match_device() with this newer API under the
> > > assumption that where it is called will be when we know the device is
> > > backed by a DT node. This nicely avoids referencing the match table when
> > > it is undefined with configurations where CONFIG_OF=n.
> >
> > > +       devid = (int)(uintptr_t)of_device_get_match_data(dev);
> >
> > > +               devid = (int)(uintptr_t)of_device_get_match_data(&client->dev);
> >
> > This still leaves it OF-centric.
> > Better to use device_get_match_data().
> >
> > Also, I'm thinking that following may help to clean a lot of the i2c
> > client drivers
> >
> > static inline // perhaps no
> > const void *i2c_device_get_match_data(struct i2c_client *client, const
> > struct i2c_device_id *id)
> > {
> >   if (id)
> >     return (const void *)id->driver_data;
> >   return device_get_match_data(&client->dev);
> > }
> >
>
> Looks alright to me. Maybe device_get_match_data() can look at the bus
> and call some bus op if the firmware match isn't present? Then we can
> replace a bunch of these calls with device_get_match_data() and it will
> "do the right thing" regardless of what bus or firmware the device is
> running on.

It will be something ugly like

buses {
#ifdef I2C
&i2c_bus_type,
#endif
...
}

in the code. I won't do this.

See generic_match_buses[] for example.
Stephen Boyd Oct. 15, 2019, 10:41 p.m. UTC | #7
Quoting Andy Shevchenko (2019-10-15 02:02:01)
> On Mon, Oct 14, 2019 at 11:54 PM Stephen Boyd <swboyd@chromium.org> wrote:
> > Quoting Andy Shevchenko (2019-10-14 10:50:06)
> > > On Sat, Oct 5, 2019 at 12:47 AM Stephen Boyd <swboyd@chromium.org> wrote:
> > > >
> > > > This driver can use the of_device_get_match_data() API to simplify the
> > > > code. Replace calls to of_match_device() with this newer API under the
> > > > assumption that where it is called will be when we know the device is
> > > > backed by a DT node. This nicely avoids referencing the match table when
> > > > it is undefined with configurations where CONFIG_OF=n.
> > >
> > > > +       devid = (int)(uintptr_t)of_device_get_match_data(dev);
> > >
> > > > +               devid = (int)(uintptr_t)of_device_get_match_data(&client->dev);
> > >
> > > This still leaves it OF-centric.
> > > Better to use device_get_match_data().
> > >
> > > Also, I'm thinking that following may help to clean a lot of the i2c
> > > client drivers
> > >
> > > static inline // perhaps no
> > > const void *i2c_device_get_match_data(struct i2c_client *client, const
> > > struct i2c_device_id *id)
> > > {
> > >   if (id)
> > >     return (const void *)id->driver_data;
> > >   return device_get_match_data(&client->dev);
> > > }
> > >
> >
> > Looks alright to me. Maybe device_get_match_data() can look at the bus
> > and call some bus op if the firmware match isn't present? Then we can
> > replace a bunch of these calls with device_get_match_data() and it will
> > "do the right thing" regardless of what bus or firmware the device is
> > running on.
> 
> It will be something ugly like
> 
> buses {
> #ifdef I2C
> &i2c_bus_type,
> #endif
> ...
> }
> 
> in the code. I won't do this.
> 
> See generic_match_buses[] for example.

Why is it like generic_match_buses[]? I thought it would look at
struct device::of_node or struct device::fw_node and try to extract
device data out that and if that fails it would fallback to some new
function like struct bus_type::get_match_data() that does the right
thing for the bus. In the case of i2c it would extract the i2c_client's
i2c_device_id pointer and return it onwards.
Andy Shevchenko Oct. 16, 2019, 1:46 p.m. UTC | #8
On Wed, Oct 16, 2019 at 1:42 AM Stephen Boyd <swboyd@chromium.org> wrote:
> Quoting Andy Shevchenko (2019-10-15 02:02:01)
> > On Mon, Oct 14, 2019 at 11:54 PM Stephen Boyd <swboyd@chromium.org> wrote:
> > > Quoting Andy Shevchenko (2019-10-14 10:50:06)
> > > > On Sat, Oct 5, 2019 at 12:47 AM Stephen Boyd <swboyd@chromium.org> wrote:

> > > > Also, I'm thinking that following may help to clean a lot of the i2c
> > > > client drivers
> > > >
> > > > static inline // perhaps no
> > > > const void *i2c_device_get_match_data(struct i2c_client *client, const
> > > > struct i2c_device_id *id)
> > > > {
> > > >   if (id)
> > > >     return (const void *)id->driver_data;
> > > >   return device_get_match_data(&client->dev);
> > > > }
> > > >
> > >
> > > Looks alright to me. Maybe device_get_match_data() can look at the bus
> > > and call some bus op if the firmware match isn't present? Then we can
> > > replace a bunch of these calls with device_get_match_data() and it will
> > > "do the right thing" regardless of what bus or firmware the device is
> > > running on.
> >
> > It will be something ugly like
> >
> > buses {
> > #ifdef I2C
> > &i2c_bus_type,
> > #endif
> > ...
> > }
> >
> > in the code. I won't do this.
> >
> > See generic_match_buses[] for example.
>
> Why is it like generic_match_buses[]? I thought it would look at
> struct device::of_node or struct device::fw_node and try to extract
> device data out that and if that fails it would fallback to some new
> function like struct bus_type::get_match_data() that does the right
> thing for the bus. In the case of i2c it would extract the i2c_client's
> i2c_device_id pointer and return it onwards.

Can you send a patch for review?
Pavel Machek Nov. 4, 2019, 9:09 a.m. UTC | #9
Hi!

> This driver can use the of_device_get_match_data() API to simplify the
> code. Replace calls to of_match_device() with this newer API under the
> assumption that where it is called will be when we know the device is
> backed by a DT node. This nicely avoids referencing the match table when
> it is undefined with configurations where CONFIG_OF=n.


> Please ack or pick for immediate merge so the last patch can be
  merged.

I see nothing obviously wrong, so...

Acked-by: Pavel Machek <pavel@ucw.cz>

... but it did not apply on top of leds-next tree.

Best regards,
									Pavel

Patch
diff mbox series

diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index c7c7199e8ebd..7d515d5e57bd 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -467,16 +467,11 @@  pca9532_of_populate_pdata(struct device *dev, struct device_node *np)
 {
 	struct pca9532_platform_data *pdata;
 	struct device_node *child;
-	const struct of_device_id *match;
 	int devid, maxleds;
 	int i = 0;
 	const char *state;
 
-	match = of_match_device(of_pca9532_leds_match, dev);
-	if (!match)
-		return ERR_PTR(-ENODEV);
-
-	devid = (int)(uintptr_t)match->data;
+	devid = (int)(uintptr_t)of_device_get_match_data(dev);
 	maxleds = pca9532_chip_info_tbl[devid].num_leds;
 
 	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
@@ -509,7 +504,6 @@  static int pca9532_probe(struct i2c_client *client,
 	const struct i2c_device_id *id)
 {
 	int devid;
-	const struct of_device_id *of_id;
 	struct pca9532_data *data = i2c_get_clientdata(client);
 	struct pca9532_platform_data *pca9532_pdata =
 			dev_get_platdata(&client->dev);
@@ -525,11 +519,7 @@  static int pca9532_probe(struct i2c_client *client,
 			dev_err(&client->dev, "no platform data\n");
 			return -EINVAL;
 		}
-		of_id = of_match_device(of_pca9532_leds_match,
-				&client->dev);
-		if (unlikely(!of_id))
-			return -EINVAL;
-		devid = (int)(uintptr_t) of_id->data;
+		devid = (int)(uintptr_t)of_device_get_match_data(&client->dev);
 	} else {
 		devid = id->driver_data;
 	}