Skip to content
Snippets Groups Projects
Commit a272b281 authored by David Plowman's avatar David Plowman Committed by popcornmix
Browse files

media: ov5647: Fix return codes from ov5647_write/ov5647_read functions.


Previously they were returning positive non-zero codes for success,
which were getting passed up the call stack. Since release 4.19,
do_dentry_open (fs/open.c) has been catching these and flagging an
error. (So this driver has been broken since that date.)

Fixes: 3c2472a3 [media] media: i2c: Add support for OV5647 sensor
Signed-off-by: default avatarDavid Plowman <david.plowman@raspberrypi.org>
Signed-off-by: default avatarNaushir Patuck <naush@raspberrypi.com>
parent 3e463f7b
No related merge requests found
...@@ -214,9 +214,18 @@ static int ov5647_write(struct v4l2_subdev *sd, u16 reg, u8 val) ...@@ -214,9 +214,18 @@ static int ov5647_write(struct v4l2_subdev *sd, u16 reg, u8 val)
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
ret = i2c_master_send(client, data, 3); ret = i2c_master_send(client, data, 3);
if (ret < 0) /*
* Writing the wrong number of bytes also needs to be flagged as an
* error. Success needs to produce a 0 return code.
*/
if (ret == 3) {
ret = 0;
} else {
dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n", dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n",
__func__, reg); __func__, reg);
if (ret >= 0)
ret = -EINVAL;
}
return ret; return ret;
} }
...@@ -228,16 +237,31 @@ static int ov5647_read(struct v4l2_subdev *sd, u16 reg, u8 *val) ...@@ -228,16 +237,31 @@ static int ov5647_read(struct v4l2_subdev *sd, u16 reg, u8 *val)
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
ret = i2c_master_send(client, data_w, 2); ret = i2c_master_send(client, data_w, 2);
if (ret < 0) { /*
* A negative return code, or sending the wrong number of bytes, both
* count as an error.
*/
if (ret != 2) {
dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n", dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n",
__func__, reg); __func__, reg);
if (ret >= 0)
ret = -EINVAL;
return ret; return ret;
} }
ret = i2c_master_recv(client, val, 1); ret = i2c_master_recv(client, val, 1);
if (ret < 0) /*
* The only return value indicating success is 1. Anything else, even
* a non-negative value, indicates something went wrong.
*/
if (ret == 1) {
ret = 0;
} else {
dev_dbg(&client->dev, "%s: i2c read error, reg: %x\n", dev_dbg(&client->dev, "%s: i2c read error, reg: %x\n",
__func__, reg); __func__, reg);
if (ret >= 0)
ret = -EINVAL;
}
return ret; return ret;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment