linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] merge calls to of_match_device and of_device_get_match_data
@ 2018-05-21  9:49 Julia Lawall
  2018-05-21  9:49 ` [PATCH 1/3] i2c: mux: pca954x: " Julia Lawall
  2018-05-21  9:49 ` [PATCH 3/3] iio: potentiometer: " Julia Lawall
  0 siblings, 2 replies; 6+ messages in thread
From: Julia Lawall @ 2018-05-21  9:49 UTC (permalink / raw)
  To: linux-i2c
  Cc: kernel-janitors, linux-kernel, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, linux-iio,
	Himanshu Jha

of_device_get_match_data calls of_match_device and fails if the latter
fails, so both calls aren't needed.

---

 drivers/i2c/muxes/i2c-mux-pca954x.c |    7 ++-----
 drivers/iio/adc/max1363.c           |    8 ++------
 drivers/iio/potentiometer/max5481.c |    7 ++-----
 drivers/iio/potentiometer/mcp4018.c |    7 ++-----
 drivers/iio/potentiometer/mcp4531.c |    7 ++-----
 5 files changed, 10 insertions(+), 26 deletions(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] i2c: mux: pca954x: merge calls to of_match_device and of_device_get_match_data
  2018-05-21  9:49 [PATCH 0/3] merge calls to of_match_device and of_device_get_match_data Julia Lawall
@ 2018-05-21  9:49 ` Julia Lawall
  2018-05-24 11:53   ` Peter Rosin
  2018-05-21  9:49 ` [PATCH 3/3] iio: potentiometer: " Julia Lawall
  1 sibling, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2018-05-21  9:49 UTC (permalink / raw)
  To: Peter Rosin; +Cc: kernel-janitors, linux-i2c, linux-kernel, Himanshu Jha

Drop call to of_match_device, which is subsumed by the subsequent
call to of_device_get_match_data.  The code becomes simpler, and a
temporary variable can be dropped.

The semantic match that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
local idexpression match;
identifier i;
expression x, dev, e, e1;
@@
-        match@i = of_match_device(x, dev);
-        if (match) e = of_device_get_match_data(dev);
-        else e = e1;
+        e = of_device_get_match_data(dev);
+        if (!e) e = e1;

@@
identifier r.i;
@@
- const struct of_device_id *i;
... when != i
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/i2c/muxes/i2c-mux-pca954x.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 09bafd3..ced840f 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -373,7 +373,6 @@ static int pca954x_probe(struct i2c_client *client,
 	int num, force, class;
 	struct i2c_mux_core *muxc;
 	struct pca954x *data;
-	const struct of_device_id *match;
 	int ret;
 
 	if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE))
@@ -394,10 +393,8 @@ static int pca954x_probe(struct i2c_client *client,
 	if (IS_ERR(gpio))
 		return PTR_ERR(gpio);
 
-	match = of_match_device(of_match_ptr(pca954x_of_match), &client->dev);
-	if (match)
-		data->chip = of_device_get_match_data(&client->dev);
-	else
+	data->chip = of_device_get_match_data(&client->dev);
+	if (!data->chip)
 		data->chip = &chips[id->driver_data];
 
 	if (data->chip->id.manufacturer_id != I2C_DEVICE_ID_NONE) {

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] iio: potentiometer: merge calls to of_match_device and of_device_get_match_data
  2018-05-21  9:49 [PATCH 0/3] merge calls to of_match_device and of_device_get_match_data Julia Lawall
  2018-05-21  9:49 ` [PATCH 1/3] i2c: mux: pca954x: " Julia Lawall
@ 2018-05-21  9:49 ` Julia Lawall
  2018-08-19  7:02   ` Peter Rosin
  1 sibling, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2018-05-21  9:49 UTC (permalink / raw)
  To: Peter Meerwald-Stadler
  Cc: kernel-janitors, linux-kernel, linux-iio, Lars-Peter Clausen,
	Hartmut Knaack, Jonathan Cameron, Peter Rosin, Himanshu Jha

Drop call to of_match_device, which is subsumed by the subsequent
call to of_device_get_match_data.  The code becomes simpler, and a
temporary variable can be dropped.

The semantic match that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
local idexpression match;
identifier i;
expression x, dev, e, e1;
@@
-        match@i = of_match_device(x, dev);
-        if (match) e = of_device_get_match_data(dev);
-        else e = e1;
+        e = of_device_get_match_data(dev);
+        if (!e) e = e1;

@@
identifier r.i;
@@
- const struct of_device_id *i;
... when != i
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/iio/potentiometer/max5481.c |    7 ++-----
 drivers/iio/potentiometer/mcp4018.c |    7 ++-----
 drivers/iio/potentiometer/mcp4531.c |    7 ++-----
 3 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/drivers/iio/potentiometer/mcp4018.c b/drivers/iio/potentiometer/mcp4018.c
index 320a7c9..c051ee0 100644
--- a/drivers/iio/potentiometer/mcp4018.c
+++ b/drivers/iio/potentiometer/mcp4018.c
@@ -147,7 +147,6 @@ static int mcp4018_probe(struct i2c_client *client)
 	struct device *dev = &client->dev;
 	struct mcp4018_data *data;
 	struct iio_dev *indio_dev;
-	const struct of_device_id *match;
 
 	if (!i2c_check_functionality(client->adapter,
 				     I2C_FUNC_SMBUS_BYTE)) {
@@ -162,10 +161,8 @@ static int mcp4018_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, indio_dev);
 	data->client = client;
 
-	match = of_match_device(of_match_ptr(mcp4018_of_match), dev);
-	if (match)
-		data->cfg = of_device_get_match_data(dev);
-	else
+	data->cfg = of_device_get_match_data(dev);
+	if (!data->cfg)
 		data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data];
 
 	indio_dev->dev.parent = dev;
diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
index df894af..d87ca85 100644
--- a/drivers/iio/potentiometer/mcp4531.c
+++ b/drivers/iio/potentiometer/mcp4531.c
@@ -360,7 +360,6 @@ static int mcp4531_probe(struct i2c_client *client)
 	struct device *dev = &client->dev;
 	struct mcp4531_data *data;
 	struct iio_dev *indio_dev;
-	const struct of_device_id *match;
 
 	if (!i2c_check_functionality(client->adapter,
 				     I2C_FUNC_SMBUS_WORD_DATA)) {
@@ -375,10 +374,8 @@ static int mcp4531_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, indio_dev);
 	data->client = client;
 
-	match = of_match_device(of_match_ptr(mcp4531_of_match), dev);
-	if (match)
-		data->cfg = of_device_get_match_data(dev);
-	else
+	data->cfg = of_device_get_match_data(dev);
+	if (!data->cfg)
 		data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data];
 
 	indio_dev->dev.parent = dev;
diff --git a/drivers/iio/potentiometer/max5481.c b/drivers/iio/potentiometer/max5481.c
index ffe2761..6d2f13f 100644
--- a/drivers/iio/potentiometer/max5481.c
+++ b/drivers/iio/potentiometer/max5481.c
@@ -137,7 +137,6 @@ static int max5481_probe(struct spi_device *spi)
 	struct iio_dev *indio_dev;
 	struct max5481_data *data;
 	const struct spi_device_id *id = spi_get_device_id(spi);
-	const struct of_device_id *match;
 	int ret;
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
@@ -149,10 +148,8 @@ static int max5481_probe(struct spi_device *spi)
 
 	data->spi = spi;
 
-	match = of_match_device(of_match_ptr(max5481_match), &spi->dev);
-	if (match)
-		data->cfg = of_device_get_match_data(&spi->dev);
-	else
+	data->cfg = of_device_get_match_data(&spi->dev);
+	if (!data->cfg)
 		data->cfg = &max5481_cfg[id->driver_data];
 
 	indio_dev->name = id->name;

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] i2c: mux: pca954x: merge calls to of_match_device and of_device_get_match_data
  2018-05-21  9:49 ` [PATCH 1/3] i2c: mux: pca954x: " Julia Lawall
@ 2018-05-24 11:53   ` Peter Rosin
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Rosin @ 2018-05-24 11:53 UTC (permalink / raw)
  To: Julia Lawall; +Cc: kernel-janitors, linux-i2c, linux-kernel, Himanshu Jha

On 2018-05-21 11:49, Julia Lawall wrote:
> Drop call to of_match_device, which is subsumed by the subsequent
> call to of_device_get_match_data.  The code becomes simpler, and a
> temporary variable can be dropped.

Thanks for your patch!

Applied to i2c-mux/for-next

Cheers,
Peter

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] iio: potentiometer: merge calls to of_match_device and of_device_get_match_data
  2018-05-21  9:49 ` [PATCH 3/3] iio: potentiometer: " Julia Lawall
@ 2018-08-19  7:02   ` Peter Rosin
  2018-08-19 19:17     ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Rosin @ 2018-08-19  7:02 UTC (permalink / raw)
  To: Julia Lawall, Peter Meerwald-Stadler
  Cc: kernel-janitors, linux-kernel, linux-iio, Lars-Peter Clausen,
	Hartmut Knaack, Jonathan Cameron, Himanshu Jha

On 2018-05-21 11:49, Julia Lawall wrote:
> Drop call to of_match_device, which is subsumed by the subsequent
> call to of_device_get_match_data.  The code becomes simpler, and a
> temporary variable can be dropped.
> 
> The semantic match that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @r@
> local idexpression match;
> identifier i;
> expression x, dev, e, e1;
> @@
> -        match@i = of_match_device(x, dev);
> -        if (match) e = of_device_get_match_data(dev);
> -        else e = e1;
> +        e = of_device_get_match_data(dev);
> +        if (!e) e = e1;
> 
> @@
> identifier r.i;
> @@
> - const struct of_device_id *i;
> ... when != i
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Reviewed-by: Peter Rosin <peda@axentia.se>

Cheers,
Peter

> 
> ---
>  drivers/iio/potentiometer/max5481.c |    7 ++-----
>  drivers/iio/potentiometer/mcp4018.c |    7 ++-----
>  drivers/iio/potentiometer/mcp4531.c |    7 ++-----
>  3 files changed, 6 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/iio/potentiometer/mcp4018.c b/drivers/iio/potentiometer/mcp4018.c
> index 320a7c9..c051ee0 100644
> --- a/drivers/iio/potentiometer/mcp4018.c
> +++ b/drivers/iio/potentiometer/mcp4018.c
> @@ -147,7 +147,6 @@ static int mcp4018_probe(struct i2c_client *client)
>  	struct device *dev = &client->dev;
>  	struct mcp4018_data *data;
>  	struct iio_dev *indio_dev;
> -	const struct of_device_id *match;
>  
>  	if (!i2c_check_functionality(client->adapter,
>  				     I2C_FUNC_SMBUS_BYTE)) {
> @@ -162,10 +161,8 @@ static int mcp4018_probe(struct i2c_client *client)
>  	i2c_set_clientdata(client, indio_dev);
>  	data->client = client;
>  
> -	match = of_match_device(of_match_ptr(mcp4018_of_match), dev);
> -	if (match)
> -		data->cfg = of_device_get_match_data(dev);
> -	else
> +	data->cfg = of_device_get_match_data(dev);
> +	if (!data->cfg)
>  		data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data];
>  
>  	indio_dev->dev.parent = dev;
> diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
> index df894af..d87ca85 100644
> --- a/drivers/iio/potentiometer/mcp4531.c
> +++ b/drivers/iio/potentiometer/mcp4531.c
> @@ -360,7 +360,6 @@ static int mcp4531_probe(struct i2c_client *client)
>  	struct device *dev = &client->dev;
>  	struct mcp4531_data *data;
>  	struct iio_dev *indio_dev;
> -	const struct of_device_id *match;
>  
>  	if (!i2c_check_functionality(client->adapter,
>  				     I2C_FUNC_SMBUS_WORD_DATA)) {
> @@ -375,10 +374,8 @@ static int mcp4531_probe(struct i2c_client *client)
>  	i2c_set_clientdata(client, indio_dev);
>  	data->client = client;
>  
> -	match = of_match_device(of_match_ptr(mcp4531_of_match), dev);
> -	if (match)
> -		data->cfg = of_device_get_match_data(dev);
> -	else
> +	data->cfg = of_device_get_match_data(dev);
> +	if (!data->cfg)
>  		data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data];
>  
>  	indio_dev->dev.parent = dev;
> diff --git a/drivers/iio/potentiometer/max5481.c b/drivers/iio/potentiometer/max5481.c
> index ffe2761..6d2f13f 100644
> --- a/drivers/iio/potentiometer/max5481.c
> +++ b/drivers/iio/potentiometer/max5481.c
> @@ -137,7 +137,6 @@ static int max5481_probe(struct spi_device *spi)
>  	struct iio_dev *indio_dev;
>  	struct max5481_data *data;
>  	const struct spi_device_id *id = spi_get_device_id(spi);
> -	const struct of_device_id *match;
>  	int ret;
>  
>  	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
> @@ -149,10 +148,8 @@ static int max5481_probe(struct spi_device *spi)
>  
>  	data->spi = spi;
>  
> -	match = of_match_device(of_match_ptr(max5481_match), &spi->dev);
> -	if (match)
> -		data->cfg = of_device_get_match_data(&spi->dev);
> -	else
> +	data->cfg = of_device_get_match_data(&spi->dev);
> +	if (!data->cfg)
>  		data->cfg = &max5481_cfg[id->driver_data];
>  
>  	indio_dev->name = id->name;
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] iio: potentiometer: merge calls to of_match_device and of_device_get_match_data
  2018-08-19  7:02   ` Peter Rosin
@ 2018-08-19 19:17     ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2018-08-19 19:17 UTC (permalink / raw)
  To: Peter Rosin
  Cc: Julia Lawall, Peter Meerwald-Stadler, kernel-janitors,
	linux-kernel, linux-iio, Lars-Peter Clausen, Hartmut Knaack,
	Himanshu Jha

On Sun, 19 Aug 2018 09:02:42 +0200
Peter Rosin <peda@axentia.se> wrote:

> On 2018-05-21 11:49, Julia Lawall wrote:
> > Drop call to of_match_device, which is subsumed by the subsequent
> > call to of_device_get_match_data.  The code becomes simpler, and a
> > temporary variable can be dropped.
> > 
> > The semantic match that makes this change is as follows:
> > (http://coccinelle.lip6.fr/)
> > 
> > // <smpl>
> > @r@
> > local idexpression match;
> > identifier i;
> > expression x, dev, e, e1;
> > @@
> > -        match@i = of_match_device(x, dev);
> > -        if (match) e = of_device_get_match_data(dev);
> > -        else e = e1;
> > +        e = of_device_get_match_data(dev);
> > +        if (!e) e = e1;
> > 
> > @@
> > identifier r.i;
> > @@
> > - const struct of_device_id *i;
> > ... when != i
> > // </smpl>
> > 
> > Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>  
> 
> Reviewed-by: Peter Rosin <peda@axentia.se>

Applied to the togreg branch of iio.git.

Glad you replied to this one Peter, it had definitely dropped through the cracks.

Jonathan
> 
> Cheers,
> Peter
> 
> > 
> > ---
> >  drivers/iio/potentiometer/max5481.c |    7 ++-----
> >  drivers/iio/potentiometer/mcp4018.c |    7 ++-----
> >  drivers/iio/potentiometer/mcp4531.c |    7 ++-----
> >  3 files changed, 6 insertions(+), 15 deletions(-)
> > 
> > diff --git a/drivers/iio/potentiometer/mcp4018.c b/drivers/iio/potentiometer/mcp4018.c
> > index 320a7c9..c051ee0 100644
> > --- a/drivers/iio/potentiometer/mcp4018.c
> > +++ b/drivers/iio/potentiometer/mcp4018.c
> > @@ -147,7 +147,6 @@ static int mcp4018_probe(struct i2c_client *client)
> >  	struct device *dev = &client->dev;
> >  	struct mcp4018_data *data;
> >  	struct iio_dev *indio_dev;
> > -	const struct of_device_id *match;
> >  
> >  	if (!i2c_check_functionality(client->adapter,
> >  				     I2C_FUNC_SMBUS_BYTE)) {
> > @@ -162,10 +161,8 @@ static int mcp4018_probe(struct i2c_client *client)
> >  	i2c_set_clientdata(client, indio_dev);
> >  	data->client = client;
> >  
> > -	match = of_match_device(of_match_ptr(mcp4018_of_match), dev);
> > -	if (match)
> > -		data->cfg = of_device_get_match_data(dev);
> > -	else
> > +	data->cfg = of_device_get_match_data(dev);
> > +	if (!data->cfg)
> >  		data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data];
> >  
> >  	indio_dev->dev.parent = dev;
> > diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
> > index df894af..d87ca85 100644
> > --- a/drivers/iio/potentiometer/mcp4531.c
> > +++ b/drivers/iio/potentiometer/mcp4531.c
> > @@ -360,7 +360,6 @@ static int mcp4531_probe(struct i2c_client *client)
> >  	struct device *dev = &client->dev;
> >  	struct mcp4531_data *data;
> >  	struct iio_dev *indio_dev;
> > -	const struct of_device_id *match;
> >  
> >  	if (!i2c_check_functionality(client->adapter,
> >  				     I2C_FUNC_SMBUS_WORD_DATA)) {
> > @@ -375,10 +374,8 @@ static int mcp4531_probe(struct i2c_client *client)
> >  	i2c_set_clientdata(client, indio_dev);
> >  	data->client = client;
> >  
> > -	match = of_match_device(of_match_ptr(mcp4531_of_match), dev);
> > -	if (match)
> > -		data->cfg = of_device_get_match_data(dev);
> > -	else
> > +	data->cfg = of_device_get_match_data(dev);
> > +	if (!data->cfg)
> >  		data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data];
> >  
> >  	indio_dev->dev.parent = dev;
> > diff --git a/drivers/iio/potentiometer/max5481.c b/drivers/iio/potentiometer/max5481.c
> > index ffe2761..6d2f13f 100644
> > --- a/drivers/iio/potentiometer/max5481.c
> > +++ b/drivers/iio/potentiometer/max5481.c
> > @@ -137,7 +137,6 @@ static int max5481_probe(struct spi_device *spi)
> >  	struct iio_dev *indio_dev;
> >  	struct max5481_data *data;
> >  	const struct spi_device_id *id = spi_get_device_id(spi);
> > -	const struct of_device_id *match;
> >  	int ret;
> >  
> >  	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
> > @@ -149,10 +148,8 @@ static int max5481_probe(struct spi_device *spi)
> >  
> >  	data->spi = spi;
> >  
> > -	match = of_match_device(of_match_ptr(max5481_match), &spi->dev);
> > -	if (match)
> > -		data->cfg = of_device_get_match_data(&spi->dev);
> > -	else
> > +	data->cfg = of_device_get_match_data(&spi->dev);
> > +	if (!data->cfg)
> >  		data->cfg = &max5481_cfg[id->driver_data];
> >  
> >  	indio_dev->name = id->name;
> >   
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-08-19 19:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-21  9:49 [PATCH 0/3] merge calls to of_match_device and of_device_get_match_data Julia Lawall
2018-05-21  9:49 ` [PATCH 1/3] i2c: mux: pca954x: " Julia Lawall
2018-05-24 11:53   ` Peter Rosin
2018-05-21  9:49 ` [PATCH 3/3] iio: potentiometer: " Julia Lawall
2018-08-19  7:02   ` Peter Rosin
2018-08-19 19:17     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).