* [PATCH] drm/sun4i: fix refcount leak in sun4i_backend_init_sat()
@ 2026-06-07 3:09 Wentao Liang
2026-06-07 6:32 ` Christophe JAILLET
2026-06-13 7:50 ` Jernej Škrabec
0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-06-07 3:09 UTC (permalink / raw)
To: wens, maarten.lankhorst, mripard, tzimmermann, airlied, simona,
jernej.skrabec, samuel
Cc: dri-devel, linux-arm-kernel, linux-sunxi, linux-kernel,
Wentao Liang, stable
When sun4i_backend_init_sat() calls reset_control_deassert() it
increments the deassert_count of the reset controller, and must
pair that with a reset_control_assert() call to decrement it.
In the error path where clk_prepare_enable() fails, the function
returns immediately without calling reset_control_assert(), leaking
the reference count. Other error paths, like the devm_clk_get()
failure, correctly jump to the err_assert_reset label which performs
the missing assert.
Fix the leak by using the existing err_assert_reset label in the
clk_prepare_enable error path instead of returning directly.
Cc: stable@vger.kernel.org
Fixes: 440d2c7b127a ("drm/sun4i: backend: Handle the SAT")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/gpu/drm/sun4i/sun4i_backend.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c
index bc35dad53b07..c9ec5fc26f7e 100644
--- a/drivers/gpu/drm/sun4i/sun4i_backend.c
+++ b/drivers/gpu/drm/sun4i/sun4i_backend.c
@@ -686,7 +686,7 @@ static int sun4i_backend_init_sat(struct device *dev) {
ret = clk_prepare_enable(backend->sat_clk);
if (ret) {
dev_err(dev, "Couldn't enable the SAT clock\n");
- return ret;
+ goto err_assert_reset;
}
return 0;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] drm/sun4i: fix refcount leak in sun4i_backend_init_sat()
2026-06-07 3:09 [PATCH] drm/sun4i: fix refcount leak in sun4i_backend_init_sat() Wentao Liang
@ 2026-06-07 6:32 ` Christophe JAILLET
2026-06-13 7:50 ` Jernej Škrabec
1 sibling, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2026-06-07 6:32 UTC (permalink / raw)
To: Wentao Liang, wens, maarten.lankhorst, mripard, tzimmermann,
airlied, simona, jernej.skrabec, samuel
Cc: dri-devel, linux-arm-kernel, linux-sunxi, linux-kernel, stable
Le 07/06/2026 à 05:09, Wentao Liang a écrit :
> When sun4i_backend_init_sat() calls reset_control_deassert() it
> increments the deassert_count of the reset controller, and must
> pair that with a reset_control_assert() call to decrement it.
> In the error path where clk_prepare_enable() fails, the function
> returns immediately without calling reset_control_assert(), leaking
> the reference count. Other error paths, like the devm_clk_get()
> failure, correctly jump to the err_assert_reset label which performs
> the missing assert.
>
> Fix the leak by using the existing err_assert_reset label in the
> clk_prepare_enable error path instead of returning directly.
>
> Cc: stable@vger.kernel.org
> Fixes: 440d2c7b127a ("drm/sun4i: backend: Handle the SAT")
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
> drivers/gpu/drm/sun4i/sun4i_backend.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c
> index bc35dad53b07..c9ec5fc26f7e 100644
> --- a/drivers/gpu/drm/sun4i/sun4i_backend.c
> +++ b/drivers/gpu/drm/sun4i/sun4i_backend.c
> @@ -686,7 +686,7 @@ static int sun4i_backend_init_sat(struct device *dev) {
> ret = clk_prepare_enable(backend->sat_clk);
> if (ret) {
> dev_err(dev, "Couldn't enable the SAT clock\n");
> - return ret;
> + goto err_assert_reset;
> }
>
> return 0;
Hi,
another way to fix it and simplify the code at the same time would be to
use devm_reset_control_get_exclusive_deasserted() and
devm_clk_get_enabled().
just my 2c,
CJ
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] drm/sun4i: fix refcount leak in sun4i_backend_init_sat()
2026-06-07 3:09 [PATCH] drm/sun4i: fix refcount leak in sun4i_backend_init_sat() Wentao Liang
2026-06-07 6:32 ` Christophe JAILLET
@ 2026-06-13 7:50 ` Jernej Škrabec
1 sibling, 0 replies; 3+ messages in thread
From: Jernej Škrabec @ 2026-06-13 7:50 UTC (permalink / raw)
To: wens, maarten.lankhorst, mripard, tzimmermann, airlied, simona,
samuel, Wentao Liang
Cc: dri-devel, linux-arm-kernel, linux-sunxi, linux-kernel,
Wentao Liang, stable
Dne nedelja, 7. junij 2026 ob 05:09:50 Srednjeevropski poletni čas je Wentao Liang napisal(a):
> When sun4i_backend_init_sat() calls reset_control_deassert() it
> increments the deassert_count of the reset controller, and must
> pair that with a reset_control_assert() call to decrement it.
> In the error path where clk_prepare_enable() fails, the function
> returns immediately without calling reset_control_assert(), leaking
> the reference count. Other error paths, like the devm_clk_get()
> failure, correctly jump to the err_assert_reset label which performs
> the missing assert.
>
> Fix the leak by using the existing err_assert_reset label in the
> clk_prepare_enable error path instead of returning directly.
>
> Cc: stable@vger.kernel.org
> Fixes: 440d2c7b127a ("drm/sun4i: backend: Handle the SAT")
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Best regards,
Jernej
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-13 7:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-07 3:09 [PATCH] drm/sun4i: fix refcount leak in sun4i_backend_init_sat() Wentao Liang
2026-06-07 6:32 ` Christophe JAILLET
2026-06-13 7:50 ` Jernej Škrabec
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox