Skip to content

Commit 50b9fa7

Browse files
committed
media: adv7604: prevent underflow condition when reporting colorspace
Currently, adv76xx_log_status() reads some date using io_read() which may return negative values. The current logic doesn't check such errors, causing colorspace to be reported on a wrong way at adv76xx_log_status(), as reported by Coverity. If I/O error happens there, print a different message, instead of reporting bogus messages to userspace. Fixes: 54450f5 ("[media] adv7604: driver for the Analog Devices ADV7604 video decoder") Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Reviewed-by: Hans Verkuil <hverkuil@xs4all.nl>
1 parent 576a307 commit 50b9fa7

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

drivers/media/i2c/adv7604.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,10 +2519,10 @@ static int adv76xx_log_status(struct v4l2_subdev *sd)
25192519
const struct adv76xx_chip_info *info = state->info;
25202520
struct v4l2_dv_timings timings;
25212521
struct stdi_readback stdi;
2522-
u8 reg_io_0x02 = io_read(sd, 0x02);
2522+
int ret;
2523+
u8 reg_io_0x02;
25232524
u8 edid_enabled;
25242525
u8 cable_det;
2525-
25262526
static const char * const csc_coeff_sel_rb[16] = {
25272527
"bypassed", "YPbPr601 -> RGB", "reserved", "YPbPr709 -> RGB",
25282528
"reserved", "RGB -> YPbPr601", "reserved", "RGB -> YPbPr709",
@@ -2621,13 +2621,21 @@ static int adv76xx_log_status(struct v4l2_subdev *sd)
26212621
v4l2_info(sd, "-----Color space-----\n");
26222622
v4l2_info(sd, "RGB quantization range ctrl: %s\n",
26232623
rgb_quantization_range_txt[state->rgb_quantization_range]);
2624-
v4l2_info(sd, "Input color space: %s\n",
2625-
input_color_space_txt[reg_io_0x02 >> 4]);
2626-
v4l2_info(sd, "Output color space: %s %s, alt-gamma %s\n",
2627-
(reg_io_0x02 & 0x02) ? "RGB" : "YCbCr",
2628-
(((reg_io_0x02 >> 2) & 0x01) ^ (reg_io_0x02 & 0x01)) ?
2629-
"(16-235)" : "(0-255)",
2630-
(reg_io_0x02 & 0x08) ? "enabled" : "disabled");
2624+
2625+
ret = io_read(sd, 0x02);
2626+
if (ret < 0) {
2627+
v4l2_info(sd, "Can't read Input/Output color space\n");
2628+
} else {
2629+
reg_io_0x02 = ret;
2630+
2631+
v4l2_info(sd, "Input color space: %s\n",
2632+
input_color_space_txt[reg_io_0x02 >> 4]);
2633+
v4l2_info(sd, "Output color space: %s %s, alt-gamma %s\n",
2634+
(reg_io_0x02 & 0x02) ? "RGB" : "YCbCr",
2635+
(((reg_io_0x02 >> 2) & 0x01) ^ (reg_io_0x02 & 0x01)) ?
2636+
"(16-235)" : "(0-255)",
2637+
(reg_io_0x02 & 0x08) ? "enabled" : "disabled");
2638+
}
26312639
v4l2_info(sd, "Color space conversion: %s\n",
26322640
csc_coeff_sel_rb[cp_read(sd, info->cp_csc) >> 4]);
26332641

0 commit comments

Comments
 (0)