From dab62ac5d3625160e183454fd801c3cf7b0a1fec Mon Sep 17 00:00:00 2001 From: Venkateshwar Rao Gannavarapu Date: Wed, 27 Apr 2022 22:59:26 +0530 Subject: [PATCH] drm: xlnx: pl_disp: Add strict check of video format in dt parsing. This patch adds strict check of supported video formats in device tree parsing. Signed-off-by: Venkateshwar Rao Gannavarapu Reviewed-by: Vishal Sagar --- drivers/gpu/drm/xlnx/xlnx_pl_disp.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/xlnx/xlnx_pl_disp.c b/drivers/gpu/drm/xlnx/xlnx_pl_disp.c index a7b226261500be..adcfecbd9daaf0 100644 --- a/drivers/gpu/drm/xlnx/xlnx_pl_disp.c +++ b/drivers/gpu/drm/xlnx/xlnx_pl_disp.c @@ -30,6 +30,7 @@ #include "xlnx_drv.h" #define XLNX_PL_DISP_MAX_NUM_PLANES 3 +#define XLNX_PL_DISP_VFMT_SIZE 4 /* * Overview * -------- @@ -584,6 +585,7 @@ static int xlnx_pl_disp_probe(struct platform_device *pdev) const char *vformat; struct dma_chan *dma_chan; struct xlnx_dma_chan *xlnx_dma_chan; + const struct drm_format_info *info; xlnx_pl_disp = devm_kzalloc(dev, sizeof(*xlnx_pl_disp), GFP_KERNEL); if (!xlnx_pl_disp) @@ -607,7 +609,13 @@ static int xlnx_pl_disp_probe(struct platform_device *pdev) goto err_dma; } - strcpy((char *)&xlnx_pl_disp->fmt, vformat); + strncpy((char *)&xlnx_pl_disp->fmt, vformat, XLNX_PL_DISP_VFMT_SIZE); + info = drm_format_info(xlnx_pl_disp->fmt); + if (!info) { + dev_err(dev, "Invalid video format in dts\n"); + ret = -EINVAL; + goto err_dma; + } /* VTC Bridge support */ vtc_node = of_parse_phandle(dev->of_node, "xlnx,bridge", 0);