Skip to content

Commit 8653be1

Browse files
Ilya YanokSamuel Ortiz
Ilya Yanok
authored and
Samuel Ortiz
committed
mfd: Fix twl-core oops while calling twl_i2c_* for unbound driver
Check inuse variable before trying to access twl_map to prevent dereferencing of uninitialized variable. Signed-off-by: Ilya Yanok <[email protected]> Cc: [email protected] Signed-off-by: Samuel Ortiz <[email protected]>
1 parent 858a630 commit 8653be1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/mfd/twl-core.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,13 @@ int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
363363
pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
364364
return -EPERM;
365365
}
366-
sid = twl_map[mod_no].sid;
367-
twl = &twl_modules[sid];
368-
369366
if (unlikely(!inuse)) {
370-
pr_err("%s: client %d is not initialized\n", DRIVER_NAME, sid);
367+
pr_err("%s: not initialized\n", DRIVER_NAME);
371368
return -EPERM;
372369
}
370+
sid = twl_map[mod_no].sid;
371+
twl = &twl_modules[sid];
372+
373373
mutex_lock(&twl->xfer_lock);
374374
/*
375375
* [MSG1]: fill the register address data
@@ -420,13 +420,13 @@ int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
420420
pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
421421
return -EPERM;
422422
}
423-
sid = twl_map[mod_no].sid;
424-
twl = &twl_modules[sid];
425-
426423
if (unlikely(!inuse)) {
427-
pr_err("%s: client %d is not initialized\n", DRIVER_NAME, sid);
424+
pr_err("%s: not initialized\n", DRIVER_NAME);
428425
return -EPERM;
429426
}
427+
sid = twl_map[mod_no].sid;
428+
twl = &twl_modules[sid];
429+
430430
mutex_lock(&twl->xfer_lock);
431431
/* [MSG1] fill the register address data */
432432
msg = &twl->xfer_msg[0];

0 commit comments

Comments
 (0)