Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 947ed99e authored by Prashant Laddha's avatar Prashant Laddha Committed by Mauro Carvalho Chehab
Browse files

[media] v4l2-dv-timings: add sanity checks in cvt,gtf calculations



Wrong values of hfreq and image height can lead to strange timings.
Avoid timing calculations for such values.

Suggested By: Martin Bugge <marbugge@cisco.com>

Cc: Martin Bugge <marbugge@cisco.com>
Signed-off-by: default avatarPrashant Laddha <prladdha@cisco.com>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent d7ed5a3d
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -365,6 +365,9 @@ bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
	else
	else
		return false;
		return false;


	if (hfreq == 0)
		return false;

	/* Vertical */
	/* Vertical */
	if (reduced_blanking) {
	if (reduced_blanking) {
		v_fp = CVT_RB_V_FPORCH;
		v_fp = CVT_RB_V_FPORCH;
@@ -382,6 +385,9 @@ bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync,
	}
	}
	image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1;
	image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1;


	if (image_height < 0)
		return false;

	/* Aspect ratio based on vsync */
	/* Aspect ratio based on vsync */
	switch (vsync) {
	switch (vsync) {
	case 4:
	case 4:
@@ -527,12 +533,18 @@ bool v4l2_detect_gtf(unsigned frame_height,
	else
	else
		return false;
		return false;


	if (hfreq == 0)
		return false;

	/* Vertical */
	/* Vertical */
	v_fp = GTF_V_FP;
	v_fp = GTF_V_FP;


	v_bp = (GTF_MIN_VSYNC_BP * hfreq + 500000) / 1000000 - vsync;
	v_bp = (GTF_MIN_VSYNC_BP * hfreq + 500000) / 1000000 - vsync;
	image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1;
	image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1;


	if (image_height < 0)
		return false;

	if (aspect.numerator == 0 || aspect.denominator == 0) {
	if (aspect.numerator == 0 || aspect.denominator == 0) {
		aspect.numerator = 16;
		aspect.numerator = 16;
		aspect.denominator = 9;
		aspect.denominator = 9;