kernel: bump 5.15 to 5.15.75
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0369-media-ov5647-Fix-return-codes-from-ov5647_write-ov56.patch
1 From 4095981bf8a912e5e8f5d86ff305d974d506b091 Mon Sep 17 00:00:00 2001
2 From: David Plowman <david.plowman@raspberrypi.org>
3 Date: Wed, 15 Jan 2020 13:40:38 +0000
4 Subject: [PATCH] media: ov5647: Fix return codes from
5 ov5647_write/ov5647_read functions.
6
7 Previously they were returning positive non-zero codes for success,
8 which were getting passed up the call stack. Since release 4.19,
9 do_dentry_open (fs/open.c) has been catching these and flagging an
10 error. (So this driver has been broken since that date.)
11
12 Fixes: 3c2472a [media] media: i2c: Add support for OV5647 sensor
13 Signed-off-by: David Plowman <david.plowman@raspberrypi.org>
14 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
15 ---
16 drivers/media/i2c/ov5647.c | 38 ++++++++++++++++++++++++++++++++------
17 1 file changed, 32 insertions(+), 6 deletions(-)
18
19 --- a/drivers/media/i2c/ov5647.c
20 +++ b/drivers/media/i2c/ov5647.c
21 @@ -587,7 +587,13 @@ static int ov5647_write16(struct v4l2_su
22 int ret;
23
24 ret = i2c_master_send(client, data, 4);
25 - if (ret < 0) {
26 + /*
27 + * Writing the wrong number of bytes also needs to be flagged as an
28 + * error. Success needs to produce a 0 return code.
29 + */
30 + if (ret == 4) {
31 + ret = 0;
32 + } else {
33 dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n",
34 __func__, reg);
35 return ret;
36 @@ -603,10 +609,17 @@ static int ov5647_write(struct v4l2_subd
37 int ret;
38
39 ret = i2c_master_send(client, data, 3);
40 - if (ret < 0) {
41 + /*
42 + * Writing the wrong number of bytes also needs to be flagged as an
43 + * error. Success needs to produce a 0 return code.
44 + */
45 + if (ret == 3) {
46 + ret = 0;
47 + } else {
48 dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n",
49 __func__, reg);
50 - return ret;
51 + if (ret >= 0)
52 + ret = -EINVAL;
53 }
54
55 return 0;
56 @@ -619,17 +632,30 @@ static int ov5647_read(struct v4l2_subde
57 int ret;
58
59 ret = i2c_master_send(client, data_w, 2);
60 - if (ret < 0) {
61 + /*
62 + * A negative return code, or sending the wrong number of bytes, both
63 + * count as an error.
64 + */
65 + if (ret != 2) {
66 dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n",
67 __func__, reg);
68 + if (ret >= 0)
69 + ret = -EINVAL;
70 return ret;
71 }
72
73 ret = i2c_master_recv(client, val, 1);
74 - if (ret < 0) {
75 + /*
76 + * The only return value indicating success is 1. Anything else, even
77 + * a non-negative value, indicates something went wrong.
78 + */
79 + if (ret == 1) {
80 + ret = 0;
81 + } else {
82 dev_dbg(&client->dev, "%s: i2c read error, reg: %x\n",
83 __func__, reg);
84 - return ret;
85 + if (ret >= 0)
86 + ret = -EINVAL;
87 }
88
89 return 0;