2018-04-22 09:16:32

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 0/6] tree-wide: simplify getting .drvdata

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

I send this out as one patch per directory per subsystem. I think they should
be applied individually. If you prefer a broken out series per subsystem, I can
provide this as well. Just mail me.

A branch (tested by buildbot; only with all commits squashed into one commit
before) can be found here:

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

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 (6):
dmaengine: at_hdmac: simplify getting .drvdata
dmaengine: at_xdmac: simplify getting .drvdata
dmaengine: fsldma: simplify getting .drvdata
dmaengine: idma64: simplify getting .drvdata
dmaengine: ste_dma40: simplify getting .drvdata
dmaengine: txx9dmac: simplify getting .drvdata

drivers/dma/at_hdmac.c | 9 +++------
drivers/dma/at_xdmac.c | 9 +++------
drivers/dma/fsldma.c | 6 ++----
drivers/dma/idma64.c | 6 ++----
drivers/dma/ste_dma40.c | 12 ++++--------
drivers/dma/txx9dmac.c | 8 +++-----
6 files changed, 17 insertions(+), 33 deletions(-)

--
2.11.0



2018-04-22 09:16:22

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 6/6] dmaengine: txx9dmac: simplify getting .drvdata

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

Signed-off-by: Wolfram Sang <[email protected]>
---

Build tested only. buildbot is happy. Please apply to your tree directly.

drivers/dma/txx9dmac.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/txx9dmac.c b/drivers/dma/txx9dmac.c
index 4d8c7b9078fd..eb45af71d3a3 100644
--- a/drivers/dma/txx9dmac.c
+++ b/drivers/dma/txx9dmac.c
@@ -1244,8 +1244,7 @@ static void txx9dmac_shutdown(struct platform_device *pdev)

static int txx9dmac_suspend_noirq(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct txx9dmac_dev *ddev = platform_get_drvdata(pdev);
+ struct txx9dmac_dev *ddev = dev_get_drvdata(dev);

txx9dmac_off(ddev);
return 0;
@@ -1253,9 +1252,8 @@ static int txx9dmac_suspend_noirq(struct device *dev)

static int txx9dmac_resume_noirq(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct txx9dmac_dev *ddev = platform_get_drvdata(pdev);
- struct txx9dmac_platform_data *pdata = dev_get_platdata(&pdev->dev);
+ struct txx9dmac_dev *ddev = dev_get_drvdata(dev);
+ struct txx9dmac_platform_data *pdata = dev_get_platdata(dev);
u32 mcr;

mcr = TXX9_DMA_MCR_MSTEN | MCR_LE;
--
2.11.0


2018-04-22 09:16:55

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 5/6] dmaengine: ste_dma40: simplify getting .drvdata

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

Signed-off-by: Wolfram Sang <[email protected]>
---

Build tested only. buildbot is happy. Please apply to your tree directly.

drivers/dma/ste_dma40.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index c2b089af0420..1bc149af990e 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -2889,8 +2889,7 @@ static int __init d40_dmaengine_init(struct d40_base *base,
#ifdef CONFIG_PM_SLEEP
static int dma40_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct d40_base *base = platform_get_drvdata(pdev);
+ struct d40_base *base = dev_get_drvdata(dev);
int ret;

ret = pm_runtime_force_suspend(dev);
@@ -2904,8 +2903,7 @@ static int dma40_suspend(struct device *dev)

static int dma40_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct d40_base *base = platform_get_drvdata(pdev);
+ struct d40_base *base = dev_get_drvdata(dev);
int ret = 0;

if (base->lcpa_regulator) {
@@ -2970,8 +2968,7 @@ static void d40_save_restore_registers(struct d40_base *base, bool save)

static int dma40_runtime_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct d40_base *base = platform_get_drvdata(pdev);
+ struct d40_base *base = dev_get_drvdata(dev);

d40_save_restore_registers(base, true);

@@ -2985,8 +2982,7 @@ static int dma40_runtime_suspend(struct device *dev)

static int dma40_runtime_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct d40_base *base = platform_get_drvdata(pdev);
+ struct d40_base *base = dev_get_drvdata(dev);

d40_save_restore_registers(base, false);

--
2.11.0


2018-04-22 09:17:15

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 1/6] dmaengine: at_hdmac: simplify getting .drvdata

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

Signed-off-by: Wolfram Sang <[email protected]>
---

Build tested only. buildbot is happy. Please apply to your tree directly.

drivers/dma/at_hdmac.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index a861b5b4d443..75f38d19fcbe 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -2041,8 +2041,7 @@ static void at_dma_shutdown(struct platform_device *pdev)

static int at_dma_prepare(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct at_dma *atdma = platform_get_drvdata(pdev);
+ struct at_dma *atdma = dev_get_drvdata(dev);
struct dma_chan *chan, *_chan;

list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels,
@@ -2076,8 +2075,7 @@ static void atc_suspend_cyclic(struct at_dma_chan *atchan)

static int at_dma_suspend_noirq(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct at_dma *atdma = platform_get_drvdata(pdev);
+ struct at_dma *atdma = dev_get_drvdata(dev);
struct dma_chan *chan, *_chan;

/* preserve data */
@@ -2118,8 +2116,7 @@ static void atc_resume_cyclic(struct at_dma_chan *atchan)

static int at_dma_resume_noirq(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct at_dma *atdma = platform_get_drvdata(pdev);
+ struct at_dma *atdma = dev_get_drvdata(dev);
struct dma_chan *chan, *_chan;

/* bring back DMA controller */
--
2.11.0


2018-04-22 09:17:21

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 4/6] dmaengine: idma64: simplify getting .drvdata

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

Signed-off-by: Wolfram Sang <[email protected]>
---

Build tested only. buildbot is happy. Please apply to your tree directly.

drivers/dma/idma64.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/idma64.c b/drivers/dma/idma64.c
index 1953e57505f4..e5c911200bdb 100644
--- a/drivers/dma/idma64.c
+++ b/drivers/dma/idma64.c
@@ -670,8 +670,7 @@ static int idma64_platform_remove(struct platform_device *pdev)

static int idma64_pm_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct idma64_chip *chip = platform_get_drvdata(pdev);
+ struct idma64_chip *chip = dev_get_drvdata(dev);

idma64_off(chip->idma64);
return 0;
@@ -679,8 +678,7 @@ static int idma64_pm_suspend(struct device *dev)

static int idma64_pm_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct idma64_chip *chip = platform_get_drvdata(pdev);
+ struct idma64_chip *chip = dev_get_drvdata(dev);

idma64_on(chip->idma64);
return 0;
--
2.11.0


2018-04-22 09:18:02

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 2/6] dmaengine: at_xdmac: simplify getting .drvdata

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

Signed-off-by: Wolfram Sang <[email protected]>
---

Build tested only. buildbot is happy. Please apply to your tree directly.

drivers/dma/at_xdmac.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c
index 94236ec9d410..4bf72561667c 100644
--- a/drivers/dma/at_xdmac.c
+++ b/drivers/dma/at_xdmac.c
@@ -1833,8 +1833,7 @@ static void at_xdmac_free_chan_resources(struct dma_chan *chan)
#ifdef CONFIG_PM
static int atmel_xdmac_prepare(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct at_xdmac *atxdmac = platform_get_drvdata(pdev);
+ struct at_xdmac *atxdmac = dev_get_drvdata(dev);
struct dma_chan *chan, *_chan;

list_for_each_entry_safe(chan, _chan, &atxdmac->dma.channels, device_node) {
@@ -1853,8 +1852,7 @@ static int atmel_xdmac_prepare(struct device *dev)
#ifdef CONFIG_PM_SLEEP
static int atmel_xdmac_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct at_xdmac *atxdmac = platform_get_drvdata(pdev);
+ struct at_xdmac *atxdmac = dev_get_drvdata(dev);
struct dma_chan *chan, *_chan;

list_for_each_entry_safe(chan, _chan, &atxdmac->dma.channels, device_node) {
@@ -1878,8 +1876,7 @@ static int atmel_xdmac_suspend(struct device *dev)

static int atmel_xdmac_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct at_xdmac *atxdmac = platform_get_drvdata(pdev);
+ struct at_xdmac *atxdmac = dev_get_drvdata(dev);
struct at_xdmac_chan *atchan;
struct dma_chan *chan, *_chan;
int i;
--
2.11.0


2018-04-22 09:18:07

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 3/6] dmaengine: fsldma: simplify getting .drvdata

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

Signed-off-by: Wolfram Sang <[email protected]>
---

Build tested only. buildbot is happy. Please apply to your tree directly.

drivers/dma/fsldma.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/fsldma.c b/drivers/dma/fsldma.c
index 3eaece888e75..1117b5123a6f 100644
--- a/drivers/dma/fsldma.c
+++ b/drivers/dma/fsldma.c
@@ -1328,8 +1328,7 @@ static int fsldma_of_remove(struct platform_device *op)
#ifdef CONFIG_PM
static int fsldma_suspend_late(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct fsldma_device *fdev = platform_get_drvdata(pdev);
+ struct fsldma_device *fdev = dev_get_drvdata(dev);
struct fsldma_chan *chan;
int i;

@@ -1360,8 +1359,7 @@ static int fsldma_suspend_late(struct device *dev)

static int fsldma_resume_early(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct fsldma_device *fdev = platform_get_drvdata(pdev);
+ struct fsldma_device *fdev = dev_get_drvdata(dev);
struct fsldma_chan *chan;
u32 mode;
int i;
--
2.11.0


2018-04-22 16:07:51

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 0/6] tree-wide: simplify getting .drvdata

On Sun, Apr 22, 2018 at 11:14:08AM +0200, Wolfram Sang wrote:
> 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);
>
> I send this out as one patch per directory per subsystem. I think they should
> be applied individually. If you prefer a broken out series per subsystem, I can
> provide this as well. Just mail me.

Applied all, thanks

--
~Vinod

2018-04-23 05:48:22

by Ludovic Desroches

[permalink] [raw]
Subject: Re: [PATCH 1/6] dmaengine: at_hdmac: simplify getting .drvdata

On Sun, Apr 22, 2018 at 11:14:09AM +0200, Wolfram Sang wrote:
> We should get drvdata from struct device directly. Going via
> platform_device is an unneeded step back and forth.
>
> Signed-off-by: Wolfram Sang <[email protected]>
Acked-by: Ludovic Desroches <[email protected]>

Thanks
> ---
>
> Build tested only. buildbot is happy. Please apply to your tree directly.
>
> drivers/dma/at_hdmac.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
> index a861b5b4d443..75f38d19fcbe 100644
> --- a/drivers/dma/at_hdmac.c
> +++ b/drivers/dma/at_hdmac.c
> @@ -2041,8 +2041,7 @@ static void at_dma_shutdown(struct platform_device *pdev)
>
> static int at_dma_prepare(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct at_dma *atdma = platform_get_drvdata(pdev);
> + struct at_dma *atdma = dev_get_drvdata(dev);
> struct dma_chan *chan, *_chan;
>
> list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels,
> @@ -2076,8 +2075,7 @@ static void atc_suspend_cyclic(struct at_dma_chan *atchan)
>
> static int at_dma_suspend_noirq(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct at_dma *atdma = platform_get_drvdata(pdev);
> + struct at_dma *atdma = dev_get_drvdata(dev);
> struct dma_chan *chan, *_chan;
>
> /* preserve data */
> @@ -2118,8 +2116,7 @@ static void atc_resume_cyclic(struct at_dma_chan *atchan)
>
> static int at_dma_resume_noirq(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct at_dma *atdma = platform_get_drvdata(pdev);
> + struct at_dma *atdma = dev_get_drvdata(dev);
> struct dma_chan *chan, *_chan;
>
> /* bring back DMA controller */
> --
> 2.11.0
>

2018-04-23 05:49:00

by Ludovic Desroches

[permalink] [raw]
Subject: Re: [PATCH 2/6] dmaengine: at_xdmac: simplify getting .drvdata

On Sun, Apr 22, 2018 at 11:14:10AM +0200, Wolfram Sang wrote:
> We should get drvdata from struct device directly. Going via
> platform_device is an unneeded step back and forth.
>
> Signed-off-by: Wolfram Sang <[email protected]>
Acked-by: Ludovic Desroches <[email protected]>

Thanks
> ---
>
> Build tested only. buildbot is happy. Please apply to your tree directly.
>
> drivers/dma/at_xdmac.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c
> index 94236ec9d410..4bf72561667c 100644
> --- a/drivers/dma/at_xdmac.c
> +++ b/drivers/dma/at_xdmac.c
> @@ -1833,8 +1833,7 @@ static void at_xdmac_free_chan_resources(struct dma_chan *chan)
> #ifdef CONFIG_PM
> static int atmel_xdmac_prepare(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct at_xdmac *atxdmac = platform_get_drvdata(pdev);
> + struct at_xdmac *atxdmac = dev_get_drvdata(dev);
> struct dma_chan *chan, *_chan;
>
> list_for_each_entry_safe(chan, _chan, &atxdmac->dma.channels, device_node) {
> @@ -1853,8 +1852,7 @@ static int atmel_xdmac_prepare(struct device *dev)
> #ifdef CONFIG_PM_SLEEP
> static int atmel_xdmac_suspend(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct at_xdmac *atxdmac = platform_get_drvdata(pdev);
> + struct at_xdmac *atxdmac = dev_get_drvdata(dev);
> struct dma_chan *chan, *_chan;
>
> list_for_each_entry_safe(chan, _chan, &atxdmac->dma.channels, device_node) {
> @@ -1878,8 +1876,7 @@ static int atmel_xdmac_suspend(struct device *dev)
>
> static int atmel_xdmac_resume(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct at_xdmac *atxdmac = platform_get_drvdata(pdev);
> + struct at_xdmac *atxdmac = dev_get_drvdata(dev);
> struct at_xdmac_chan *atchan;
> struct dma_chan *chan, *_chan;
> int i;
> --
> 2.11.0
>