Skip to contentSkip to conversation

mfd: fix unintentional NULL check in menelaus_set_voltage()

PATCH In review Emil Goode 3 participants 3 messages May 28, 2014 – Jun 2, 2014

Subsystems (3)
lore
Share & tools
lore

Emil Goode

author
#0 lore raw

PATCH v2 1/1 mfd: fix unintentional NULL check in menelaus_set_voltage()

The struct menelaus_vtg pointer vtg cannot be NULL here so the condition is never true and if it ever was true it would lead to a NULL pointer dereference when we goto label set_voltage.

Before the below patch was applied the code was:

if (vtg == 0)

The intention was to check if vtg_val is 0.

commit 59a9f7a32adf6537b4e4db8ca204eeb77d7a634e
("mfd: menelaus: Use NULL instead of 0")

---
v2: Changed (vtg_val == 0) to (!vtg_val)

 drivers/mfd/menelaus.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/menelaus.c +1 -1
index ad25bfa..40df76a 100644
@@ -466,7 +466,7 @@ 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)
+	if (!vtg_val)
 		goto set_voltage;
 
 	ret = menelaus_read_reg(vtg->vtg_reg);
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 27 lines · Emil Goode

The struct menelaus_vtg pointer vtg cannot be NULL here so the condition is never true and if it ever was true it would lead to a NULL pointer dereference when we goto label set_voltage.

Before the below patch was applied the code was:

if (vtg = 0)

The intention was to check if vtg_val is 0.

commit 59a9f7a32adf6537b4e4db8ca204eeb77d7a634e
("mfd: menelaus: Use NULL instead of 0")

---
v2: Changed (vtg_val = 0) to (!vtg_val)

 drivers/mfd/menelaus.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/menelaus.c +0 -0
index ad25bfa..40df76a 100644

drivers/mfd/menelaus.c static int menelaus_set_voltage(const struct menelaus_vtg *vtg, int mV, · line 470

Quoted 6 lines
drivers/mfd/menelaus.c +1 -1
@@ -466,7 +466,7 @@ 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)
+	if (!vtg_val)
 		goto set_voltage;

(+cc Trilok Soni, Tony Lindgren)

In this case, if 'vtg_val' is 0, setting voltage as 0 for registers such as MENELAUS_xxx_CTRLx will be skipped. So, it is not possible to set the voltage value as 0.

Is it right? If not, how about just removing this check and the label 'set_voltage'?

Best regards,
Jingoo Han

Quoted 4 lines
drivers/mfd/menelaus.c +0 -1
 	ret = menelaus_read_reg(vtg->vtg_reg);
--

1.7.10.4

maintainer
#2 lore raw
Quoted 37 lines · Jingoo Han
Quoted 27 lines · Emil Goode

The struct menelaus_vtg pointer vtg cannot be NULL here so the condition is never true and if it ever was true it would lead to a NULL pointer dereference when we goto label set_voltage.

Before the below patch was applied the code was:

if (vtg = 0)

The intention was to check if vtg_val is 0.

commit 59a9f7a32adf6537b4e4db8ca204eeb77d7a634e
("mfd: menelaus: Use NULL instead of 0")

---
v2: Changed (vtg_val = 0) to (!vtg_val)

 drivers/mfd/menelaus.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/menelaus.c +0 -0
index ad25bfa..40df76a 100644

drivers/mfd/menelaus.c static int menelaus_set_voltage(const struct menelaus_vtg *vtg, int mV, · line 470

Quoted 6 lines
drivers/mfd/menelaus.c +1 -1
@@ -466,7 +466,7 @@ 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)
+	if (!vtg_val)
 		goto set_voltage;

(+cc Trilok Soni, Tony Lindgren)

Quoted 6 lines

In this case, if 'vtg_val' is 0, setting voltage as 0 for registers such as MENELAUS_xxx_CTRLx will be skipped. So, it is not possible to set the voltage value as 0.

Is it right? If not, how about just removing this check and the label 'set_voltage'?

Added Aaro and Jarkko to Cc.

Regards,

Tony

Quoted 8 lines

Best regards,
Jingoo Han

Quoted 4 lines
drivers/mfd/menelaus.c +0 -1
 	ret = menelaus_read_reg(vtg->vtg_reg);
--

1.7.10.4