Skip to content

Commit 91811a3

Browse files
author
Wolfram Sang
committed
i2c: smbus: fix NULL function pointer dereference
Baruch reported an OOPS when using the designware controller as target only. Target-only modes break the assumption of one transfer function always being available. Fix this by always checking the pointer in __i2c_transfer. Reported-by: Baruch Siach <[email protected]> Closes: https://lore.kernel.org/r/4269631780e5ba789cf1ae391eec1b959def7d99.1712761976.git.baruch@tkos.co.il Fixes: 4b1acc4 ("i2c: core changes for slave support") [wsa: dropped the simplification in core-smbus to avoid theoretical regressions] Signed-off-by: Wolfram Sang <[email protected]> Tested-by: Baruch Siach <[email protected]>
1 parent 1d422e4 commit 91811a3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,13 +2200,18 @@ static int i2c_check_for_quirks(struct i2c_adapter *adap, struct i2c_msg *msgs,
22002200
* Returns negative errno, else the number of messages executed.
22012201
*
22022202
* Adapter lock must be held when calling this function. No debug logging
2203-
* takes place. adap->algo->master_xfer existence isn't checked.
2203+
* takes place.
22042204
*/
22052205
int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
22062206
{
22072207
unsigned long orig_jiffies;
22082208
int ret, try;
22092209

2210+
if (!adap->algo->master_xfer) {
2211+
dev_dbg(&adap->dev, "I2C level transfers not supported\n");
2212+
return -EOPNOTSUPP;
2213+
}
2214+
22102215
if (WARN_ON(!msgs || num < 1))
22112216
return -EINVAL;
22122217

@@ -2273,11 +2278,6 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
22732278
{
22742279
int ret;
22752280

2276-
if (!adap->algo->master_xfer) {
2277-
dev_dbg(&adap->dev, "I2C level transfers not supported\n");
2278-
return -EOPNOTSUPP;
2279-
}
2280-
22812281
/* REVISIT the fault reporting model here is weak:
22822282
*
22832283
* - When we get an error after receiving N bytes from a slave,

0 commit comments

Comments
 (0)