* [PATCH] media: coda: Release firmware if code buffer allocation fails
@ 2026-11-26 5:21 Yige Jiang
2026-11-26 9:46 ` Philipp Zabel
0 siblings, 1 reply; 2+ messages in thread
From: Yige Jiang @ 2026-11-26 5:21 UTC (permalink / raw)
To: Philipp Zabel, Mauro Carvalho Chehab
Cc: Yige Jiang, linux-media, linux-kernel, stable
coda_fw_callback() owns the firmware passed to it by
request_firmware_nowait(). It normally releases the firmware after copying
it into the BIT processor's code buffer. If allocating that buffer fails,
the callback jumps to put_pm and skips release_firmware(), leaking the
firmware and its associated resources.
Release the firmware before jumping to put_pm, which drops the runtime PM
reference taken in coda_probe().
An AI coding assistant helped identify the leak during review of static
analysis results and helped draft the fix and commit message.
Fixes: 186b250a0725 ("[media] media: coda: Add driver for Coda video codec")
Cc: stable@vger.kernel.org
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
Based on linux-next next-20261109 (630059a5a632).
Compile-tested: arm64 coda-common.o with GCC 14.2 and W=1,
CONFIG_COMPILE_TEST=y, CONFIG_ARCH_MXC=y and CONFIG_VIDEO_CODA=m.
The baseline and patched object builds both produced 0 warnings.
No hardware or runtime test was performed.
The path needs the coherent DMA allocation of the code buffer to fail in the async firmware callback (OOM or fault injection).
drivers/media/platform/chips-media/coda/coda-common.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/chips-media/coda/coda-common.c b/drivers/media/platform/chips-media/coda/coda-common.c
index 3fe33c4..ca8f953 100644
--- a/drivers/media/platform/chips-media/coda/coda-common.c
+++ b/drivers/media/platform/chips-media/coda/coda-common.c
@@ -3004,8 +3004,10 @@ static void coda_fw_callback(const struct firmware *fw, void *context)
/* allocate auxiliary per-device code buffer for the BIT processor */
ret = coda_alloc_aux_buf(dev, &dev->codebuf, fw->size, "codebuf",
dev->debugfs_root);
- if (ret < 0)
+ if (ret < 0) {
+ release_firmware(fw);
goto put_pm;
+ }
coda_copy_firmware(dev, fw->data, fw->size);
release_firmware(fw);
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] media: coda: Release firmware if code buffer allocation fails
2026-11-26 5:21 [PATCH] media: coda: Release firmware if code buffer allocation fails Yige Jiang
@ 2026-11-26 9:46 ` Philipp Zabel
0 siblings, 0 replies; 2+ messages in thread
From: Philipp Zabel @ 2026-11-26 9:46 UTC (permalink / raw)
To: Yige Jiang, Mauro Carvalho Chehab; +Cc: linux-media, linux-kernel, stable
On Do, 2026-11-26 at 13:21 +0800, Yige Jiang wrote:
> coda_fw_callback() owns the firmware passed to it by
> request_firmware_nowait(). It normally releases the firmware after copying
> it into the BIT processor's code buffer. If allocating that buffer fails,
> the callback jumps to put_pm and skips release_firmware(), leaking the
> firmware and its associated resources.
>
> Release the firmware before jumping to put_pm, which drops the runtime PM
> reference taken in coda_probe().
>
> An AI coding assistant helped identify the leak during review of static
> analysis results and helped draft the fix and commit message.
>
> Fixes: 186b250a0725 ("[media] media: coda: Add driver for Coda video codec")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
> ---
> Based on linux-next next-20261109 (630059a5a632).
> Compile-tested: arm64 coda-common.o with GCC 14.2 and W=1,
> CONFIG_COMPILE_TEST=y, CONFIG_ARCH_MXC=y and CONFIG_VIDEO_CODA=m.
> The baseline and patched object builds both produced 0 warnings.
> No hardware or runtime test was performed.
> The path needs the coherent DMA allocation of the code buffer to fail in the async firmware callback (OOM or fault injection).
>
> drivers/media/platform/chips-media/coda/coda-common.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/chips-media/coda/coda-common.c b/drivers/media/platform/chips-media/coda/coda-common.c
> index 3fe33c4..ca8f953 100644
> --- a/drivers/media/platform/chips-media/coda/coda-common.c
> +++ b/drivers/media/platform/chips-media/coda/coda-common.c
> @@ -3004,8 +3004,10 @@ static void coda_fw_callback(const struct firmware *fw, void *context)
> /* allocate auxiliary per-device code buffer for the BIT processor */
> ret = coda_alloc_aux_buf(dev, &dev->codebuf, fw->size, "codebuf",
> dev->debugfs_root);
> - if (ret < 0)
> + if (ret < 0) {
> + release_firmware(fw);
> goto put_pm;
> + }
>
> coda_copy_firmware(dev, fw->data, fw->size);
> release_firmware(fw);
>
> base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
regards
Philipp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 9:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 5:21 [PATCH] media: coda: Release firmware if code buffer allocation fails Yige Jiang
2026-11-26 9:46 ` Philipp Zabel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®