Skip to content

Commit 147e084

Browse files
idlethreadSamuel Ortiz
authored andcommitted
mfd: Clarify twl4030 return value for read and write
We should be checking if all the messages were tranferred. If not, then we should propagate the i2c core error code or EIO. Currently we return success (0) even if none of messages were transferred successfully. Signed-off-by: Amit Kucheria <amit.kucheria@verdurent.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent ab4abe0 commit 147e084

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

‎drivers/mfd/twl4030-core.c‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,17 @@ int twl4030_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
306306
ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 1);
307307
mutex_unlock(&twl->xfer_lock);
308308

309-
/* i2cTransfer returns num messages.translate it pls.. */
310-
if (ret >= 0)
311-
ret = 0;
312-
return ret;
309+
/* i2c_transfer returns number of messages transferred */
310+
if (ret != 1) {
311+
pr_err("%s: i2c_write failed to transfer all messages\n",
312+
DRIVER_NAME);
313+
if (ret < 0)
314+
return ret;
315+
else
316+
return -EIO;
317+
} else {
318+
return 0;
319+
}
313320
}
314321
EXPORT_SYMBOL(twl4030_i2c_write);
315322

@@ -358,10 +365,17 @@ int twl4030_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
358365
ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 2);
359366
mutex_unlock(&twl->xfer_lock);
360367

361-
/* i2cTransfer returns num messages.translate it pls.. */
362-
if (ret >= 0)
363-
ret = 0;
364-
return ret;
368+
/* i2c_transfer returns number of messages transferred */
369+
if (ret != 2) {
370+
pr_err("%s: i2c_read failed to transfer all messages\n",
371+
DRIVER_NAME);
372+
if (ret < 0)
373+
return ret;
374+
else
375+
return -EIO;
376+
} else {
377+
return 0;
378+
}
365379
}
366380
EXPORT_SYMBOL(twl4030_i2c_read);
367381

0 commit comments

Comments
 (0)