From: Wolfram Sang <wsa+renesas@sang-engineering.com> Date: 2018-10-21 20:04:39
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 (9):
net: dsa: bcm_sf2: simplify getting .driver_data
net: dsa: qca8k: simplify getting .driver_data
net: ethernet: cadence: macb_main: simplify getting .driver_data
net: ethernet: davicom: dm9000: simplify getting .driver_data
net: ethernet: smsc: smc91x: simplify getting .driver_data
net: ethernet: ti: cpsw: simplify getting .driver_data
net: ethernet: ti: davinci_emac: simplify getting .driver_data
net: ethernet: wiznet: w5300: simplify getting .driver_data
net: phy: mdio-mux-bcm-iproc: simplify getting .driver_data
drivers/net/dsa/bcm_sf2.c | 6 ++----
drivers/net/dsa/qca8k.c | 6 ++----
drivers/net/ethernet/cadence/macb_main.c | 6 ++----
drivers/net/ethernet/davicom/dm9000.c | 6 ++----
drivers/net/ethernet/smsc/smc91x.c | 3 +--
drivers/net/ethernet/ti/cpsw.c | 6 ++----
drivers/net/ethernet/ti/davinci_emac.c | 6 ++----
drivers/net/ethernet/wiznet/w5300.c | 6 ++----
drivers/net/phy/mdio-mux-bcm-iproc.c | 6 ++----
9 files changed, 17 insertions(+), 34 deletions(-)
--
2.19.0
From: Wolfram Sang <wsa+renesas@sang-engineering.com> Date: 2018-10-21 20:00:28
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Build tested only. buildbot is happy.
drivers/net/dsa/bcm_sf2.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
From: Wolfram Sang <wsa+renesas@sang-engineering.com> Date: 2018-10-21 20:00:31
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Build tested only. buildbot is happy.
drivers/net/ethernet/cadence/macb_main.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
From: Wolfram Sang <wsa+renesas@sang-engineering.com> Date: 2018-10-21 20:00:32
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Build tested only. buildbot is happy.
drivers/net/ethernet/smsc/smc91x.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
From: Wolfram Sang <wsa+renesas@sang-engineering.com> Date: 2018-10-21 20:00:34
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Build tested only. buildbot is happy.
drivers/net/ethernet/ti/davinci_emac.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
From: Wolfram Sang <wsa+renesas@sang-engineering.com> Date: 2018-10-21 20:00:36
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Build tested only. buildbot is happy.
drivers/net/phy/mdio-mux-bcm-iproc.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
From: Wolfram Sang <wsa+renesas@sang-engineering.com> Date: 2018-10-21 20:03:31
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Build tested only. buildbot is happy.
drivers/net/ethernet/wiznet/w5300.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
From: Wolfram Sang <wsa+renesas@sang-engineering.com> Date: 2018-10-21 20:03:56
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Build tested only. buildbot is happy.
drivers/net/ethernet/davicom/dm9000.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
From: Wolfram Sang <wsa+renesas@sang-engineering.com> Date: 2018-10-21 20:04:06
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Build tested only. buildbot is happy.
drivers/net/ethernet/ti/cpsw.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
From: Wolfram Sang <wsa+renesas@sang-engineering.com> Date: 2018-10-21 20:04:29
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Build tested only. buildbot is happy.
drivers/net/dsa/qca8k.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
From: Andrew Lunn <andrew@lunn.ch> Date: 2018-10-21 23:14:58
On Sun, Oct 21, 2018 at 10:00:20PM +0200, Wolfram Sang wrote:
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
From: Andrew Lunn <andrew@lunn.ch> Date: 2018-10-21 23:15:53
On Sun, Oct 21, 2018 at 10:00:13PM +0200, Wolfram Sang wrote:
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
From: Andrew Lunn <andrew@lunn.ch> Date: 2018-10-21 23:16:41
On Sun, Oct 21, 2018 at 10:00:12PM +0200, Wolfram Sang wrote:
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
From: David Miller <davem@davemloft.net> Date: 2018-10-22 04:11:14
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
Date: Sun, 21 Oct 2018 22:00:11 +0200
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:
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
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.
Would it make sense to annotate platform_get_drvdata() with __deprecated
or something like that to prevent further uses by driver authors?
Do you mind submitting the cocci-script to the maintainers of the
coccinelle scripts that way it can be included and run by automated
tools? Thanks!