media: vimc: Ensure that pixel_rate fits in 32 bits

pixel_rate is set to VIMC_PIXEL_RATE_FIXED, which the code expects to
fit in 32 bits. Make that constraint into a WARN_ON, so if we ever break
that constraint a kernel warning will be triggered.

It also fixes the following cocci warning:
./test-drivers/vimc/vimc-sensor.c:107:1-7: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead.

Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
This commit is contained in:
Ricardo Ribalda 2026-06-29 11:30:45 +00:00 committed by Hans Verkuil
parent 91624e5806
commit 6b8ff73412

View File

@ -103,8 +103,12 @@ static void vimc_sensor_update_frame_timing(struct v4l2_subdev *sd,
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, pixel_rate);
do_div(frame_interval_ns, (u32)pixel_rate);
vsensor->hw.fps_jiffies = nsecs_to_jiffies(frame_interval_ns);
if (vsensor->hw.fps_jiffies == 0)
vsensor->hw.fps_jiffies = 1;