media: camss: Fix signedness bug in video_enum_fmt()
Subsystems (5)
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.
---
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
@@ -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
PATCH 2/2 media: camss: missing error code in msm_video_register()
This error path returns success but it should return -EINVAL.
--- drivers/media/platform/qcom/camss/camss-video.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/platform/qcom/camss/camss-video.c +1 -0
@@ -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
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")Signed-off-by Dan Carpenter <[email protected]>--- drivers/media/platform/qcom/camss/camss-video.c | 1 + 1 file changed, 1 insertion(+)drivers/media/platform/qcom/camss/camss-video.c +1
-1@@ -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
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 toUINT_MAXwhich 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"")Signed-off-by Dan Carpenter <[email protected]>---
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@@ -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
Andrey Konovalov
Reviewed-byHi Dan,
Good catch!
Thanks,
Andrey
Quoted 38 lines · Robert Foss
Hey Dan,
Thank you for submitting this.
Reviewed-by Robert Foss <[email protected]>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 toUINT_MAXwhich 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"")Signed-off-by Dan Carpenter <[email protected]>---
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@@ -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