cb9a82b12769673eee6e2e6b6eaa9c571d271cab
[openwrt/staging/nbd.git] /
1 From 1a013467030ffd6f1958b8a4db1b5312213fb9bd Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Thu, 17 Oct 2019 10:16:16 +0100
4 Subject: [PATCH] media: bcm2835-unicam: Replace hard coded loop limit
5 with a define
6
7 In order to protect against a dodgy sensor driver never returning
8 an error from enum_mbus_code there was a hardcoded value of 128
9 that aborted the loop.
10 There is a need to call enum_mbus_code from elsewhere, so move that
11 number to a define so it is common across calls.
12
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
14 ---
15 drivers/media/platform/bcm2835/bcm2835-unicam.c | 11 ++++++-----
16 1 file changed, 6 insertions(+), 5 deletions(-)
17
18 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
19 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
20 @@ -97,6 +97,11 @@ MODULE_PARM_DESC(debug, "Debug level 0-3
21 #define unicam_err(dev, fmt, arg...) \
22 v4l2_err(&(dev)->v4l2_dev, fmt, ##arg)
23
24 +/* To protect against a dodgy sensor driver never returning an error from
25 + * enum_mbus_code, set a maximum index value to be used.
26 + */
27 +#define MAX_ENUM_MBUS_CODE 128
28 +
29 /*
30 * Stride is a 16 bit register, but also has to be a multiple of 16.
31 */
32 @@ -738,11 +743,7 @@ static int unicam_enum_fmt_vid_cap(struc
33 int ret = 0;
34 int i;
35
36 - /* Loop whilst the sensor driver says it has more formats, but add a
37 - * failsafe against a dodgy driver at 128 (more than any sensor will
38 - * ever sensibly advertise)
39 - */
40 - for (i = 0; !ret && i < 128 ; i++) {
41 + for (i = 0; !ret && i < MAX_ENUM_MBUS_CODE; i++) {
42 memset(&mbus_code, 0, sizeof(mbus_code));
43 mbus_code.index = i;
44