Skip to contentSkip to conversation

mfd: fix unintentional NULL check in menelaus_set_voltage()

PATCH Superseded Emil Goode 2 participants 3 messages May 28, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Emil Goode

author
#0 lore raw

PATCH 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")

---
Hello,

This is only build tested, it would be good to get a comment from someone who is familiar with this code.

Found using coccinelle.

Best regards,

Emil Goode

 drivers/mfd/menelaus.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/menelaus.c +1 -1
index ad25bfa..4859597 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 == 0)
 		goto set_voltage;
 
 	ret = menelaus_read_reg(vtg->vtg_reg);
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 35 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")

---
Hello,

This is only build tested, it would be good to get a comment from someone who is familiar with this code.

Found using coccinelle.

Best regards,

Emil Goode

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

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

Quoted 5 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 = 0)

I would prefer:

if (!vtg_val)

Quoted 3 lines
drivers/mfd/menelaus.c +0 -0
 		goto set_voltage;
 
 	ret = menelaus_read_reg(vtg->vtg_reg);
Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#2 lore raw

Hello,

Quoted 39 lines · Lee Jones
Quoted 37 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")

---
Hello,

This is only build tested, it would be good to get a comment from someone who is familiar with this code.

Found using coccinelle.

Best regards,

Emil Goode

 drivers/mfd/menelaus.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/menelaus.c +0 -0
index ad25bfa..4859597 100644
@@ -466,7 +466,7 @@ static int menelaus_set_voltage(const struct menelaus_vtg *vtg, int mV,
 	struct i2c_client *c = the_menelaus->client;
 
Quoted 7 lines

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

Quoted 3 lines
drivers/mfd/menelaus.c +1 -1
 	mutex_lock(&the_menelaus->lock);
-	if (!vtg)
+	if (vtg_val == 0)

I would prefer:

if (!vtg_val)

Ok, I will resend.

Best regards,

Emil Goode