Skip to contentSkip to conversation

media: v4l2-subdev: Fix error check in v4l2_subdev_get_frame_desc_passthrough()

PATCH In review Chen Ni 2 participants 2 messages Mar 17 – Mar 18 Media (V4L/DVB)

lore
Share & tools
lore

Chen Ni

author
#0 lore raw

PATCH v3 1/1 media: v4l2-subdev: Fix error check in v4l2_subdev_get_frame_desc_passthrough()

Use IS_ERR() and PTR_ERR() to properly handle the error return from media_pad_remote_pad_unique(), which returns ERR_PTR() on failure but never NULL. The previous code only checked for NULL, leading to invalid pointer dereference.

Detected by Smatch:
drivers/media/v4l2-core/v4l2-subdev.c:2588 v4l2_subdev_get_frame_desc_passthrough() warn:
'remote_source_pad' is an error pointer or valid

drivers/media/v4l2-core/v4l2-subdev.c:2595 v4l2_subdev_get_frame_desc_passthrough() error:
'remote_source_pad' dereferencing possible ERR_PTR()

Fixes a564839e630c ("media: subdev: Add v4l2_subdev_get_frame_desc_passthrough helper")

---
Changes in v3:
- Remove the Reported-by tag due to missing Closes: URL

Changes in v2:
- Added Smatch warning messages to commit message
- Added Reported-by tag for Ethan Tidmore
- Kept both Reviewed-by tags

---
 drivers/media/v4l2-core/v4l2-subdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +2 -2
index 9efd14d4026f..7cb17e0a5617 100644
@@ -2585,10 +2585,10 @@ int v4l2_subdev_get_frame_desc_passthrough(struct v4l2_subdev *sd,
 
 			if (!have_source_fd) {
 				remote_source_pad = media_pad_remote_pad_unique(local_sink_pad);
-				if (!remote_source_pad) {
+				if (IS_ERR(remote_source_pad)) {
 					dev_dbg(dev, "Failed to find remote pad for sink pad %u\n",
 						local_sink_pad->index);
-					ret = -EINVAL;
+					ret = PTR_ERR(remote_source_pad);
 					goto out_unlock;
 				}
 
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#1 lore raw

Hi Chen,

Thank you for the patch.

Quoted 9 lines · Chen Ni

Use IS_ERR() and PTR_ERR() to properly handle the error return from media_pad_remote_pad_unique(), which returns ERR_PTR() on failure but never NULL. The previous code only checked for NULL, leading to invalid pointer dereference.

Detected by Smatch:
drivers/media/v4l2-core/v4l2-subdev.c:2588 v4l2_subdev_get_frame_desc_passthrough() warn:
'remote_source_pad' is an error pointer or valid

Quoted 7 lines

drivers/media/v4l2-core/v4l2-subdev.c:2595 v4l2_subdev_get_frame_desc_passthrough() error:
'remote_source_pad' dereferencing possible ERR_PTR()

Fixes a564839e630c ("media: subdev: Add v4l2_subdev_get_frame_desc_passthrough helper")

Sakari, Hans, will you pick this patch up for v7.1 ?

Quoted 29 lines

---
Changes in v3:
- Remove the Reported-by tag due to missing Closes: URL

Changes in v2:
- Added Smatch warning messages to commit message
- Added Reported-by tag for Ethan Tidmore
- Kept both Reviewed-by tags

---
 drivers/media/v4l2-core/v4l2-subdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +2 -2
index 9efd14d4026f..7cb17e0a5617 100644
@@ -2585,10 +2585,10 @@ int v4l2_subdev_get_frame_desc_passthrough(struct v4l2_subdev *sd,
 
 			if (!have_source_fd) {
 				remote_source_pad = media_pad_remote_pad_unique(local_sink_pad);
-				if (!remote_source_pad) {
+				if (IS_ERR(remote_source_pad)) {
 					dev_dbg(dev, "Failed to find remote pad for sink pad %u\n",
 						local_sink_pad->index);
-					ret = -EINVAL;
+					ret = PTR_ERR(remote_source_pad);
 					goto out_unlock;
 				}
 
Signature · 3 lines
Regards,

Laurent Pinchart