Skip to contentSkip to conversation

media: amlogic: c3-mipi-csi2: clear csi->src_pad on error in enable_streams()

PATCH New Elkin Cruz 1 participant 1 message Nov 20

Subsystems (2)
lore
Share & tools
lore

Elkin Cruz

author
#0 lore raw

PATCH 1/1 media: amlogic: c3-mipi-csi2: clear csi->src_pad on error in enable_streams()

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")

---
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(+)
drivers/media/platform/amlogic/c3/mipi-csi2/c3-mipi-csi2.c +1 -0
index b5e59e810e13..c261daef15b3 100644
@@ -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;
 	}
 
Signature · 1 line
2.56.1.750.gf70dc682cf-goog