Skip to contentSkip to conversation

rtc: simplify getting .driver_data

PATCH Applied Wolfram Sang 3 participants 5 messages Oct 21, 2018 – Oct 22, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover rtc: simplify getting .driver_data

I got tired of fixing this in Renesas drivers manually, so I took the big hammer. Remove this cumbersome code pattern which got copy-pasted too much already:

- struct platform_device *pdev = to_platform_device(dev);
- struct ep93xx_keypad *keypad = platform_get_drvdata(pdev);
+ struct ep93xx_keypad *keypad = dev_get_drvdata(dev);

A branch, tested by buildbot, can be found here:

git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git coccinelle/get_drvdata

I have been asked if it couldn't be done for dev_set_drvdata as well. I checked it and did not find one occasion where it could be simplified like this. Not much of a surprise because driver_data is usually set in probe() functions which access struct platform_device in many other ways.

I am open for other comments, suggestions, too, of course.

Here is the cocci-script I created:

@@
struct device* d;
identifier pdev;
expression *ptr;
@@
(
- struct platform_device *pdev = to_platform_device(d);
|

-	struct platform_device *pdev;
	...
-	pdev = to_platform_device(d);
)
	<... when != pdev
-	&pdev->dev
+	d
	...>

	ptr =

- platform_get_drvdata(pdev)
+ dev_get_drvdata(d)

	<... when != pdev
-	&pdev->dev
+	d
	...>

Kind regards,

Wolfram

Wolfram Sang (1):
rtc: ds1685: simplify getting .driver_data

 drivers/rtc/rtc-ds1685.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Signature · 1 line
2.19.0
#1 lore raw

PATCH 1/1 rtc: ds1685: simplify getting .driver_data

We should get 'driver_data' from 'struct device' directly. Going via platform_device is an unneeded step back and forth.

---

Build tested only. buildbot is happy.

 drivers/rtc/rtc-ds1685.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/rtc/rtc-ds1685.c +1 -2
index b0723025ac31..2710f2594c42 100644
@@ -778,8 +778,7 @@ static const char *ds1685_rtc_sqw_freq[16] = {
 static int
 ds1685_rtc_proc(struct device *dev, struct seq_file *seq)
 {
-	struct platform_device *pdev = to_platform_device(dev);
-	struct ds1685_priv *rtc = platform_get_drvdata(pdev);
+	struct ds1685_priv *rtc = dev_get_drvdata(dev);
 	u8 ctrla, ctrlb, ctrlc, ctrld, ctrl4a, ctrl4b, ssn[8];
 	char *model;
 
Signature · 1 line
2.19.0
maintainer Applied
#2 lore raw

Re: [PATCH 1/1] rtc: ds1685: simplify getting .driver_data

Quoted 11 lines · Wolfram Sang

We should get 'driver_data' from 'struct device' directly. Going via platform_device is an unneeded step back and forth.

---

Build tested only. buildbot is happy.

 drivers/rtc/rtc-ds1685.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Applied, thanks.

Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw

Re: [PATCH 1/1] rtc: ds1685: simplify getting .driver_data

Quoted 7 lines · Alexandre Belloni
Quoted 6 lines · Wolfram Sang

We should get 'driver_data' from 'struct device' directly. Going via platform_device is an unneeded step back and forth.

---

Quoted 7 lines
Quoted 5 lines

Build tested only. buildbot is happy.

 drivers/rtc/rtc-ds1685.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Applied, thanks.

By the way, is there any reason why this was not part of your patch back in April? I had a deja vu feeling ;)

Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#4 lore raw

Re: [PATCH 1/1] rtc: ds1685: simplify getting .driver_data

Quoted 3 lines

By the way, is there any reason why this was not part of your patch back in April? I had a deja vu feeling ;)

I haven't checked but I guess the driver looked different back then. I didn't update the rule, so it should have matched back then, too.