Skip to content

Commit aa512c1

Browse files
committed
Merge tag 'thermal-6.1-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull more thermal control updates from Rafael Wysocki: "These fix assorted issues in the thermal core and ARM thermal drivers. Specifics: - Use platform data to get the sensor ID instead of parsing the device in imx_sc thermal driver and remove the dedicated OF function from the core code (Daniel Lezcano). - Fix Kconfig dependency for the QCom tsens thermal driver (Jonathan Cameron). - Add missing const annotation to the RCar ops thermal driver (Lad Prabhakar). - Drop duplicate parameter check from thermal_zone_device_register_with_trips() (Lad Prabhakar). - Fix NULL pointer dereference in trip_point_temp_store() by making it check if the ->set_trip_temp() operation is present (Lad Prabhakar). - Fix the MSM8939 fourth sensor hardware ID in the QCom tsens thermal driver (Vincent Knecht)" * tag 'thermal-6.1-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: thermal/drivers/qcom/tsens-v0_1: Fix MSM8939 fourth sensor hw_id thermal/core: Add a check before calling set_trip_temp() thermal/core: Drop valid pointer check for type thermal/drivers/rcar_thermal: Constify static thermal_zone_device_ops thermal/drivers/qcom: Drop false build dependency of all QCOM drivers on QCOM_TSENS thermal/of: Remove the thermal_zone_of_get_sensor_id() function thermal/drivers/imx_sc: Rely on the platform data to get the resource id
2 parents f848b3c + e021563 commit aa512c1

File tree

8 files changed

+42
-96
lines changed

8 files changed

+42
-96
lines changed

drivers/thermal/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ obj-$(CONFIG_DA9062_THERMAL) += da9062-thermal.o
5252
obj-y += intel/
5353
obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
5454
obj-y += st/
55-
obj-$(CONFIG_QCOM_TSENS) += qcom/
55+
obj-y += qcom/
5656
obj-y += tegra/
5757
obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o
5858
obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o

drivers/thermal/imx_sc_thermal.c

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -76,68 +76,66 @@ static const struct thermal_zone_device_ops imx_sc_thermal_ops = {
7676

7777
static int imx_sc_thermal_probe(struct platform_device *pdev)
7878
{
79-
struct device_node *np, *child, *sensor_np;
8079
struct imx_sc_sensor *sensor;
81-
int ret;
80+
const int *resource_id;
81+
int i, ret;
8282

8383
ret = imx_scu_get_handle(&thermal_ipc_handle);
8484
if (ret)
8585
return ret;
8686

87-
np = of_find_node_by_name(NULL, "thermal-zones");
88-
if (!np)
89-
return -ENODEV;
87+
resource_id = of_device_get_match_data(&pdev->dev);
88+
if (!resource_id)
89+
return -EINVAL;
9090

91-
sensor_np = of_node_get(pdev->dev.of_node);
91+
for (i = 0; resource_id[i] > 0; i++) {
9292

93-
for_each_available_child_of_node(np, child) {
9493
sensor = devm_kzalloc(&pdev->dev, sizeof(*sensor), GFP_KERNEL);
95-
if (!sensor) {
96-
of_node_put(child);
97-
ret = -ENOMEM;
98-
goto put_node;
99-
}
94+
if (!sensor)
95+
return -ENOMEM;
10096

101-
ret = thermal_zone_of_get_sensor_id(child,
102-
sensor_np,
103-
&sensor->resource_id);
104-
if (ret < 0) {
105-
dev_err(&pdev->dev,
106-
"failed to get valid sensor resource id: %d\n",
107-
ret);
108-
of_node_put(child);
109-
break;
110-
}
97+
sensor->resource_id = resource_id[i];
11198

112-
sensor->tzd = devm_thermal_of_zone_register(&pdev->dev,
113-
sensor->resource_id,
114-
sensor,
115-
&imx_sc_thermal_ops);
99+
sensor->tzd = devm_thermal_of_zone_register(&pdev->dev, sensor->resource_id,
100+
sensor, &imx_sc_thermal_ops);
116101
if (IS_ERR(sensor->tzd)) {
117-
dev_err(&pdev->dev, "failed to register thermal zone\n");
102+
/*
103+
* Save the error value before freeing the
104+
* sensor pointer, otherwise we endup with a
105+
* use-after-free error
106+
*/
118107
ret = PTR_ERR(sensor->tzd);
119-
of_node_put(child);
120-
break;
108+
109+
devm_kfree(&pdev->dev, sensor);
110+
111+
/*
112+
* The thermal framework notifies us there is
113+
* no thermal zone description for such a
114+
* sensor id
115+
*/
116+
if (ret == -ENODEV)
117+
continue;
118+
119+
dev_err(&pdev->dev, "failed to register thermal zone\n");
120+
return ret;
121121
}
122122

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

127-
put_node:
128-
of_node_put(sensor_np);
129-
of_node_put(np);
130-
131-
return ret;
127+
return 0;
132128
}
133129

134130
static int imx_sc_thermal_remove(struct platform_device *pdev)
135131
{
136132
return 0;
137133
}
138134

135+
static int imx_sc_sensors[] = { IMX_SC_R_SYSTEM, IMX_SC_R_PMIC_0, -1 };
136+
139137
static const struct of_device_id imx_sc_thermal_table[] = {
140-
{ .compatible = "fsl,imx-sc-thermal", },
138+
{ .compatible = "fsl,imx-sc-thermal", .data = imx_sc_sensors },
141139
{}
142140
};
143141
MODULE_DEVICE_TABLE(of, imx_sc_thermal_table);

drivers/thermal/qcom/tsens-v0_1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ static const struct tsens_ops ops_8939 = {
604604
struct tsens_plat_data data_8939 = {
605605
.num_sensors = 10,
606606
.ops = &ops_8939,
607-
.hw_ids = (unsigned int []){ 0, 1, 2, 4, 5, 6, 7, 8, 9, 10 },
607+
.hw_ids = (unsigned int []){ 0, 1, 2, 3, 5, 6, 7, 8, 9, 10 },
608608

609609
.feat = &tsens_v0_1_feat,
610610
.fields = tsens_v0_1_regfields,

drivers/thermal/rcar_thermal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static int rcar_thermal_get_trip_temp(struct thermal_zone_device *zone,
316316
return 0;
317317
}
318318

319-
static struct thermal_zone_device_ops rcar_thermal_zone_of_ops = {
319+
static const struct thermal_zone_device_ops rcar_thermal_zone_of_ops = {
320320
.get_temp = rcar_thermal_get_temp,
321321
};
322322

drivers/thermal/thermal_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
11861186
return ERR_PTR(-EINVAL);
11871187
}
11881188

1189-
if (type && strlen(type) >= THERMAL_NAME_LENGTH) {
1189+
if (strlen(type) >= THERMAL_NAME_LENGTH) {
11901190
pr_err("Thermal zone name (%s) too long, should be under %d chars\n",
11911191
type, THERMAL_NAME_LENGTH);
11921192
return ERR_PTR(-EINVAL);

drivers/thermal/thermal_of.c

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -130,50 +130,6 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz,
130130
return -EINVAL;
131131
}
132132

133-
/**
134-
* thermal_zone_of_get_sensor_id - get sensor ID from a DT thermal zone
135-
* @tz_np: a valid thermal zone device node.
136-
* @sensor_np: a sensor node of a valid sensor device.
137-
* @id: the sensor ID returned if success.
138-
*
139-
* This function will get sensor ID from a given thermal zone node and
140-
* the sensor node must match the temperature provider @sensor_np.
141-
*
142-
* Return: 0 on success, proper error code otherwise.
143-
*/
144-
145-
int thermal_zone_of_get_sensor_id(struct device_node *tz_np,
146-
struct device_node *sensor_np,
147-
u32 *id)
148-
{
149-
struct of_phandle_args sensor_specs;
150-
int ret;
151-
152-
ret = of_parse_phandle_with_args(tz_np,
153-
"thermal-sensors",
154-
"#thermal-sensor-cells",
155-
0,
156-
&sensor_specs);
157-
if (ret)
158-
return ret;
159-
160-
if (sensor_specs.np != sensor_np) {
161-
of_node_put(sensor_specs.np);
162-
return -ENODEV;
163-
}
164-
165-
if (sensor_specs.args_count > 1)
166-
pr_warn("%pOFn: too many cells in sensor specifier %d\n",
167-
sensor_specs.np, sensor_specs.args_count);
168-
169-
*id = sensor_specs.args_count ? sensor_specs.args[0] : 0;
170-
171-
of_node_put(sensor_specs.np);
172-
173-
return 0;
174-
}
175-
EXPORT_SYMBOL_GPL(thermal_zone_of_get_sensor_id);
176-
177133
/*** functions parsing device tree nodes ***/
178134

179135
static int of_find_trip_id(struct device_node *np, struct device_node *trip)

drivers/thermal/thermal_sysfs.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,11 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
128128
if (kstrtoint(buf, 10, &temperature))
129129
return -EINVAL;
130130

131-
ret = tz->ops->set_trip_temp(tz, trip, temperature);
132-
if (ret)
133-
return ret;
131+
if (tz->ops->set_trip_temp) {
132+
ret = tz->ops->set_trip_temp(tz, trip, temperature);
133+
if (ret)
134+
return ret;
135+
}
134136

135137
if (tz->trips)
136138
tz->trips[trip].temperature = temperature;

include/linux/thermal.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,6 @@ void devm_thermal_of_zone_unregister(struct device *dev, struct thermal_zone_dev
308308

309309
void thermal_of_zone_unregister(struct thermal_zone_device *tz);
310310

311-
int thermal_zone_of_get_sensor_id(struct device_node *tz_np,
312-
struct device_node *sensor_np,
313-
u32 *id);
314311
#else
315312
static inline
316313
struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, int id, void *data,
@@ -334,13 +331,6 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev,
334331
struct thermal_zone_device *tz)
335332
{
336333
}
337-
338-
static inline int thermal_zone_of_get_sensor_id(struct device_node *tz_np,
339-
struct device_node *sensor_np,
340-
u32 *id)
341-
{
342-
return -ENOENT;
343-
}
344334
#endif
345335

346336
#ifdef CONFIG_THERMAL

0 commit comments

Comments
 (0)