From 6c70405c2e294920e989aa7fe4635525d3f8eef0 Mon Sep 17 00:00:00 2001 From: Akhil Raghu Menon Date: Wed, 18 May 2022 03:11:30 -0700 Subject: [PATCH] v4l: xilinx: multi-scaler: Fix warnings for unchecked return value This patch fixes the coverity warnings about return value not being checked and improper use of negative value. The actual warnings are: For xm2msc_parse_of(): Event check_return: Calling of_property_count_strings without checking return value Event unchecked_value: Using value hw_vid_fmt_cnt as a function argument without checking appropriately Event negative_return_fn: Function of_property_count_strings (node, "xlnx,vid-formats") returns a negative number Event negative_returns: hw_vid_fmt_cnt is passed to a parameter that cannot be negative Signed-off-by: Akhil Raghu Menon Reviewed-by: Vishal Sagar --- drivers/media/platform/xilinx/xilinx-multi-scaler.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/media/platform/xilinx/xilinx-multi-scaler.c b/drivers/media/platform/xilinx/xilinx-multi-scaler.c index eb4ec0c8963258..5bfdab85b41393 100644 --- a/drivers/media/platform/xilinx/xilinx-multi-scaler.c +++ b/drivers/media/platform/xilinx/xilinx-multi-scaler.c @@ -2286,6 +2286,13 @@ static int xm2msc_parse_of(struct platform_device *pdev, /* read supported video formats and update internal table */ hw_vid_fmt_cnt = of_property_count_strings(node, "xlnx,vid-formats"); + /* Validate the number of strings returned */ + if (hw_vid_fmt_cnt < 0) + return hw_vid_fmt_cnt; + + if (hw_vid_fmt_cnt > ARRAY_SIZE(formats)) + return -EINVAL; + ret = of_property_read_string_array(node, "xlnx,vid-formats", vid_fmts, hw_vid_fmt_cnt); if (ret < 0) {