Re: [PATCH next 23/25] thermal: Use dev_get_drvdata()

From: Zhang Rui
Date: Sun Apr 28 2019 - 23:48:06 EST


On ä, 2019-04-23 at 15:50 +0800, Kefeng Wang wrote:
> Using dev_get_drvdata directly.
>
> Cc: Zhang Rui <rui.zhang@xxxxxxxxx>
> Cc: Eduardo Valentin <edubezval@xxxxxxxxx>
> Cc: Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>
> Cc: linux-pm@xxxxxxxxxxxxxxx
> Signed-off-by: Kefeng Wang <wangkefeng.wang@xxxxxxxxxx>
> ---
> Â.../intel/int340x_thermal/processor_thermal_device.cÂÂÂÂÂÂ| 8 +-----
> --
> Âdrivers/thermal/st/stm_thermal.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ| 6 ++----
> Â2 files changed, 3 insertions(+), 11 deletions(-)
>
> diff --git
> a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c
> b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c
> index 8e1cf4d789be..4ad54b8d4778 100644
> ---
> a/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c
> +++
> b/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c
> @@ -81,8 +81,6 @@ static ssize_t
> power_limit_##index##_##suffix##_show(struct device *dev, \
> Â struct device_attribute
> *attr, \
> Â char *buf) \
> Â{ \
> - struct pci_dev *pci_dev; \
> - struct platform_device *pdev; \
> Â struct proc_thermal_device *proc_dev; \
> Â \
> Â if (proc_thermal_emum_mode == PROC_THERMAL_NONE) { \
> @@ -91,11 +89,7 @@ static ssize_t
> power_limit_##index##_##suffix##_show(struct device *dev, \
> Â } \
> Â \
> Â if (proc_thermal_emum_mode == PROC_THERMAL_PLATFORM_DEV) { \
> - pdev = to_platform_device(dev); \
> - proc_dev = platform_get_drvdata(pdev); \
> - } else { \
> - pci_dev = to_pci_dev(dev); \
> - proc_dev = pci_get_drvdata(pci_dev); \
> + proc_dev = dev_get_drvdata(dev); \
> Â } \
> Â return sprintf(buf, "%lu\n",\
> Â (unsigned long)proc_dev->power_limits[index].suffix * 1000);
> \

Sumeet has a patch to fix the same issue, which has been in my tree
https://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git/commit
/?h=next&id=1948d498dcf680bc650391f23da2f97e59f9126d

Plus, the previous fix is wrong because proc_dev will be left
uninitialized ifÂproc_thermal_emum_mode equalsÂPROC_THERMAL_PCI.

thanks,
rui

> diff --git a/drivers/thermal/st/stm_thermal.c
> b/drivers/thermal/st/stm_thermal.c
> index bbd73c5a4a4e..cf9ddc52f30e 100644
> --- a/drivers/thermal/st/stm_thermal.c
> +++ b/drivers/thermal/st/stm_thermal.c
> @@ -570,8 +570,7 @@ static int stm_thermal_prepare(struct
> stm_thermal_sensor *sensor)
> Âstatic int stm_thermal_suspend(struct device *dev)
> Â{
> Â int ret;
> - struct platform_device *pdev = to_platform_device(dev);
> - struct stm_thermal_sensor *sensor =
> platform_get_drvdata(pdev);
> + struct stm_thermal_sensor *sensor = dev_get_drvdata(dev);
> Â
> Â ret = stm_thermal_sensor_off(sensor);
> Â if (ret)
> @@ -585,8 +584,7 @@ static int stm_thermal_suspend(struct device
> *dev)
> Âstatic int stm_thermal_resume(struct device *dev)
> Â{
> Â int ret;
> - struct platform_device *pdev = to_platform_device(dev);
> - struct stm_thermal_sensor *sensor =
> platform_get_drvdata(pdev);
> + struct stm_thermal_sensor *sensor = dev_get_drvdata(dev);
> Â
> Â ret = stm_thermal_prepare(sensor);
> Â if (ret)