Skip to contentSkip to conversation

mfd: menelaus: remove null pointer dereference

PATCH Applied Himangi Saraogi 2 participants 2 messages Aug 9, 2014 – Aug 21, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mfd: menelaus: remove null pointer dereference

If vtg is NULL, it is not possible to access its mode_reg field. At all sites where the static function menelaus_set_voltage is called, the first argument is the address of a structure defined in the file. So, the null test is unnecessary and is removed. Also, a label is done away with.

This problem was found using the following Coccinelle semantic match:

// <smpl>
@@
expression E, E1;
identifier f;
statement S1,S2,S3;
@@

* if (E == NULL)
{
... when != if (E == NULL) S1 else S2

      when != E = E1

* E->f
... when any
return ...;
}
else S3
// </smpl>

---
Not compile tested.

 drivers/mfd/menelaus.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/mfd/menelaus.c +0 -3
index 5e2667a..18ff56f 100644
@@ -466,8 +466,6 @@ static int menelaus_set_voltage(const struct menelaus_vtg *vtg, int mV,
 	struct i2c_client *c = the_menelaus->client;
 
 	mutex_lock(&the_menelaus->lock);
-	if (!vtg)
-		goto set_voltage;
 
 	ret = menelaus_read_reg(vtg->vtg_reg);
 	if (ret < 0)
@@ -482,7 +480,6 @@ static int menelaus_set_voltage(const struct menelaus_vtg *vtg, int mV,
 	ret = menelaus_write_reg(vtg->vtg_reg, val);
 	if (ret < 0)
 		goto out;
-set_voltage:
 	ret = menelaus_write_reg(vtg->mode_reg, mode);
 out:
 	mutex_unlock(&the_menelaus->lock);
Signature · 1 line
1.9.1
Applied
#1 lore raw
Quoted 25 lines · Himangi Saraogi

If vtg is NULL, it is not possible to access its mode_reg field. At all sites where the static function menelaus_set_voltage is called, the first argument is the address of a structure defined in the file. So, the null test is unnecessary and is removed. Also, a label is done away with.

This problem was found using the following Coccinelle semantic match:

// <smpl>
@@
expression E, E1;
identifier f;
statement S1,S2,S3;
@@

* if (E == NULL)
{
... when != if (E == NULL) S1 else S2

      when != E = E1

* E->f
... when any
return ...;
}
else S3
// </smpl>

Quoted 6 lines

---
Not compile tested.

 drivers/mfd/menelaus.c | 3 ---
 1 file changed, 3 deletions(-)

Applied, thanks.

Quoted 21 lines
drivers/mfd/menelaus.c +0 -3
index 5e2667a..18ff56f 100644
@@ -466,8 +466,6 @@ static int menelaus_set_voltage(const struct menelaus_vtg *vtg, int mV,
 	struct i2c_client *c = the_menelaus->client;
 
 	mutex_lock(&the_menelaus->lock);
-	if (!vtg)
-		goto set_voltage;
 
 	ret = menelaus_read_reg(vtg->vtg_reg);
 	if (ret < 0)
@@ -482,7 +480,6 @@ static int menelaus_set_voltage(const struct menelaus_vtg *vtg, int mV,
 	ret = menelaus_write_reg(vtg->vtg_reg, val);
 	if (ret < 0)
 		goto out;
-set_voltage:
 	ret = menelaus_write_reg(vtg->mode_reg, mode);
 out:
 	mutex_unlock(&the_menelaus->lock);
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog