mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH -next] iio: potentiometer: mcp4531: merge calls to of_match_device and of_device_get_match_data
@ 2018-09-15 10:54 YueHaibing
  2018-09-15 11:35 ` Peter Rosin
  2018-09-15 17:46 ` Himanshu Jha
  0 siblings, 2 replies; 3+ messages in thread
From: YueHaibing @ 2018-09-15 10:54 UTC (permalink / raw)
  To: peda, jic23, knaack.h, lars, pmeerw; +Cc: linux-kernel, linux-iio, YueHaibing

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.

Found by coccinelle.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/iio/potentiometer/mcp4531.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

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;
-- 
1.8.3.1



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

* Re: [PATCH -next] iio: potentiometer: mcp4531: merge calls to of_match_device and of_device_get_match_data
  2018-09-15 10:54 [PATCH -next] iio: potentiometer: mcp4531: merge calls to of_match_device and of_device_get_match_data YueHaibing
@ 2018-09-15 11:35 ` Peter Rosin
  2018-09-15 17:46 ` Himanshu Jha
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Rosin @ 2018-09-15 11:35 UTC (permalink / raw)
  To: YueHaibing, jic23, knaack.h, lars, pmeerw; +Cc: linux-kernel, linux-iio

On 2018-09-15 12:54, YueHaibing 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.
> 
> Found by coccinelle.
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

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

Cheers,
Peter

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

* Re: [PATCH -next] iio: potentiometer: mcp4531: merge calls to of_match_device and of_device_get_match_data
  2018-09-15 10:54 [PATCH -next] iio: potentiometer: mcp4531: merge calls to of_match_device and of_device_get_match_data YueHaibing
  2018-09-15 11:35 ` Peter Rosin
@ 2018-09-15 17:46 ` Himanshu Jha
  1 sibling, 0 replies; 3+ messages in thread
From: Himanshu Jha @ 2018-09-15 17:46 UTC (permalink / raw)
  To: YueHaibing
  Cc: peda, jic23, knaack.h, lars, pmeerw, linux-kernel, linux-iio,
	Julia.Lawall

On Sat, Sep 15, 2018 at 06:54:30PM +0800, YueHaibing 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.
> 
> Found by coccinelle.
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

Already applied!
https://lore.kernel.org/lkml/20180819201752.2280be76@archlinux/

Anyway, if you want to work on making similar changes, you may
refer the following cocci script:

I tested[1] the changes through 0-day and had few false positives
and regressions. Therefore, check the results and compile test
the changes before sending patches.


Julia, and I had tried to make the confidence "High" but few 
cases were difficult to resolve, and later neither of us had 
time to look back at it again.

Not all maintainers will acknowledge such a change, but IIRC
Rob Herring gave a thumbs up on few cases on the dt-mailing list.


[1] https://github.com/himanshujha199640/linux-next/commit/efb7ed923bd00c86fe0a4e67e2ddb636ff0e0ff4

---------------------------------------------------------------------

/// Use of_device_get_match_data() to get matched data in an OF driver
//# of_device_get_match_data() returns const * and therefore the left
//# argument of assignment should also be a const * for compatible
//# types.
///
// Confidence: Moderate
// Copyright: (C) 2018 Himanshu Jha, GPLv2.
// Copyright: (C) 2018 Julia Lawall, INRIA/LIP6.  GPLv2.
// Keywords: of_match_device, of_device_get_match_data

virtual patch
virtual context
virtual org
virtual report


@r1 depends on patch && !context && !org && !report@
expression x,y,z;
identifier match;
type T;
statement S;
@@

- match = of_match_device(x, y);
(
- if(match==NULL) S
- z = match->data;
+ z = of_device_get_match_data(y);
|
- if(match==NULL) S
- z = (T *)match->data;
+ z = of_device_get_match_data(y);
|
- if(match==NULL) S
- z = (T)match->data;
+ z = (T)of_device_get_match_data(y);
|
- if(match!= NULL)
- z = match->data;
+ z = of_device_get_match_data(y);
|
- if(match!= NULL)
- z = (T *)match->data;
+ z = of_device_get_match_data(y);
|
- if(match!= NULL)
- z = (T)match->data;
+ z = (T)of_device_get_match_data(y);
)
... when != match

@r2 depends on r1 && patch && !context && !org && !report@
type T1;
expression e;
identifier r1.match;
@@

(
- T1 match = e;
|
- T1 match;
)

// ----------------------------------------------------------------------------

@r1_context depends on !patch && (context || org || report)@
type T;
identifier match;
statement S;
expression x, y, z;
position j0, j1;
@@

*  match@j0 = of_match_device(x, y);
(
*  if(match==NULL) S
*  z = match@j1->data;
|
*  if(match==NULL) S
*  z = (T *)match@j1->data;
|
*  if(match==NULL) S
*  z = (T)match@j1->data;
|
*  if(match!= NULL)
*  z = match@j1->data;
|
*  if(match!= NULL)
*  z = (T *)match@j1->data;
|
*  if(match!= NULL)
*  z = (T)match@j1->data;
)
... when != match

@r2_context depends on r1 && !patch && (context || org || report)@
type T1;
identifier r1_context.match;
expression e;
position j0;
@@

(
*  T1 match@j0 = e;
|
*  T1 match@j0;
)

// ----------------------------------------------------------------------------

@script:python r1_org depends on org@
j0 << r1_context.j0;
j1 << r1_context.j1;
@@

msg = "WARNING: opportunity for of_device_get_match_data."
coccilib.org.print_todo(j0[0], msg)
coccilib.org.print_link(j1[0], "")

// ----------------------------------------------------------------------------

@script:python r1_report depends on report@
j0 << r1_context.j0;
j1 << r1_context.j1;
@@

msg = "WARNING: opportunity for of_device_get_match_data around line %s." % (j1[0].line)
coccilib.report.print_report(j0[0], msg)

---------------------------------------------------------------------


Thanks
-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology

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

end of thread, other threads:[~2018-09-15 17:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-15 10:54 [PATCH -next] iio: potentiometer: mcp4531: merge calls to of_match_device and of_device_get_match_data YueHaibing
2018-09-15 11:35 ` Peter Rosin
2018-09-15 17:46 ` Himanshu Jha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®