Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: ov5640: fix frame interval enumeration

Driver must reject frame interval enumeration of unsupported resolution.
This was detected by v4l2-compliance format ioctl test:
v4l2-compliance Format ioctls:
info: found 2 frameintervals for pixel format 4745504a and size 176x144
fail: v4l2-test-formats.cpp(123):
found frame intervals for invalid size 177x144
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: FAIL

Signed-off-by: Hugues Fruchet <hugues.fruchet@st.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Hugues Fruchet and committed by
Mauro Carvalho Chehab
3c4a7372 2bbc46e8

+16 -18
+16 -18
drivers/media/i2c/ov5640.c
··· 1413 1413 ov5640_find_mode(struct ov5640_dev *sensor, enum ov5640_frame_rate fr, 1414 1414 int width, int height, bool nearest) 1415 1415 { 1416 - const struct ov5640_mode_info *mode = NULL; 1417 - int i; 1416 + const struct ov5640_mode_info *mode; 1418 1417 1419 - for (i = OV5640_NUM_MODES - 1; i >= 0; i--) { 1420 - mode = &ov5640_mode_data[fr][i]; 1418 + mode = v4l2_find_nearest_size(ov5640_mode_data[fr], 1419 + ARRAY_SIZE(ov5640_mode_data[fr]), 1420 + hact, vact, 1421 + width, height); 1421 1422 1422 - if (!mode->reg_data) 1423 - continue; 1424 - 1425 - if ((nearest && mode->hact <= width && 1426 - mode->vact <= height) || 1427 - (!nearest && mode->hact == width && 1428 - mode->vact == height)) 1429 - break; 1430 - } 1431 - 1432 - if (nearest && i < 0) 1433 - mode = &ov5640_mode_data[fr][0]; 1423 + if (!mode || 1424 + (!nearest && (mode->hact != width || mode->vact != height))) 1425 + return NULL; 1434 1426 1435 1427 return mode; 1436 1428 } ··· 2501 2509 2502 2510 sensor->current_fr = frame_rate; 2503 2511 sensor->frame_interval = fi->interval; 2504 - sensor->current_mode = ov5640_find_mode(sensor, frame_rate, mode->hact, 2505 - mode->vact, true); 2512 + mode = ov5640_find_mode(sensor, frame_rate, mode->hact, 2513 + mode->vact, true); 2514 + if (!mode) { 2515 + ret = -EINVAL; 2516 + goto out; 2517 + } 2518 + 2519 + sensor->current_mode = mode; 2506 2520 sensor->pending_mode_change = true; 2507 2521 out: 2508 2522 mutex_unlock(&sensor->lock);