Skip to contentSkip to conversation

media: vimc: sensor: fix pixel_rate type to resolve do_div() warning

PATCH In review Faizel K B 2 participants 2 messages Jul 28

Subsystems (2)
lore
Share & tools
lore

Faizel K B

author
#0 lore raw

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
index 83dcc9d61ee0..7cb544fdfddb 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw

Thanks

Quoted 8 lines · Faizel K B

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.

Quoted 4 lines
Quoted 35 lines
---
 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
index 83dcc9d61ee0..7cb544fdfddb 100644
@@ -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