linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] treewide: simplify getting .driver_data
@ 2021-09-20  9:05 Wolfram Sang
  2021-09-20  9:05 ` [PATCH 6/9] iio: common: cros_ec_sensors: " Wolfram Sang
  2021-10-15 17:22 ` [PATCH 0/9] treewide: " Bjorn Andersson
  0 siblings, 2 replies; 7+ messages in thread
From: Wolfram Sang @ 2021-09-20  9:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-renesas-soc, Wolfram Sang, dmaengine, dri-devel, freedreno,
	linux-amlogic, linux-arm-kernel, linux-arm-msm, linux-gpio,
	linux-iio, linux-remoteproc, linux-stm32, netdev

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 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):
  dmaengine: stm32-dmamux: simplify getting .driver_data
  firmware: meson: simplify getting .driver_data
  gpio: xilinx: simplify getting .driver_data
  drm/msm: simplify getting .driver_data
  drm/panfrost: simplify getting .driver_data
  iio: common: cros_ec_sensors: simplify getting .driver_data
  net: mdio: mdio-bcm-iproc: simplify getting .driver_data
  platform: chrome: cros_ec_sensorhub: simplify getting .driver_data
  remoteproc: omap_remoteproc: simplify getting .driver_data

 drivers/dma/stm32-dmamux.c                         | 14 +++++---------
 drivers/firmware/meson/meson_sm.c                  |  3 +--
 drivers/gpio/gpio-xilinx.c                         |  6 ++----
 drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c            | 13 +++++--------
 drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c           |  6 ++----
 drivers/gpu/drm/msm/dp/dp_display.c                |  6 ++----
 drivers/gpu/drm/msm/dsi/dsi_host.c                 |  6 ++----
 drivers/gpu/drm/msm/msm_drv.c                      |  3 +--
 drivers/gpu/drm/panfrost/panfrost_device.c         |  6 ++----
 .../common/cros_ec_sensors/cros_ec_sensors_core.c  |  3 +--
 drivers/net/mdio/mdio-bcm-iproc.c                  |  3 +--
 drivers/platform/chrome/cros_ec_sensorhub.c        |  6 ++----
 drivers/remoteproc/omap_remoteproc.c               |  6 ++----
 13 files changed, 28 insertions(+), 53 deletions(-)

-- 
2.30.2


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

* [PATCH 6/9] iio: common: cros_ec_sensors: simplify getting .driver_data
  2021-09-20  9:05 [PATCH 0/9] treewide: simplify getting .driver_data Wolfram Sang
@ 2021-09-20  9:05 ` Wolfram Sang
  2021-09-23  9:16   ` Enric Balletbo i Serra
  2021-10-15 17:22 ` [PATCH 0/9] treewide: " Bjorn Andersson
  1 sibling, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2021-09-20  9:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-renesas-soc, Wolfram Sang, Jonathan Cameron,
	Lars-Peter Clausen, Benson Leung, Enric Balletbo i Serra,
	Guenter Roeck, linux-iio

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/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 28bde13003b7..b2725c6adc7f 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -831,8 +831,7 @@ EXPORT_SYMBOL_GPL(cros_ec_sensors_core_write);
 
 static int __maybe_unused cros_ec_sensors_resume(struct device *dev)
 {
-	struct platform_device *pdev = to_platform_device(dev);
-	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
 	int ret = 0;
 
-- 
2.30.2


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

* Re: [PATCH 6/9] iio: common: cros_ec_sensors: simplify getting .driver_data
  2021-09-20  9:05 ` [PATCH 6/9] iio: common: cros_ec_sensors: " Wolfram Sang
@ 2021-09-23  9:16   ` Enric Balletbo i Serra
  2021-09-25 14:54     ` Jonathan Cameron
  0 siblings, 1 reply; 7+ messages in thread
From: Enric Balletbo i Serra @ 2021-09-23  9:16 UTC (permalink / raw)
  To: Wolfram Sang, linux-kernel
  Cc: linux-renesas-soc, Jonathan Cameron, Lars-Peter Clausen,
	Benson Leung, Guenter Roeck, linux-iio

Hi Wolfram,

On 20/9/21 11:05, 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>

Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

I'm fine to pick this patch through chrome-platform tree if Jonathan is fine, or
can go through his tree.

I plan also to pick patch  "[PATCH 8/9] platform: chrome: cros_ec_sensorhub:
simplify getting .driver_data"

Thanks,
  Enric

> ---
> 
> Build tested only. buildbot is happy.
> 
>  drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> index 28bde13003b7..b2725c6adc7f 100644
> --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> @@ -831,8 +831,7 @@ EXPORT_SYMBOL_GPL(cros_ec_sensors_core_write);
>  
>  static int __maybe_unused cros_ec_sensors_resume(struct device *dev)
>  {
> -	struct platform_device *pdev = to_platform_device(dev);
> -	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>  	struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
>  	int ret = 0;
>  
> 

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

* Re: [PATCH 6/9] iio: common: cros_ec_sensors: simplify getting .driver_data
  2021-09-23  9:16   ` Enric Balletbo i Serra
@ 2021-09-25 14:54     ` Jonathan Cameron
  2021-10-12  7:31       ` Wolfram Sang
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2021-09-25 14:54 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Wolfram Sang, linux-kernel, linux-renesas-soc,
	Lars-Peter Clausen, Benson Leung, Guenter Roeck, linux-iio

On Thu, 23 Sep 2021 11:16:47 +0200
Enric Balletbo i Serra <enric.balletbo@collabora.com> wrote:

> Hi Wolfram,
> 
> On 20/9/21 11:05, 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>  
> 
> Acked-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> 
> I'm fine to pick this patch through chrome-platform tree if Jonathan is fine, or
> can go through his tree.

Fine by me, though a suggestion follows to take this a little further than done here.

Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

It's not something that ever bothered me that much, but we have had debates in
the past about whether there are semantic issues around this sort of cleanup
as it mixes

platform_set_drvdata() with device_get_drvdata()

Whilst they access the same pointer today, in theory that isn't necessarily
always going to be the case in future and it isn't necessarily apparent
to the casual reader of the code.

In this particular case you could tidy that up by using device_set_drvdata() in
the first place, but then to keep things consistent there is one other place
where platform_get_drvdata is used in a devm_add_action_or_reset() callback.
That one is also easily fixed though if we want to be consistent throughout.

Jonathan

> 
> I plan also to pick patch  "[PATCH 8/9] platform: chrome: cros_ec_sensorhub:
> simplify getting .driver_data"
> 
> Thanks,
>   Enric
> 
> > ---
> > 
> > Build tested only. buildbot is happy.
> > 
> >  drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > index 28bde13003b7..b2725c6adc7f 100644
> > --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > @@ -831,8 +831,7 @@ EXPORT_SYMBOL_GPL(cros_ec_sensors_core_write);
> >  
> >  static int __maybe_unused cros_ec_sensors_resume(struct device *dev)
> >  {
> > -	struct platform_device *pdev = to_platform_device(dev);
> > -	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> > +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> >  	struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
> >  	int ret = 0;
> >  
> >   


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

* Re: [PATCH 6/9] iio: common: cros_ec_sensors: simplify getting .driver_data
  2021-09-25 14:54     ` Jonathan Cameron
@ 2021-10-12  7:31       ` Wolfram Sang
  2021-10-12  8:31         ` Jonathan Cameron
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2021-10-12  7:31 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Enric Balletbo i Serra, linux-kernel, linux-renesas-soc,
	Lars-Peter Clausen, Benson Leung, Guenter Roeck, linux-iio

[-- Attachment #1: Type: text/plain, Size: 1014 bytes --]

Hi Jonathan,

> It's not something that ever bothered me that much, but we have had debates in
> the past about whether there are semantic issues around this sort of cleanup
> as it mixes
> 
> platform_set_drvdata() with device_get_drvdata()

Yeah, I see this concern. Mixing the two makes reading the code a bit
more difficult. As I said, it wasn't so easy to convert set_drvdata, but
I will have another go at this.

> Whilst they access the same pointer today, in theory that isn't necessarily
> always going to be the case in future and it isn't necessarily apparent
> to the casual reader of the code.

That one I don't really see. *_get_drvdata() should always get
'dev->driver_data' and the prefix just tells from what namespace we
come. If you want to change that, a lot of things will break loose, I'd
think. Even in the unlikely case of platform_device gaining a seperate
driver_data(?), it probably should be named *_get_pdrvdata(), or?

Thanks and happy hacking,

   Wolfram


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH 6/9] iio: common: cros_ec_sensors: simplify getting .driver_data
  2021-10-12  7:31       ` Wolfram Sang
@ 2021-10-12  8:31         ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2021-10-12  8:31 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Jonathan Cameron, Enric Balletbo i Serra, linux-kernel,
	linux-renesas-soc, Lars-Peter Clausen, Benson Leung,
	Guenter Roeck, linux-iio

On Tue, 12 Oct 2021 09:31:11 +0200
Wolfram Sang <wsa+renesas@sang-engineering.com> wrote:

> Hi Jonathan,
> 
> > It's not something that ever bothered me that much, but we have had debates in
> > the past about whether there are semantic issues around this sort of cleanup
> > as it mixes
> > 
> > platform_set_drvdata() with device_get_drvdata()  
> 
> Yeah, I see this concern. Mixing the two makes reading the code a bit
> more difficult. As I said, it wasn't so easy to convert set_drvdata, but
> I will have another go at this.
> 
> > Whilst they access the same pointer today, in theory that isn't necessarily
> > always going to be the case in future and it isn't necessarily apparent
> > to the casual reader of the code.  
> 
> That one I don't really see. *_get_drvdata() should always get
> 'dev->driver_data' and the prefix just tells from what namespace we
> come. If you want to change that, a lot of things will break loose, I'd
> think. Even in the unlikely case of platform_device gaining a seperate
> driver_data(?), it probably should be named *_get_pdrvdata(), or?

Agreed. Does indeed seem like any change to this would be a mess so would
require different naming etc.

Thanks,

Jonathan

> 
> Thanks and happy hacking,
> 
>    Wolfram
> 
> 


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

* Re: [PATCH 0/9] treewide: simplify getting .driver_data
  2021-09-20  9:05 [PATCH 0/9] treewide: simplify getting .driver_data Wolfram Sang
  2021-09-20  9:05 ` [PATCH 6/9] iio: common: cros_ec_sensors: " Wolfram Sang
@ 2021-10-15 17:22 ` Bjorn Andersson
  1 sibling, 0 replies; 7+ messages in thread
From: Bjorn Andersson @ 2021-10-15 17:22 UTC (permalink / raw)
  To: Wolfram Sang, linux-kernel
  Cc: dmaengine, dri-devel, linux-stm32, linux-gpio, freedreno,
	linux-renesas-soc, linux-amlogic, linux-remoteproc,
	linux-arm-kernel, netdev, linux-iio, linux-arm-msm

On Mon, 20 Sep 2021 11:05:12 +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);
> 
> [...]

Applied, thanks!

[1/9] dmaengine: stm32-dmamux: simplify getting .driver_data
      (no commit info)
[2/9] firmware: meson: simplify getting .driver_data
      (no commit info)
[3/9] gpio: xilinx: simplify getting .driver_data
      (no commit info)
[4/9] drm/msm: simplify getting .driver_data
      (no commit info)
[5/9] drm/panfrost: simplify getting .driver_data
      (no commit info)
[6/9] iio: common: cros_ec_sensors: simplify getting .driver_data
      (no commit info)
[7/9] net: mdio: mdio-bcm-iproc: simplify getting .driver_data
      (no commit info)
[8/9] platform: chrome: cros_ec_sensorhub: simplify getting .driver_data
      (no commit info)
[9/9] remoteproc: omap_remoteproc: simplify getting .driver_data
      commit: c34bfafd7c6ce8bdb5205aa990973b6ec7a6557c

Best regards,
-- 
Bjorn Andersson <bjorn.andersson@linaro.org>

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

end of thread, other threads:[~2021-10-15 17:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20  9:05 [PATCH 0/9] treewide: simplify getting .driver_data Wolfram Sang
2021-09-20  9:05 ` [PATCH 6/9] iio: common: cros_ec_sensors: " Wolfram Sang
2021-09-23  9:16   ` Enric Balletbo i Serra
2021-09-25 14:54     ` Jonathan Cameron
2021-10-12  7:31       ` Wolfram Sang
2021-10-12  8:31         ` Jonathan Cameron
2021-10-15 17:22 ` [PATCH 0/9] treewide: " Bjorn Andersson

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