2021-09-20 10:03:26

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 0/9] treewide: 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 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


2021-09-20 10:03:48

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 7/9] net: mdio: mdio-bcm-iproc: simplify getting .driver_data

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 <[email protected]>
---

Build tested only. buildbot is happy.

drivers/net/mdio/mdio-bcm-iproc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/mdio/mdio-bcm-iproc.c b/drivers/net/mdio/mdio-bcm-iproc.c
index 77fc970cdfde..5666cfab15b9 100644
--- a/drivers/net/mdio/mdio-bcm-iproc.c
+++ b/drivers/net/mdio/mdio-bcm-iproc.c
@@ -181,8 +181,7 @@ static int iproc_mdio_remove(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP
static int iproc_mdio_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct iproc_mdio_priv *priv = platform_get_drvdata(pdev);
+ struct iproc_mdio_priv *priv = dev_get_drvdata(dev);

/* restore the mii clock configuration */
iproc_mdio_config_clk(priv->base);
--
2.30.2

2021-09-20 10:06:22

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 9/9] remoteproc: omap_remoteproc: simplify getting .driver_data

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 <[email protected]>
---

Build tested only. buildbot is happy.

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

diff --git a/drivers/remoteproc/omap_remoteproc.c b/drivers/remoteproc/omap_remoteproc.c
index 43531caa1959..32a588fefbdc 100644
--- a/drivers/remoteproc/omap_remoteproc.c
+++ b/drivers/remoteproc/omap_remoteproc.c
@@ -901,8 +901,7 @@ static int _omap_rproc_resume(struct rproc *rproc, bool auto_suspend)

static int __maybe_unused omap_rproc_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct rproc *rproc = platform_get_drvdata(pdev);
+ struct rproc *rproc = dev_get_drvdata(dev);
struct omap_rproc *oproc = rproc->priv;
int ret = 0;

@@ -938,8 +937,7 @@ static int __maybe_unused omap_rproc_suspend(struct device *dev)

static int __maybe_unused omap_rproc_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct rproc *rproc = platform_get_drvdata(pdev);
+ struct rproc *rproc = dev_get_drvdata(dev);
struct omap_rproc *oproc = rproc->priv;
int ret = 0;

--
2.30.2

2021-09-20 12:53:55

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 5/9] drm/panfrost: simplify getting .driver_data

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 <[email protected]>
---

Build tested only. buildbot is happy.

drivers/gpu/drm/panfrost/panfrost_device.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/panfrost/panfrost_device.c b/drivers/gpu/drm/panfrost/panfrost_device.c
index bd9b7be63b0f..fd4309209088 100644
--- a/drivers/gpu/drm/panfrost/panfrost_device.c
+++ b/drivers/gpu/drm/panfrost/panfrost_device.c
@@ -400,8 +400,7 @@ void panfrost_device_reset(struct panfrost_device *pfdev)
#ifdef CONFIG_PM
int panfrost_device_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct panfrost_device *pfdev = platform_get_drvdata(pdev);
+ struct panfrost_device *pfdev = dev_get_drvdata(dev);

panfrost_device_reset(pfdev);
panfrost_devfreq_resume(pfdev);
@@ -411,8 +410,7 @@ int panfrost_device_resume(struct device *dev)

int panfrost_device_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct panfrost_device *pfdev = platform_get_drvdata(pdev);
+ struct panfrost_device *pfdev = dev_get_drvdata(dev);

if (!panfrost_job_is_idle(pfdev))
return -EBUSY;
--
2.30.2

2021-09-20 12:53:55

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 8/9] platform: chrome: cros_ec_sensorhub: simplify getting .driver_data

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 <[email protected]>
---

Build tested only. buildbot is happy.

drivers/platform/chrome/cros_ec_sensorhub.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_sensorhub.c b/drivers/platform/chrome/cros_ec_sensorhub.c
index 9c4af76a9956..31fb8bdaad5a 100644
--- a/drivers/platform/chrome/cros_ec_sensorhub.c
+++ b/drivers/platform/chrome/cros_ec_sensorhub.c
@@ -224,8 +224,7 @@ static int cros_ec_sensorhub_probe(struct platform_device *pdev)
*/
static int cros_ec_sensorhub_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct cros_ec_sensorhub *sensorhub = platform_get_drvdata(pdev);
+ struct cros_ec_sensorhub *sensorhub = dev_get_drvdata(dev);
struct cros_ec_dev *ec = sensorhub->ec;

if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO))
@@ -235,8 +234,7 @@ static int cros_ec_sensorhub_suspend(struct device *dev)

static int cros_ec_sensorhub_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct cros_ec_sensorhub *sensorhub = platform_get_drvdata(pdev);
+ struct cros_ec_sensorhub *sensorhub = dev_get_drvdata(dev);
struct cros_ec_dev *ec = sensorhub->ec;

if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO))
--
2.30.2

2021-09-20 12:53:55

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 4/9] drm/msm: simplify getting .driver_data

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 <[email protected]>
---

Build tested only. buildbot is happy.

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 +--
5 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
index ae48f41821cf..32410bd299e7 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
@@ -1185,16 +1185,15 @@ static int dpu_bind(struct device *dev, struct device *master, void *data)

static void dpu_unbind(struct device *dev, struct device *master, void *data)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct dpu_kms *dpu_kms = platform_get_drvdata(pdev);
+ struct dpu_kms *dpu_kms = dev_get_drvdata(dev);
struct dss_module_power *mp = &dpu_kms->mp;

msm_dss_put_clk(mp->clk_config, mp->num_clk);
- devm_kfree(&pdev->dev, mp->clk_config);
+ devm_kfree(dev, mp->clk_config);
mp->num_clk = 0;

if (dpu_kms->rpm_enabled)
- pm_runtime_disable(&pdev->dev);
+ pm_runtime_disable(dev);
}

static const struct component_ops dpu_ops = {
@@ -1216,8 +1215,7 @@ static int dpu_dev_remove(struct platform_device *pdev)
static int __maybe_unused dpu_runtime_suspend(struct device *dev)
{
int i, rc = -1;
- struct platform_device *pdev = to_platform_device(dev);
- struct dpu_kms *dpu_kms = platform_get_drvdata(pdev);
+ struct dpu_kms *dpu_kms = dev_get_drvdata(dev);
struct dss_module_power *mp = &dpu_kms->mp;

/* Drop the performance state vote */
@@ -1235,8 +1233,7 @@ static int __maybe_unused dpu_runtime_suspend(struct device *dev)
static int __maybe_unused dpu_runtime_resume(struct device *dev)
{
int rc = -1;
- struct platform_device *pdev = to_platform_device(dev);
- struct dpu_kms *dpu_kms = platform_get_drvdata(pdev);
+ struct dpu_kms *dpu_kms = dev_get_drvdata(dev);
struct drm_encoder *encoder;
struct drm_device *ddev;
struct dss_module_power *mp = &dpu_kms->mp;
diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
index b3b42672b2d4..3db9d1603dfe 100644
--- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
+++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
@@ -1015,8 +1015,7 @@ static int mdp5_dev_remove(struct platform_device *pdev)

static __maybe_unused int mdp5_runtime_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct mdp5_kms *mdp5_kms = platform_get_drvdata(pdev);
+ struct mdp5_kms *mdp5_kms = dev_get_drvdata(dev);

DBG("");

@@ -1025,8 +1024,7 @@ static __maybe_unused int mdp5_runtime_suspend(struct device *dev)

static __maybe_unused int mdp5_runtime_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct mdp5_kms *mdp5_kms = platform_get_drvdata(pdev);
+ struct mdp5_kms *mdp5_kms = dev_get_drvdata(dev);

DBG("");

diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index fbe4c2cd52a3..a58fccacc874 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -1272,8 +1272,7 @@ static int dp_display_remove(struct platform_device *pdev)

static int dp_pm_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct msm_dp *dp_display = platform_get_drvdata(pdev);
+ struct msm_dp *dp_display = dev_get_drvdata(dev);
struct dp_display_private *dp;
int sink_count = 0;

@@ -1329,8 +1328,7 @@ static int dp_pm_resume(struct device *dev)

static int dp_pm_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct msm_dp *dp_display = platform_get_drvdata(pdev);
+ struct msm_dp *dp_display = dev_get_drvdata(dev);
struct dp_display_private *dp;

dp = container_of(dp_display, struct dp_display_private, dp_display);
diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c
index e269df285136..d27db5777f2c 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -470,8 +470,7 @@ static void dsi_bus_clk_disable(struct msm_dsi_host *msm_host)

int msm_dsi_runtime_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct msm_dsi *msm_dsi = platform_get_drvdata(pdev);
+ struct msm_dsi *msm_dsi = dev_get_drvdata(dev);
struct mipi_dsi_host *host = msm_dsi->host;
struct msm_dsi_host *msm_host = to_msm_dsi_host(host);

@@ -485,8 +484,7 @@ int msm_dsi_runtime_suspend(struct device *dev)

int msm_dsi_runtime_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct msm_dsi *msm_dsi = platform_get_drvdata(pdev);
+ struct msm_dsi *msm_dsi = dev_get_drvdata(dev);
struct mipi_dsi_host *host = msm_dsi->host;
struct msm_dsi_host *msm_host = to_msm_dsi_host(host);

diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index 2e6fc185e54d..ede3d8b43761 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -309,8 +309,7 @@ static int vblank_ctrl_queue_work(struct msm_drm_private *priv,

static int msm_drm_uninit(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct drm_device *ddev = platform_get_drvdata(pdev);
+ struct drm_device *ddev = dev_get_drvdata(dev);
struct msm_drm_private *priv = ddev->dev_private;
struct msm_kms *kms = priv->kms;
struct msm_mdss *mdss = priv->mdss;
--
2.30.2

2021-09-20 13:19:32

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 1/9] dmaengine: stm32-dmamux: simplify getting .driver_data

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 <[email protected]>
---

Build tested only. buildbot is happy.

drivers/dma/stm32-dmamux.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/dma/stm32-dmamux.c b/drivers/dma/stm32-dmamux.c
index a42164389ebc..175f06749df6 100644
--- a/drivers/dma/stm32-dmamux.c
+++ b/drivers/dma/stm32-dmamux.c
@@ -305,8 +305,7 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
#ifdef CONFIG_PM
static int stm32_dmamux_runtime_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct stm32_dmamux_data *stm32_dmamux = platform_get_drvdata(pdev);
+ struct stm32_dmamux_data *stm32_dmamux = dev_get_drvdata(dev);

clk_disable_unprepare(stm32_dmamux->clk);

@@ -315,13 +314,12 @@ static int stm32_dmamux_runtime_suspend(struct device *dev)

static int stm32_dmamux_runtime_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct stm32_dmamux_data *stm32_dmamux = platform_get_drvdata(pdev);
+ struct stm32_dmamux_data *stm32_dmamux = dev_get_drvdata(dev);
int ret;

ret = clk_prepare_enable(stm32_dmamux->clk);
if (ret) {
- dev_err(&pdev->dev, "failed to prepare_enable clock\n");
+ dev_err(dev, "failed to prepare_enable clock\n");
return ret;
}

@@ -332,8 +330,7 @@ static int stm32_dmamux_runtime_resume(struct device *dev)
#ifdef CONFIG_PM_SLEEP
static int stm32_dmamux_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct stm32_dmamux_data *stm32_dmamux = platform_get_drvdata(pdev);
+ struct stm32_dmamux_data *stm32_dmamux = dev_get_drvdata(dev);
int i, ret;

ret = pm_runtime_resume_and_get(dev);
@@ -353,8 +350,7 @@ static int stm32_dmamux_suspend(struct device *dev)

static int stm32_dmamux_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct stm32_dmamux_data *stm32_dmamux = platform_get_drvdata(pdev);
+ struct stm32_dmamux_data *stm32_dmamux = dev_get_drvdata(dev);
int i, ret;

ret = pm_runtime_force_resume(dev);
--
2.30.2

2021-09-20 13:25:45

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 3/9] gpio: xilinx: simplify getting .driver_data

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 <[email protected]>
---

Build tested only. buildbot is happy.

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

diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index a1b66338d077..b6d3a57e27ed 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -371,8 +371,7 @@ static int __maybe_unused xgpio_resume(struct device *dev)

static int __maybe_unused xgpio_runtime_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct xgpio_instance *gpio = platform_get_drvdata(pdev);
+ struct xgpio_instance *gpio = dev_get_drvdata(dev);

clk_disable(gpio->clk);

@@ -381,8 +380,7 @@ static int __maybe_unused xgpio_runtime_suspend(struct device *dev)

static int __maybe_unused xgpio_runtime_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct xgpio_instance *gpio = platform_get_drvdata(pdev);
+ struct xgpio_instance *gpio = dev_get_drvdata(dev);

return clk_enable(gpio->clk);
}
--
2.30.2

2021-09-20 13:26:01

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 6/9] iio: common: cros_ec_sensors: simplify getting .driver_data

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 <[email protected]>
---

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

2021-09-20 13:42:40

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 2/9] firmware: meson: simplify getting .driver_data

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 <[email protected]>
---

Build tested only. buildbot is happy.

drivers/firmware/meson/meson_sm.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c
index 77aa5c6398aa..714016e3aab3 100644
--- a/drivers/firmware/meson/meson_sm.c
+++ b/drivers/firmware/meson/meson_sm.c
@@ -240,12 +240,11 @@ EXPORT_SYMBOL_GPL(meson_sm_get);
static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
- struct platform_device *pdev = to_platform_device(dev);
struct meson_sm_firmware *fw;
uint8_t *id_buf;
int ret;

- fw = platform_get_drvdata(pdev);
+ fw = dev_get_drvdata(dev);

id_buf = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL);
if (!id_buf)
--
2.30.2

2021-09-20 19:21:04

by Alyssa Rosenzweig

[permalink] [raw]
Subject: Re: [PATCH 5/9] drm/panfrost: simplify getting .driver_data

Reviewed-by: Alyssa Rosenzweig <[email protected]>

> index bd9b7be63b0f..fd4309209088 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_device.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_device.c
> @@ -400,8 +400,7 @@ void panfrost_device_reset(struct panfrost_device *pfdev)
> #ifdef CONFIG_PM
> int panfrost_device_resume(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct panfrost_device *pfdev = platform_get_drvdata(pdev);
> + struct panfrost_device *pfdev = dev_get_drvdata(dev);
>
> panfrost_device_reset(pfdev);
> panfrost_devfreq_resume(pfdev);
> @@ -411,8 +410,7 @@ int panfrost_device_resume(struct device *dev)
>
> int panfrost_device_suspend(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct panfrost_device *pfdev = platform_get_drvdata(pdev);
> + struct panfrost_device *pfdev = dev_get_drvdata(dev);
>
> if (!panfrost_job_is_idle(pfdev))
> return -EBUSY;
> --
> 2.30.2
>

2021-09-20 20:58:53

by Neil Armstrong

[permalink] [raw]
Subject: Re: [PATCH 2/9] firmware: meson: simplify getting .driver_data

On 20/09/2021 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 <[email protected]>
> ---
>
> Build tested only. buildbot is happy.
>
> drivers/firmware/meson/meson_sm.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c
> index 77aa5c6398aa..714016e3aab3 100644
> --- a/drivers/firmware/meson/meson_sm.c
> +++ b/drivers/firmware/meson/meson_sm.c
> @@ -240,12 +240,11 @@ EXPORT_SYMBOL_GPL(meson_sm_get);
> static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
> char *buf)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> struct meson_sm_firmware *fw;
> uint8_t *id_buf;
> int ret;
>
> - fw = platform_get_drvdata(pdev);
> + fw = dev_get_drvdata(dev);
>
> id_buf = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL);
> if (!id_buf)
>

Reviewed-by: Neil Armstrong <[email protected]>

2021-09-21 00:23:57

by Steven Price

[permalink] [raw]
Subject: Re: [PATCH 5/9] drm/panfrost: simplify getting .driver_data

On 20/09/2021 10: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 <[email protected]>
> ---

Reviewed-by: Steven Price <[email protected]>

I'll push this to drm-misc-next.

Thanks,

Steve

>
> Build tested only. buildbot is happy.
>
> drivers/gpu/drm/panfrost/panfrost_device.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/panfrost/panfrost_device.c b/drivers/gpu/drm/panfrost/panfrost_device.c
> index bd9b7be63b0f..fd4309209088 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_device.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_device.c
> @@ -400,8 +400,7 @@ void panfrost_device_reset(struct panfrost_device *pfdev)
> #ifdef CONFIG_PM
> int panfrost_device_resume(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct panfrost_device *pfdev = platform_get_drvdata(pdev);
> + struct panfrost_device *pfdev = dev_get_drvdata(dev);
>
> panfrost_device_reset(pfdev);
> panfrost_devfreq_resume(pfdev);
> @@ -411,8 +410,7 @@ int panfrost_device_resume(struct device *dev)
>
> int panfrost_device_suspend(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct panfrost_device *pfdev = platform_get_drvdata(pdev);
> + struct panfrost_device *pfdev = dev_get_drvdata(dev);
>
> if (!panfrost_job_is_idle(pfdev))
> return -EBUSY;
>

2021-09-21 03:59:09

by Florian Fainelli

[permalink] [raw]
Subject: Re: [PATCH 7/9] net: mdio: mdio-bcm-iproc: simplify getting .driver_data

On 9/20/21 2:05 AM, 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 <[email protected]>
> ---
>
> Build tested only. buildbot is happy.
>
> drivers/net/mdio/mdio-bcm-iproc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/mdio/mdio-bcm-iproc.c b/drivers/net/mdio/mdio-bcm-iproc.c
> index 77fc970cdfde..5666cfab15b9 100644
> --- a/drivers/net/mdio/mdio-bcm-iproc.c
> +++ b/drivers/net/mdio/mdio-bcm-iproc.c
> @@ -181,8 +181,7 @@ static int iproc_mdio_remove(struct platform_device *pdev)
> #ifdef CONFIG_PM_SLEEP
> static int iproc_mdio_resume(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct iproc_mdio_priv *priv = platform_get_drvdata(pdev);
> + struct iproc_mdio_priv *priv = dev_get_drvdata(dev);

The change looks good to me, however if you change from
platform_get_drvdata() to dev_get_drvdata(), you might also want to
change from using platform_set_drvdata() to dev_set_drvdata() for
symmetry no? If not, then maybe this patch should be dropped?
--
Florian

2021-09-21 05:56:25

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 7/9] net: mdio: mdio-bcm-iproc: simplify getting .driver_data


> The change looks good to me, however if you change from
> platform_get_drvdata() to dev_get_drvdata(), you might also want to
> change from using platform_set_drvdata() to dev_set_drvdata() for
> symmetry no? If not, then maybe this patch should be dropped?

In theory, yes. However, I haven't finished the coccinelle script yet
because there are a lot more usage patterns. I can do this individually
for this driver first if you want.


Attachments:
(No filename) (450.00 B)
signature.asc (849.00 B)
Download all attachments

2021-09-22 09:51:04

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH 3/9] gpio: xilinx: simplify getting .driver_data

On Mon, Sep 20, 2021 at 11:05 AM Wolfram Sang
<[email protected]> 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 <[email protected]>
> ---
>
> Build tested only. buildbot is happy.
>
> drivers/gpio/gpio-xilinx.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
> index a1b66338d077..b6d3a57e27ed 100644
> --- a/drivers/gpio/gpio-xilinx.c
> +++ b/drivers/gpio/gpio-xilinx.c
> @@ -371,8 +371,7 @@ static int __maybe_unused xgpio_resume(struct device *dev)
>
> static int __maybe_unused xgpio_runtime_suspend(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct xgpio_instance *gpio = platform_get_drvdata(pdev);
> + struct xgpio_instance *gpio = dev_get_drvdata(dev);
>
> clk_disable(gpio->clk);
>
> @@ -381,8 +380,7 @@ static int __maybe_unused xgpio_runtime_suspend(struct device *dev)
>
> static int __maybe_unused xgpio_runtime_resume(struct device *dev)
> {
> - struct platform_device *pdev = to_platform_device(dev);
> - struct xgpio_instance *gpio = platform_get_drvdata(pdev);
> + struct xgpio_instance *gpio = dev_get_drvdata(dev);
>
> return clk_enable(gpio->clk);
> }
> --
> 2.30.2
>

Applied, thanks!

Bart

2021-09-23 09:18:59

by Enric Balletbo i Serra

[permalink] [raw]
Subject: Re: [PATCH 6/9] iio: common: cros_ec_sensors: simplify getting .driver_data

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 <[email protected]>

Acked-by: Enric Balletbo i Serra <[email protected]>

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

2021-09-25 14:54:44

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 6/9] iio: common: cros_ec_sensors: simplify getting .driver_data

On Thu, 23 Sep 2021 11:16:47 +0200
Enric Balletbo i Serra <[email protected]> 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 <[email protected]>
>
> Acked-by: Enric Balletbo i Serra <[email protected]>
>
> 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 <[email protected]>

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

2021-10-12 07:34:17

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 6/9] iio: common: cros_ec_sensors: simplify getting .driver_data

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


Attachments:
(No filename) (0.99 kB)
signature.asc (849.00 B)
Download all attachments

2021-10-12 08:33:38

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 6/9] iio: common: cros_ec_sensors: simplify getting .driver_data

On Tue, 12 Oct 2021 09:31:11 +0200
Wolfram Sang <[email protected]> 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
>
>

2021-10-17 14:29:18

by Bjorn Andersson

[permalink] [raw]
Subject: Re: [PATCH 0/9] treewide: simplify getting .driver_data

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 <[email protected]>