Skip to content

Commit e90c369

Browse files
krzkdlezcano
authored andcommitted
thermal/drivers/broadcom: Fix race between removal and clock disable
During the probe, driver enables clocks necessary to access registers (in get_temp()) and then registers thermal zone with managed-resources (devm) interface. Removal of device is not done in reversed order, because: 1. Clock will be disabled in driver remove() callback - thermal zone is still registered and accessible to users, 2. devm interface will unregister thermal zone. This leaves short window between (1) and (2) for accessing the get_temp() callback with disabled clock. Fix this by enabling clock also via devm-interface, so entire cleanup path will be in proper, reversed order. Fixes: 8454c8c ("thermal/drivers/bcm2835: Remove buggy call to thermal_of_zone_unregister") Cc: [email protected] Signed-off-by: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Lezcano <[email protected]>
1 parent 6f48290 commit e90c369

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

drivers/thermal/broadcom/bcm2835_thermal.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,14 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
185185
return err;
186186
}
187187

188-
data->clk = devm_clk_get(&pdev->dev, NULL);
188+
data->clk = devm_clk_get_enabled(&pdev->dev, NULL);
189189
if (IS_ERR(data->clk)) {
190190
err = PTR_ERR(data->clk);
191191
if (err != -EPROBE_DEFER)
192192
dev_err(&pdev->dev, "Could not get clk: %d\n", err);
193193
return err;
194194
}
195195

196-
err = clk_prepare_enable(data->clk);
197-
if (err)
198-
return err;
199-
200196
rate = clk_get_rate(data->clk);
201197
if ((rate < 1920000) || (rate > 5000000))
202198
dev_warn(&pdev->dev,
@@ -211,7 +207,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
211207
dev_err(&pdev->dev,
212208
"Failed to register the thermal device: %d\n",
213209
err);
214-
goto err_clk;
210+
return err;
215211
}
216212

217213
/*
@@ -236,7 +232,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
236232
dev_err(&pdev->dev,
237233
"Not able to read trip_temp: %d\n",
238234
err);
239-
goto err_tz;
235+
return err;
240236
}
241237

242238
/* set bandgap reference voltage and enable voltage regulator */
@@ -269,25 +265,18 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
269265
*/
270266
err = thermal_add_hwmon_sysfs(tz);
271267
if (err)
272-
goto err_tz;
268+
return err;
273269

274270
bcm2835_thermal_debugfs(pdev);
275271

276272
return 0;
277-
err_tz:
278-
devm_thermal_of_zone_unregister(&pdev->dev, tz);
279-
err_clk:
280-
clk_disable_unprepare(data->clk);
281-
282-
return err;
283273
}
284274

285275
static void bcm2835_thermal_remove(struct platform_device *pdev)
286276
{
287277
struct bcm2835_thermal_data *data = platform_get_drvdata(pdev);
288278

289279
debugfs_remove_recursive(data->debugfsdir);
290-
clk_disable_unprepare(data->clk);
291280
}
292281

293282
static struct platform_driver bcm2835_thermal_driver = {

0 commit comments

Comments
 (0)