c7e10cbdc1134f8d05104e6c6aec98436a9fc30b
[openwrt/staging/ansuel.git] /
1 From 23f717168dc55f69ad517d3ab5f412d04a5afc0e 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 | 30 +++++++++++++++++++++++++++---
17 1 file changed, 27 insertions(+), 3 deletions(-)
18
19 --- a/drivers/media/i2c/ov5647.c
20 +++ b/drivers/media/i2c/ov5647.c
21 @@ -214,9 +214,18 @@ static int ov5647_write(struct v4l2_subd
22 struct i2c_client *client = v4l2_get_subdevdata(sd);
23
24 ret = i2c_master_send(client, data, 3);
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 == 3) {
31 + ret = 0;
32 + } else {
33 dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n",
34 __func__, reg);
35 + if (ret >= 0)
36 + ret = -EINVAL;
37 + }
38
39 return ret;
40 }
41 @@ -228,16 +237,31 @@ static int ov5647_read(struct v4l2_subde
42 struct i2c_client *client = v4l2_get_subdevdata(sd);
43
44 ret = i2c_master_send(client, data_w, 2);
45 - if (ret < 0) {
46 + /*
47 + * A negative return code, or sending the wrong number of bytes, both
48 + * count as an error.
49 + */
50 + if (ret != 2) {
51 dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n",
52 __func__, reg);
53 + if (ret >= 0)
54 + ret = -EINVAL;
55 return ret;
56 }
57
58 ret = i2c_master_recv(client, val, 1);
59 - if (ret < 0)
60 + /*
61 + * The only return value indicating success is 1. Anything else, even
62 + * a non-negative value, indicates something went wrong.
63 + */
64 + if (ret == 1) {
65 + ret = 0;
66 + } else {
67 dev_dbg(&client->dev, "%s: i2c read error, reg: %x\n",
68 __func__, reg);
69 + if (ret >= 0)
70 + ret = -EINVAL;
71 + }
72
73 return ret;
74 }