mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: amlogic: c3-mipi-csi2: clear csi->src_pad on error in enable_streams()
@ 2026-11-20 19:24 Elkin Cruz
  2026-12-02  2:17 ` Keke Li
  0 siblings, 1 reply; 2+ messages in thread
From: Elkin Cruz @ 2026-11-20 19:24 UTC (permalink / raw)
  To: Keke Li, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, llvm, irogers, Elkin Cruz

When media_pad_remote_pad_unique() fails in c3_mipi_csi_enable_streams(),
csi->src_pad is left holding an ERR_PTR() value. Subsequent calls such
as c3_mipi_csi_disable_streams() can then dereference the poisoned
struct member.

Reset csi->src_pad to NULL before returning -EPIPE.

Fixes: b63ef604a28d ("media: platform: Add C3 MIPI CSI-2 driver")
Signed-off-by: Elkin Cruz <elkin@google.com>
---
I am trying out a new Clang static analysis linter for ERR_PTR/NULL
handling, and it flagged this code as possibly buggy. The findings were triaged
and fixed with an AI coding assistant, then checked against linux-next (not
runtime-tested on hardware).

Thanks,
Elkin

 drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c b/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c
index b5e59e810e13..c261daef15b3 100644
--- a/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c
+++ b/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c
@@ -426,6 +426,7 @@ static int c3_mipi_csi_enable_streams(struct v4l2_subdev *sd,
 	csi->src_pad = media_pad_remote_pad_unique(sink_pad);
 	if (IS_ERR(csi->src_pad)) {
 		dev_dbg(csi->dev, "Failed to get source pad for MIPI CSI-2\n");
+		csi->src_pad = NULL;
 		return -EPIPE;
 	}
 
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] media: amlogic: c3-mipi-csi2: clear csi->src_pad on error in enable_streams()
  2026-11-20 19:24 [PATCH] media: amlogic: c3-mipi-csi2: clear csi->src_pad on error in enable_streams() Elkin Cruz
@ 2026-12-02  2:17 ` Keke Li
  0 siblings, 0 replies; 2+ messages in thread
From: Keke Li @ 2026-12-02  2:17 UTC (permalink / raw)
  To: Elkin Cruz, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, llvm, irogers

Hi Elkin,

Thanks for your patch.

On 11/21/26 03:24, Elkin Cruz wrote:
> [You don't often get email from elkin@google.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> When media_pad_remote_pad_unique() fails in c3_mipi_csi_enable_streams(),
> csi->src_pad is left holding an ERR_PTR() value. Subsequent calls such
> as c3_mipi_csi_disable_streams() can then dereference the poisoned
> struct member.
>
> Reset csi->src_pad to NULL before returning -EPIPE.
>
> Fixes: b63ef604a28d ("media: platform: Add C3 MIPI CSI-2 driver")
> Signed-off-by: Elkin Cruz <elkin@google.com>
> ---
> I am trying out a new Clang static analysis linter for ERR_PTR/NULL
> handling, and it flagged this code as possibly buggy. The findings were triaged
> and fixed with an AI coding assistant, then checked against linux-next (not
> runtime-tested on hardware).
>
> Thanks,
> Elkin

I think you are right.

Can you help check other device nodes?

Reviewed-by: Keke Li <keke.li@amlogic.com>

>
>   drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c b/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c
> index b5e59e810e13..c261daef15b3 100644
> --- a/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c
> +++ b/drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c
> @@ -426,6 +426,7 @@ static int c3_mipi_csi_enable_streams(struct v4l2_subdev *sd,
>          csi->src_pad = media_pad_remote_pad_unique(sink_pad);
>          if (IS_ERR(csi->src_pad)) {
>                  dev_dbg(csi->dev, "Failed to get source pad for MIPI CSI-2\n");
> +               csi->src_pad = NULL;
>                  return -EPIPE;
>          }
>
> --
> 2.56.1.750.gf70dc682cf-goog
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02  2:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 19:24 [PATCH] media: amlogic: c3-mipi-csi2: clear csi->src_pad on error in enable_streams() Elkin Cruz
2026-12-02  2:17 ` Keke Li

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®