Skip to content

Commit 8938202

Browse files
tititiou36dlezcano
authored andcommitted
thermal/drivers/sun8i: Fix some error handling paths in sun8i_ths_probe()
Should an error occur after calling sun8i_ths_resource_init() in the probe function, some resources need to be released, as already done in the .remove() function. Switch to the devm_clk_get_enabled() helper and add a new devm_action to turn sun8i_ths_resource_init() into a fully managed function. Move the place where reset_control_deassert() is called so that the recommended order of reset release/clock enable steps is kept. A64 manual states that: 3.3.6.4. Gating and reset Make sure that the reset signal has been released before the release of module clock gating; This fixes the issue and removes some LoC at the same time. Fixes: dccc5c3 ("thermal/drivers/sun8i: Add thermal driver for H6/H5/H3/A64/A83T/R40") Signed-off-by: Christophe JAILLET <[email protected]> Acked-by: Maxime Ripard <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/a8ae84bd2dc4b55fe428f8e20f31438bf8bb6762.1684089931.git.christophe.jaillet@wanadoo.fr
1 parent 86edac7 commit 8938202

File tree

1 file changed

+18
-37
lines changed

1 file changed

+18
-37
lines changed

drivers/thermal/sun8i_thermal.c

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ static int sun8i_ths_calibrate(struct ths_device *tmdev)
319319
return ret;
320320
}
321321

322+
static void sun8i_ths_reset_control_assert(void *data)
323+
{
324+
reset_control_assert(data);
325+
}
326+
322327
static int sun8i_ths_resource_init(struct ths_device *tmdev)
323328
{
324329
struct device *dev = tmdev->dev;
@@ -339,47 +344,35 @@ static int sun8i_ths_resource_init(struct ths_device *tmdev)
339344
if (IS_ERR(tmdev->reset))
340345
return PTR_ERR(tmdev->reset);
341346

342-
tmdev->bus_clk = devm_clk_get(&pdev->dev, "bus");
347+
ret = reset_control_deassert(tmdev->reset);
348+
if (ret)
349+
return ret;
350+
351+
ret = devm_add_action_or_reset(dev, sun8i_ths_reset_control_assert,
352+
tmdev->reset);
353+
if (ret)
354+
return ret;
355+
356+
tmdev->bus_clk = devm_clk_get_enabled(&pdev->dev, "bus");
343357
if (IS_ERR(tmdev->bus_clk))
344358
return PTR_ERR(tmdev->bus_clk);
345359
}
346360

347361
if (tmdev->chip->has_mod_clk) {
348-
tmdev->mod_clk = devm_clk_get(&pdev->dev, "mod");
362+
tmdev->mod_clk = devm_clk_get_enabled(&pdev->dev, "mod");
349363
if (IS_ERR(tmdev->mod_clk))
350364
return PTR_ERR(tmdev->mod_clk);
351365
}
352366

353-
ret = reset_control_deassert(tmdev->reset);
354-
if (ret)
355-
return ret;
356-
357-
ret = clk_prepare_enable(tmdev->bus_clk);
358-
if (ret)
359-
goto assert_reset;
360-
361367
ret = clk_set_rate(tmdev->mod_clk, 24000000);
362368
if (ret)
363-
goto bus_disable;
364-
365-
ret = clk_prepare_enable(tmdev->mod_clk);
366-
if (ret)
367-
goto bus_disable;
369+
return ret;
368370

369371
ret = sun8i_ths_calibrate(tmdev);
370372
if (ret)
371-
goto mod_disable;
373+
return ret;
372374

373375
return 0;
374-
375-
mod_disable:
376-
clk_disable_unprepare(tmdev->mod_clk);
377-
bus_disable:
378-
clk_disable_unprepare(tmdev->bus_clk);
379-
assert_reset:
380-
reset_control_assert(tmdev->reset);
381-
382-
return ret;
383376
}
384377

385378
static int sun8i_h3_thermal_init(struct ths_device *tmdev)
@@ -530,17 +523,6 @@ static int sun8i_ths_probe(struct platform_device *pdev)
530523
return 0;
531524
}
532525

533-
static int sun8i_ths_remove(struct platform_device *pdev)
534-
{
535-
struct ths_device *tmdev = platform_get_drvdata(pdev);
536-
537-
clk_disable_unprepare(tmdev->mod_clk);
538-
clk_disable_unprepare(tmdev->bus_clk);
539-
reset_control_assert(tmdev->reset);
540-
541-
return 0;
542-
}
543-
544526
static const struct ths_thermal_chip sun8i_a83t_ths = {
545527
.sensor_num = 3,
546528
.scale = 705,
@@ -642,7 +624,6 @@ MODULE_DEVICE_TABLE(of, of_ths_match);
642624

643625
static struct platform_driver ths_driver = {
644626
.probe = sun8i_ths_probe,
645-
.remove = sun8i_ths_remove,
646627
.driver = {
647628
.name = "sun8i-thermal",
648629
.of_match_table = of_ths_match,

0 commit comments

Comments
 (0)