Commit 66083b49 authored by Dan Carpenter's avatar Dan Carpenter Committed by Mauro Carvalho Chehab

media: dib0700: fix error handling in dib0700_i2c_xfer_legacy()

Mostly this adds some unlocks to error paths.  But, if you see where
there were "break;" statements before, I changed those paths to return
error codes instead of returning success.
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent d18a6ef5
...@@ -287,7 +287,7 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap, ...@@ -287,7 +287,7 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
{ {
struct dvb_usb_device *d = i2c_get_adapdata(adap); struct dvb_usb_device *d = i2c_get_adapdata(adap);
struct dib0700_state *st = d->priv; struct dib0700_state *st = d->priv;
int i,len; int i, len, result;
if (mutex_lock_interruptible(&d->i2c_mutex) < 0) if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
return -EINTR; return -EINTR;
...@@ -304,7 +304,8 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap, ...@@ -304,7 +304,8 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
if (msg[i].len > sizeof(st->buf) - 2) { if (msg[i].len > sizeof(st->buf) - 2) {
deb_info("i2c xfer to big: %d\n", deb_info("i2c xfer to big: %d\n",
msg[i].len); msg[i].len);
return -EIO; result = -EIO;
goto unlock;
} }
memcpy(&st->buf[2], msg[i].buf, msg[i].len); memcpy(&st->buf[2], msg[i].buf, msg[i].len);
...@@ -319,13 +320,15 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap, ...@@ -319,13 +320,15 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
if (len <= 0) { if (len <= 0) {
deb_info("I2C read failed on address 0x%02x\n", deb_info("I2C read failed on address 0x%02x\n",
msg[i].addr); msg[i].addr);
break; result = -EIO;
goto unlock;
} }
if (msg[i + 1].len > sizeof(st->buf)) { if (msg[i + 1].len > sizeof(st->buf)) {
deb_info("i2c xfer buffer to small for %d\n", deb_info("i2c xfer buffer to small for %d\n",
msg[i].len); msg[i].len);
return -EIO; result = -EIO;
goto unlock;
} }
memcpy(msg[i + 1].buf, st->buf, msg[i + 1].len); memcpy(msg[i + 1].buf, st->buf, msg[i + 1].len);
...@@ -334,14 +337,17 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap, ...@@ -334,14 +337,17 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
i++; i++;
} else { } else {
st->buf[0] = REQUEST_I2C_WRITE; st->buf[0] = REQUEST_I2C_WRITE;
if (dib0700_ctrl_wr(d, st->buf, msg[i].len + 2) < 0) result = dib0700_ctrl_wr(d, st->buf, msg[i].len + 2);
break; if (result < 0)
goto unlock;
} }
} }
result = i;
unlock:
mutex_unlock(&d->usb_mutex); mutex_unlock(&d->usb_mutex);
mutex_unlock(&d->i2c_mutex); mutex_unlock(&d->i2c_mutex);
return i; return result;
} }
static int dib0700_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, static int dib0700_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment