Re: [PATCH v2] drm/vc4: release firmware on error paths in vc4_hvs_bind()
From: Tomasz Unger
Date: Wed Nov 11 2026 - 08:22:17 EST
On Thu, Apr 03, 2025 at 03:14:33PM +0300, Dan Carpenter wrote:
> There was a bug where we should have called rpi_firmware_put(firmware)
> if devm_clk_get() failed. Really, it's better and more readable to
> move all the firmware code together so that we can release it one
> time.
>
> Fixes: 2fa4ef5fb943 ("drm/vc4: hvs: Create hw_init function")
> Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
Hi Dan,
It looks like this patch was never applied: the leak is still there in
v7.4-rc1. The patch still applies on top of v7.4-rc1 (with an offset), so
I gave it a test on a Raspberry Pi 4 Model B Rev 1.5 (arm64 defconfig).
Normal path: with and without the patch vc4 binds the HVS and the other
components in the same way, the core clock is acquired by fe400000.hvs
and dmesg shows the same messages in both cases.
Error path: to reach it I forced the core clock lookup to fail with a
test-only change (hvs->core_clk = ERR_PTR(-ENODEV) right after the
devm_clk_get() call) and traced rpi_firmware_get()/rpi_firmware_put()
with the function tracer while re-binding the vc4-drm driver.
Without the patch:
rpi_firmware_get <-vc4_drm_bind
rpi_firmware_put <-vc4_drm_bind
rpi_firmware_get <-vc4_hvs_bind
With the patch:
rpi_firmware_get <-vc4_drm_bind
rpi_firmware_put <-vc4_drm_bind
rpi_firmware_get <-vc4_hvs_bind
rpi_firmware_put <-vc4_hvs_bind
So without the patch every failed bind leaks one reference, and with the
patch the reference is dropped.
Tested-by: Tomasz Unger <tomasz.unger@xxxxxxxx>
One note about the Fixes tag: 2fa4ef5fb943 only moved this code around.
As far as I can tell, the rpi_firmware_get() before devm_clk_get()
without a put on the error path was introduced by commit 2a001ca00ad5
("drm/vc4: hdmi: Rework hdmi_enable_4kp60 detection code"), which went
into v6.2.
Thanks,
Tomasz