From c23175616455864f37aae9cf40b60a10a72ff956 Mon Sep 17 00:00:00 2001 From: Dingxian Wen Date: Fri, 6 May 2022 16:11:13 +0800 Subject: [PATCH] media: rockchip: hdmirx: add timing validity judgment Signed-off-by: Dingxian Wen Change-Id: I11cfb328dc37c5239e2557460dd99f471d23a52b --- .../platform/rockchip/hdmirx/rk_hdmirx.c | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/rockchip/hdmirx/rk_hdmirx.c b/drivers/media/platform/rockchip/hdmirx/rk_hdmirx.c index c5b9179b3470..2e0606cab980 100644 --- a/drivers/media/platform/rockchip/hdmirx/rk_hdmirx.c +++ b/drivers/media/platform/rockchip/hdmirx/rk_hdmirx.c @@ -594,15 +594,36 @@ static void hdmirx_get_timings(struct rk_hdmirx_dev *hdmirx_dev, v4l2_dbg(1, debug, v4l2_dev, "get timings from %s\n", from_dma ? "dma" : "ctrl"); v4l2_dbg(1, debug, v4l2_dev, - "act:%dx%d, total:%dx%d, fps:%d, pixclk:%llu\n", + "act:%ux%u, total:%ux%u, fps:%u, pixclk:%llu\n", bt->width, bt->height, htotal, vtotal, fps, bt->pixelclock); v4l2_dbg(2, debug, v4l2_dev, - "hfp:%d, hs:%d, hbp:%d, vfp:%d, vs:%d, vbp:%d\n", + "hfp:%u, hs:%u, hbp:%u, vfp:%u, vs:%u, vbp:%u\n", bt->hfrontporch, bt->hsync, bt->hbackporch, bt->vfrontporch, bt->vsync, bt->vbackporch); } +static bool hdmirx_check_timing_valid(struct v4l2_bt_timings *bt) +{ + if (bt->width < 100 || bt->width > 5000 || + bt->height < 100 || bt->height > 5000) + return false; + + if (bt->hsync == 0 || bt->hsync > 200 || + bt->vsync == 0 || bt->vsync > 100) + return false; + + if (bt->hbackporch == 0 || bt->hbackporch > 2000 || + bt->vbackporch == 0 || bt->vbackporch > 2000) + return false; + + if (bt->hfrontporch == 0 || bt->hfrontporch > 2000 || + bt->vfrontporch == 0 || bt->vfrontporch > 2000) + return false; + + return true; +} + static int hdmirx_get_detected_timings(struct rk_hdmirx_dev *hdmirx_dev, struct v4l2_dv_timings *timings, bool from_dma) { @@ -639,16 +660,14 @@ static int hdmirx_get_detected_timings(struct rk_hdmirx_dev *hdmirx_dev, bt->il_vsync = bt->vsync + 1; } - v4l2_dbg(2, debug, v4l2_dev, "tmds_clk:%lld\n", tmds_clk); + v4l2_dbg(2, debug, v4l2_dev, "tmds_clk:%llu\n", tmds_clk); v4l2_dbg(1, debug, v4l2_dev, "interlace:%d, fmt:%d, vic:%d, color:%d, mode:%s\n", bt->interlaced, hdmirx_dev->pix_fmt, hdmirx_dev->cur_vic, hdmirx_dev->color_depth, hdmirx_dev->is_dvi_mode ? "dvi" : "hdmi"); v4l2_dbg(2, debug, v4l2_dev, "deframer_st:%#x\n", deframer_st); - if (bt->hsync > 200 || bt->vsync > 100 || - bt->hbackporch > 1000 || bt->vbackporch > 1000 || - bt->width < 100 || bt->height < 100) + if (!hdmirx_check_timing_valid(bt)) return -EINVAL; return 0;