Skip to contentSkip to conversation

twl-core: fix oops while calling twl_i2c_* for unbound driver

PATCH In review Ilya Yanok 2 participants 3 messages Aug 1, 2011 – Nov 14, 2011

Subsystems (2)
lore
Share & tools
lore

Ilya Yanok

author
#0 lore raw

PATCH 1/1 twl-core: fix oops while calling twl_i2c_* for unbound driver

Check inuse variable before trying to access twl_map to prevent dereferencing of uninitialized variable.

---
 drivers/mfd/twl-core.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
drivers/mfd/twl-core.c +8 -8
index 01ecfee..c7bc222 100644
@@ -362,13 +362,13 @@ int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
 		pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
 		return -EPERM;
 	}
-	sid = twl_map[mod_no].sid;
-	twl = &twl_modules[sid];
-
 	if (unlikely(!inuse)) {
-		pr_err("%s: client %d is not initialized\n", DRIVER_NAME, sid);
+		pr_err("%s: not initialized\n", DRIVER_NAME);
 		return -EPERM;
 	}
+	sid = twl_map[mod_no].sid;
+	twl = &twl_modules[sid];
+
 	mutex_lock(&twl->xfer_lock);
 	/*
 	 * [MSG1]: fill the register address data
@@ -419,13 +419,13 @@ int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
 		pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
 		return -EPERM;
 	}
-	sid = twl_map[mod_no].sid;
-	twl = &twl_modules[sid];
-
 	if (unlikely(!inuse)) {
-		pr_err("%s: client %d is not initialized\n", DRIVER_NAME, sid);
+		pr_err("%s: not initialized\n", DRIVER_NAME);
 		return -EPERM;
 	}
+	sid = twl_map[mod_no].sid;
+	twl = &twl_modules[sid];
+
 	mutex_lock(&twl->xfer_lock);
 	/* [MSG1] fill the register address data */
 	msg = &twl->xfer_msg[0];
Signature · 1 line
1.7.6
author
#1 lore raw

Hi,

this is still unfixed. twl_i2c_{read,write} are exported and can be called before driver initialization so we have to check it before dereferencing twl_map.

Regards, Ilya.

Quoted 48 lines · Ilya Yanok

Check inuse variable before trying to access twl_map to prevent dereferencing of uninitialized variable.

---
  drivers/mfd/twl-core.c |   16 ++++++++--------
  1 files changed, 8 insertions(+), 8 deletions(-)
drivers/mfd/twl-core.c +8 -8
index 01ecfee..c7bc222 100644
@@ -362,13 +362,13 @@ int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
  		pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
  		return -EPERM;
  	}
-	sid = twl_map[mod_no].sid;
-	twl =&twl_modules[sid];
-
  	if (unlikely(!inuse)) {
-		pr_err("%s: client %d is not initialized\n", DRIVER_NAME, sid);
+		pr_err("%s: not initialized\n", DRIVER_NAME);
  		return -EPERM;
  	}
+	sid = twl_map[mod_no].sid;
+	twl =&twl_modules[sid];
+
  	mutex_lock(&twl->xfer_lock);
  	/*
  	 * [MSG1]: fill the register address data
@@ -419,13 +419,13 @@ int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
  		pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
  		return -EPERM;
  	}
-	sid = twl_map[mod_no].sid;
-	twl =&twl_modules[sid];
-
  	if (unlikely(!inuse)) {
-		pr_err("%s: client %d is not initialized\n", DRIVER_NAME, sid);
+		pr_err("%s: not initialized\n", DRIVER_NAME);
  		return -EPERM;
  	}
+	sid = twl_map[mod_no].sid;
+	twl =&twl_modules[sid];
+
  	mutex_lock(&twl->xfer_lock);
  	/* [MSG1] fill the register address data */
  	msg =&twl->xfer_msg[0];
#2 lore raw

Hi Ilya,

Quoted 7 lines · Ilya Yanok

Hi,

this is still unfixed. twl_i2c_{read,write} are exported and can be called before driver initialization so we have to check it before dereferencing twl_map.

Regards, Ilya.

Thanks for the fix. This one should make it to 3.2 as I applied it to my for-linux branch.

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/