Commit 123ee07b authored by XuDong Liu's avatar XuDong Liu Committed by Maxime Ripard

drm: sun4i_tcon: use devm_clk_get_enabled in `sun4i_tcon_init_clocks`

Smatch reports:
drivers/gpu/drm/sun4i/sun4i_tcon.c:805 sun4i_tcon_init_clocks() warn:
'tcon->clk' from clk_prepare_enable() not released on lines: 792,801.

In the function sun4i_tcon_init_clocks(), tcon->clk and tcon->sclk0 are
not disabled in the error handling, which affects the release of
these variable. Although sun4i_tcon_bind(), which calls
sun4i_tcon_init_clocks(), use sun4i_tcon_free_clocks to disable the
variables mentioned, but the error handling branch of
sun4i_tcon_init_clocks() ignores the required disable process.

To fix this issue, use the devm_clk_get_enabled to automatically
balance enable and disabled calls. As original implementation use
sun4i_tcon_free_clocks() to disable clk explicitly, we delete the
related calls and error handling that are no longer needed.

Fixes: 9026e0d1 ("drm: Add Allwinner A10 Display Engine support")
Fixes: b14e945b ("drm/sun4i: tcon: Prepare and enable TCON channel 0 clock at init")
Fixes: 8e924047 ("drm/sun4i: support TCONs without channel 1")
Fixes: 34d698f6 ("drm/sun4i: Add has_channel_0 TCON quirk")
Signed-off-by: default avatarXuDong Liu <m202071377@hust.edu.cn>
Reviewed-by: default avatarDongliang Mu <dzm91@hust.edu.cn>
Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
Link: https://patchwork.freedesktop.org/patch/msgid/20230430112347.4689-1-m202071377@hust.edu.cn
parent 4795c787
...@@ -784,21 +784,19 @@ static irqreturn_t sun4i_tcon_handler(int irq, void *private) ...@@ -784,21 +784,19 @@ static irqreturn_t sun4i_tcon_handler(int irq, void *private)
static int sun4i_tcon_init_clocks(struct device *dev, static int sun4i_tcon_init_clocks(struct device *dev,
struct sun4i_tcon *tcon) struct sun4i_tcon *tcon)
{ {
tcon->clk = devm_clk_get(dev, "ahb"); tcon->clk = devm_clk_get_enabled(dev, "ahb");
if (IS_ERR(tcon->clk)) { if (IS_ERR(tcon->clk)) {
dev_err(dev, "Couldn't get the TCON bus clock\n"); dev_err(dev, "Couldn't get the TCON bus clock\n");
return PTR_ERR(tcon->clk); return PTR_ERR(tcon->clk);
} }
clk_prepare_enable(tcon->clk);
if (tcon->quirks->has_channel_0) { if (tcon->quirks->has_channel_0) {
tcon->sclk0 = devm_clk_get(dev, "tcon-ch0"); tcon->sclk0 = devm_clk_get_enabled(dev, "tcon-ch0");
if (IS_ERR(tcon->sclk0)) { if (IS_ERR(tcon->sclk0)) {
dev_err(dev, "Couldn't get the TCON channel 0 clock\n"); dev_err(dev, "Couldn't get the TCON channel 0 clock\n");
return PTR_ERR(tcon->sclk0); return PTR_ERR(tcon->sclk0);
} }
} }
clk_prepare_enable(tcon->sclk0);
if (tcon->quirks->has_channel_1) { if (tcon->quirks->has_channel_1) {
tcon->sclk1 = devm_clk_get(dev, "tcon-ch1"); tcon->sclk1 = devm_clk_get(dev, "tcon-ch1");
...@@ -811,12 +809,6 @@ static int sun4i_tcon_init_clocks(struct device *dev, ...@@ -811,12 +809,6 @@ static int sun4i_tcon_init_clocks(struct device *dev,
return 0; return 0;
} }
static void sun4i_tcon_free_clocks(struct sun4i_tcon *tcon)
{
clk_disable_unprepare(tcon->sclk0);
clk_disable_unprepare(tcon->clk);
}
static int sun4i_tcon_init_irq(struct device *dev, static int sun4i_tcon_init_irq(struct device *dev,
struct sun4i_tcon *tcon) struct sun4i_tcon *tcon)
{ {
...@@ -1229,14 +1221,14 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, ...@@ -1229,14 +1221,14 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master,
ret = sun4i_tcon_init_regmap(dev, tcon); ret = sun4i_tcon_init_regmap(dev, tcon);
if (ret) { if (ret) {
dev_err(dev, "Couldn't init our TCON regmap\n"); dev_err(dev, "Couldn't init our TCON regmap\n");
goto err_free_clocks; goto err_assert_reset;
} }
if (tcon->quirks->has_channel_0) { if (tcon->quirks->has_channel_0) {
ret = sun4i_dclk_create(dev, tcon); ret = sun4i_dclk_create(dev, tcon);
if (ret) { if (ret) {
dev_err(dev, "Couldn't create our TCON dot clock\n"); dev_err(dev, "Couldn't create our TCON dot clock\n");
goto err_free_clocks; goto err_assert_reset;
} }
} }
...@@ -1299,8 +1291,6 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, ...@@ -1299,8 +1291,6 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master,
err_free_dclk: err_free_dclk:
if (tcon->quirks->has_channel_0) if (tcon->quirks->has_channel_0)
sun4i_dclk_free(tcon); sun4i_dclk_free(tcon);
err_free_clocks:
sun4i_tcon_free_clocks(tcon);
err_assert_reset: err_assert_reset:
reset_control_assert(tcon->lcd_rst); reset_control_assert(tcon->lcd_rst);
return ret; return ret;
...@@ -1314,7 +1304,6 @@ static void sun4i_tcon_unbind(struct device *dev, struct device *master, ...@@ -1314,7 +1304,6 @@ static void sun4i_tcon_unbind(struct device *dev, struct device *master,
list_del(&tcon->list); list_del(&tcon->list);
if (tcon->quirks->has_channel_0) if (tcon->quirks->has_channel_0)
sun4i_dclk_free(tcon); sun4i_dclk_free(tcon);
sun4i_tcon_free_clocks(tcon);
} }
static const struct component_ops sun4i_tcon_ops = { static const struct component_ops sun4i_tcon_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment