Skip to content

Commit 3edd1fc

Browse files
Karina Yankevichhverkuil
authored andcommitted
media: v4l2-dv-timings: prevent possible overflow in v4l2_detect_gtf()
In v4l2_detect_gtf(), it seems safer to cast the 32-bit image_width variable to the 64-bit type u64 before multiplying to avoid a possible overflow. The resulting object code even seems to look better, at least on x86_64. Found by Linux Verification Center (linuxtesting.org) with Svace. [Sergey: rewrote the patch subject/descripition] Fixes: c9bc9f5 ("[media] v4l2-dv-timings: fix overflow in gtf timings calculation") Cc: [email protected] Signed-off-by: Karina Yankevich <[email protected]> Signed-off-by: Sergey Shtylyov <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 11de358 commit 3edd1fc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/media/v4l2-core/v4l2-dv-timings.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ bool v4l2_detect_gtf(unsigned int frame_height,
764764
u64 num;
765765
u32 den;
766766

767-
num = ((image_width * GTF_D_C_PRIME * (u64)hfreq) -
767+
num = (((u64)image_width * GTF_D_C_PRIME * hfreq) -
768768
((u64)image_width * GTF_D_M_PRIME * 1000));
769769
den = (hfreq * (100 - GTF_D_C_PRIME) + GTF_D_M_PRIME * 1000) *
770770
(2 * GTF_CELL_GRAN);
@@ -774,7 +774,7 @@ bool v4l2_detect_gtf(unsigned int frame_height,
774774
u64 num;
775775
u32 den;
776776

777-
num = ((image_width * GTF_S_C_PRIME * (u64)hfreq) -
777+
num = (((u64)image_width * GTF_S_C_PRIME * hfreq) -
778778
((u64)image_width * GTF_S_M_PRIME * 1000));
779779
den = (hfreq * (100 - GTF_S_C_PRIME) + GTF_S_M_PRIME * 1000) *
780780
(2 * GTF_CELL_GRAN);

0 commit comments

Comments
 (0)