media: vimc: sensor: fix pixel_rate type to resolve do_div() warning
Subsystems (2)
PATCH 1/1 media: vimc: sensor: fix pixel_rate type to resolve do_div() warning
vsensor->pixel_rate->val is a plain s32 field. Declaring the local "pixel_rate" variable as u64 misrepresented its actual range and made do_div()'s divisor look wider than the 32-bit division it actually performs, which is exactly what the do_div() coccinelle check warns. Revert pixel_rate back to its original s32 type to match vsensor->pixel_rate->val, resolving the warning correctly.
--- drivers/media/test-drivers/vimc/vimc-sensor.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/media/test-drivers/vimc/vimc-sensor.c +2 -6
@@ -97,18 +97,14 @@ static void vimc_sensor_update_frame_timing(struct v4l2_subdev *sd, {struct vimc_sensor_device *vsensor = container_of(sd, struct vimc_sensor_device, sd); -u64 pixel_rate = vsensor->pixel_rate->val; +u32 pixel_rate = vsensor->pixel_rate->val;u32 hts = width + vsensor->hblank->val;u32 vts = height + vsensor->vblank->val;u64 total_pixels = (u64 )hts * vts;u64 frame_interval_ns; -/* Sanity check, pixel rate is fixed and fits in 32 bits. */ -if (WARN_ON (pixel_rate >=0x100000000 )) -return ; - frame_interval_ns = total_pixels *NSEC_PER_SEC ; -do_div (frame_interval_ns, (u32 )pixel_rate); +do_div (frame_interval_ns, pixel_rate); vsensor->hw.fps_jiffies =nsecs_to_jiffies (frame_interval_ns);if (vsensor->hw.fps_jiffies ==0 ) vsensor->hw.fps_jiffies =1 ;
base-commit: a52e6f7923c17a672135b485ffd96fbd72f46267
Signature · 1 line
2.43.0
Thanks
Quoted 8 lines · Faizel K B
vsensor->pixel_rate->valis a plain s32 field. Declaring the local "pixel_rate" variable as u64 misrepresented its actual range and made do_div()'s divisor look wider than the 32-bit division it actually performs, which is exactly what thedo_div()coccinelle check warns. Revertpixel_rateback to its original s32 type to matchvsensor->pixel_rate->val, resolving the warning correctly.
Quoted 4 lines
Fixes ec1e620b2454 ("media: vimc: sensor: Add pixel_rate,vblank and hblank configuration")Reported-by kernel test robot <[email protected]>
Quoted 35 lines
Signed-off-by Faizel K B <[email protected]>--- drivers/media/test-drivers/vimc/vimc-sensor.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/media/test-drivers/vimc/vimc-sensor.c +2
-6@@ -97,18 +97,14 @@ static void vimc_sensor_update_frame_timing(struct v4l2_subdev *sd, {struct vimc_sensor_device *vsensor = container_of(sd, struct vimc_sensor_device, sd); -u64 pixel_rate = vsensor->pixel_rate->val; +u32 pixel_rate = vsensor->pixel_rate->val;u32 hts = width + vsensor->hblank->val;u32 vts = height + vsensor->vblank->val;u64 total_pixels = (u64 )hts * vts;u64 frame_interval_ns; -/* Sanity check, pixel rate is fixed and fits in 32 bits. */ -if (WARN_ON (pixel_rate >=0x100000000 )) -return ; - frame_interval_ns = total_pixels *NSEC_PER_SEC ; -do_div (frame_interval_ns, (u32 )pixel_rate); +do_div (frame_interval_ns, pixel_rate); vsensor->hw.fps_jiffies =nsecs_to_jiffies (frame_interval_ns);if (vsensor->hw.fps_jiffies ==0 ) vsensor->hw.fps_jiffies =1 ;base-commit:
a52e6f7923c17a672135b485ffd96fbd72f46267--
2.43.0
Signature · 1 line
Ricardo Ribalda