Skip to contentSkip to conversation

media: camss: Fix signedness bug in video_enum_fmt()

PATCH In review Dan Carpenter 3 participants 5 messages Dec 9, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 media: camss: Fix signedness bug in video_enum_fmt()

This test has a problem because we want to know if "k" is -1 or a positive value less than "f->index". But the "f->index" variable is a u32 so if "k = -1" then -1 gets type promoted to UINT_MAX which is larger than "f->index". I've added an explicit test to check for -1.

Fixes a3d412d4b9f3 ("media: Revert "media: camss: Make use of V4L2_CAP_IO_MC"")

---
I could equally well have casted "k < (int)f->index" but I feel like this is more explicit and readable.

 drivers/media/platform/qcom/camss/camss-video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/camss/camss-video.c +1 -1
index bd9334af1c73..2fa3214775d5 100644
@@ -579,7 +579,7 @@ static int video_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f)
 			break;
 	}
 
-	if (k < f->index)
+	if (k = -1 || k < f->index)
 		/*
 		 * All the unique pixel formats matching the arguments
 		 * have been enumerated (k >= 0 and f->index > 0), or
Signature · 1 line
2.29.2
#1 lore raw

PATCH 2/2 media: camss: missing error code in msm_video_register()

This error path returns success but it should return -EINVAL.

Fixes cba3819d1e93 ("media: camss: Format configuration per hardware version")
---
 drivers/media/platform/qcom/camss/camss-video.c | 1 +
 1 file changed, 1 insertion(+)
drivers/media/platform/qcom/camss/camss-video.c +1 -0
index 2fa3214775d5..97cea7c4d769 100644
@@ -961,6 +961,7 @@ int msm_video_register(struct camss_video *video, struct v4l2_device *v4l2_dev,
 			video->nformats = ARRAY_SIZE(formats_rdi_8x96);
 		}
 	} else {
+		ret = -EINVAL;
 		goto error_video_register;
 	}
 
Signature · 1 line
2.29.2
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] media: camss: missing error code in msm_video_register()

Thanks for submitting this Dan.

Quoted 24 lines · Dan Carpenter

This error path returns success but it should return -EINVAL.

Fixes cba3819d1e93 ("media: camss: Format configuration per hardware version")
---
 drivers/media/platform/qcom/camss/camss-video.c | 1 +
 1 file changed, 1 insertion(+)
drivers/media/platform/qcom/camss/camss-video.c +1 -1
index 2fa3214775d5..97cea7c4d769 100644
@@ -961,6 +961,7 @@ int msm_video_register(struct camss_video *video, struct v4l2_device *v4l2_dev,
                        video->nformats = ARRAY_SIZE(formats_rdi_8x96);
                }
        } else {
+               ret = -EINVAL;
                goto error_video_register;
        }
 
--

2.29.2

Reviewed-by on v1 1/2
#3 lore raw
In reply to Dan Carpenter

Hey Dan,

Thank you for submitting this.

Quoted 31 lines · Dan Carpenter

This test has a problem because we want to know if "k" is -1 or a positive value less than "f->index". But the "f->index" variable is a u32 so if "k = -1" then -1 gets type promoted to UINT_MAX which is larger than "f->index". I've added an explicit test to check for -1.

Fixes a3d412d4b9f3 ("media: Revert "media: camss: Make use of V4L2_CAP_IO_MC"")

---
I could equally well have casted "k < (int)f->index" but I feel like this is more explicit and readable.

 drivers/media/platform/qcom/camss/camss-video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/camss/camss-video.c +1 -2
index bd9334af1c73..2fa3214775d5 100644
@@ -579,7 +579,7 @@ static int video_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f)
                        break;
        }
 
-       if (k < f->index)
+       if (k = -1 || k < f->index)
                /*
                 * All the unique pixel formats matching the arguments
                 * have been enumerated (k >= 0 and f->index > 0), or
--

2.29.2

Reviewed-by
#4 lore raw

Hi Dan,

Good catch!

Thanks,
Andrey

Quoted 38 lines · Robert Foss

Hey Dan,

Thank you for submitting this.

Quoted 31 lines · Dan Carpenter

This test has a problem because we want to know if "k" is -1 or a positive value less than "f->index". But the "f->index" variable is a u32 so if "k = -1" then -1 gets type promoted to UINT_MAX which is larger than "f->index". I've added an explicit test to check for -1.

Fixes a3d412d4b9f3 ("media: Revert "media: camss: Make use of V4L2_CAP_IO_MC"")

---
I could equally well have casted "k < (int)f->index" but I feel like this is more explicit and readable.

  drivers/media/platform/qcom/camss/camss-video.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/camss/camss-video.c +1 -2
index bd9334af1c73..2fa3214775d5 100644
@@ -579,7 +579,7 @@ static int video_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f)
                         break;
         }
 
-       if (k < f->index)
+       if (k = -1 || k < f->index)
                 /*
                  * All the unique pixel formats matching the arguments
                  * have been enumerated (k >= 0 and f->index > 0), or
--

2.29.2