Skip to content

Commit

Permalink
thermal/hwmon: Use the right device for devm_thermal_add_hwmon_sysfs()
Browse files Browse the repository at this point in the history
The devres variant of thermal_add_hwmon_sysfs() only takes the thermal
zone structure pointer as parameter.

Actually, it uses the tz->device to add it in the devres list.

It is preferable to use the device registering the thermal zone
instead of the thermal zone device itself. That prevents the driver
accessing the thermal zone structure internals and it is from my POV
more correct regarding how devm_ is used.

Signed-off-by: Daniel Lezcano <[email protected]>
Acked-by: Martin Blumenstingl <[email protected]> #amlogic_thermal
Acked-by: Jernej Skrabec <[email protected]> #sun8i_thermal
Reviewed-by: AngeloGioacchino Del Regno <[email protected]> #MediaTek auxadc
Signed-off-by: Rafael J. Wysocki <[email protected]>
  • Loading branch information
dlezcano authored and rafaeljw committed Mar 3, 2023
1 parent 8f3f4ad commit 4a16c19
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion drivers/thermal/amlogic_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ static int amlogic_thermal_probe(struct platform_device *pdev)
return ret;
}

if (devm_thermal_add_hwmon_sysfs(pdata->tzd))
if (devm_thermal_add_hwmon_sysfs(&pdev->dev, pdata->tzd))
dev_warn(&pdev->dev, "Failed to add hwmon sysfs attributes\n");

ret = amlogic_thermal_initialize(pdata);
Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/imx8mm_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static int imx8mm_tmu_probe(struct platform_device *pdev)
}
tmu->sensors[i].hw_id = i;

if (devm_thermal_add_hwmon_sysfs(tmu->sensors[i].tzd))
if (devm_thermal_add_hwmon_sysfs(&pdev->dev, tmu->sensors[i].tzd))
dev_warn(&pdev->dev, "failed to add hwmon sysfs attributes\n");
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/imx_sc_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static int imx_sc_thermal_probe(struct platform_device *pdev)
return ret;
}

if (devm_thermal_add_hwmon_sysfs(sensor->tzd))
if (devm_thermal_add_hwmon_sysfs(&pdev->dev, sensor->tzd))
dev_warn(&pdev->dev, "failed to add hwmon sysfs attributes\n");
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/k3_bandgap.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static int k3_bandgap_probe(struct platform_device *pdev)
goto err_alloc;
}

if (devm_thermal_add_hwmon_sysfs(data[id].tzd))
if (devm_thermal_add_hwmon_sysfs(dev, data[id].tzd))
dev_warn(dev, "Failed to add hwmon sysfs attributes\n");
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/mediatek/auxadc_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ static int mtk_thermal_probe(struct platform_device *pdev)
goto err_disable_clk_peri_therm;
}

ret = devm_thermal_add_hwmon_sysfs(tzdev);
ret = devm_thermal_add_hwmon_sysfs(&pdev->dev, tzdev);
if (ret)
dev_warn(&pdev->dev, "error in thermal_add_hwmon_sysfs");

Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/qcom/qcom-spmi-adc-tm5.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ static int adc_tm5_register_tzd(struct adc_tm5_chip *adc_tm)
return PTR_ERR(tzd);
}
adc_tm->channels[i].tzd = tzd;
if (devm_thermal_add_hwmon_sysfs(tzd))
if (devm_thermal_add_hwmon_sysfs(adc_tm->dev, tzd))
dev_warn(adc_tm->dev,
"Failed to add hwmon sysfs attributes\n");
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/qcom/qcom-spmi-temp-alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ static int qpnp_tm_probe(struct platform_device *pdev)
return ret;
}

if (devm_thermal_add_hwmon_sysfs(chip->tz_dev))
if (devm_thermal_add_hwmon_sysfs(&pdev->dev, chip->tz_dev))
dev_warn(&pdev->dev,
"Failed to add hwmon sysfs attributes\n");

Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/qcom/tsens.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ static int tsens_register(struct tsens_priv *priv)
if (priv->ops->enable)
priv->ops->enable(priv, i);

if (devm_thermal_add_hwmon_sysfs(tzd))
if (devm_thermal_add_hwmon_sysfs(priv->dev, tzd))
dev_warn(priv->dev,
"Failed to add hwmon sysfs attributes\n");
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/qoriq_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev,
return ret;
}

if (devm_thermal_add_hwmon_sysfs(tzd))
if (devm_thermal_add_hwmon_sysfs(dev, tzd))
dev_warn(dev,
"Failed to add hwmon sysfs attributes\n");

Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/sun8i_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ static int sun8i_ths_register(struct ths_device *tmdev)
if (IS_ERR(tmdev->sensor[i].tzd))
return PTR_ERR(tmdev->sensor[i].tzd);

if (devm_thermal_add_hwmon_sysfs(tmdev->sensor[i].tzd))
if (devm_thermal_add_hwmon_sysfs(tmdev->dev, tmdev->sensor[i].tzd))
dev_warn(tmdev->dev,
"Failed to add hwmon sysfs attributes\n");
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/tegra/tegra30-tsensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ static int tegra_tsensor_register_channel(struct tegra_tsensor *ts,
return 0;
}

if (devm_thermal_add_hwmon_sysfs(tsc->tzd))
if (devm_thermal_add_hwmon_sysfs(ts->dev, tsc->tzd))
dev_warn(ts->dev, "failed to add hwmon sysfs attributes\n");

return 0;
Expand Down
4 changes: 2 additions & 2 deletions drivers/thermal/thermal_hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ static void devm_thermal_hwmon_release(struct device *dev, void *res)
thermal_remove_hwmon_sysfs(*(struct thermal_zone_device **)res);
}

int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
int devm_thermal_add_hwmon_sysfs(struct device *dev, struct thermal_zone_device *tz)
{
struct thermal_zone_device **ptr;
int ret;
Expand All @@ -280,7 +280,7 @@ int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
}

*ptr = tz;
devres_add(&tz->device, ptr);
devres_add(dev, ptr);

return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/thermal/thermal_hwmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#ifdef CONFIG_THERMAL_HWMON
int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz);
int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz);
int devm_thermal_add_hwmon_sysfs(struct device *dev, struct thermal_zone_device *tz);
void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz);
#else
static inline int
Expand All @@ -27,7 +27,7 @@ thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
}

static inline int
devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
devm_thermal_add_hwmon_sysfs(struct device *dev, struct thermal_zone_device *tz)
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/thermal/ti-soc-thermal/ti-thermal-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id,
ti_bandgap_set_sensor_data(bgp, id, data);
ti_bandgap_write_update_interval(bgp, data->sensor_id, interval);

if (devm_thermal_add_hwmon_sysfs(data->ti_thermal))
if (devm_thermal_add_hwmon_sysfs(bgp->dev, data->ti_thermal))
dev_warn(bgp->dev, "failed to add hwmon sysfs attributes\n");

return 0;
Expand Down

0 comments on commit 4a16c19

Please sign in to comment.