Skip to contentSkip to conversation

mfd: add null check before pointer dereference

PATCH Superseded Gustavo A. R. Silva 3 participants 4 messages May 24, 2017

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

PATCH 1/1 mfd: add null check before pointer dereference

Add NULL check before dereferencing pointer of_id in order to avoid a potential NULL pointer dereference.

Addresses-Coverity-ID: 1408829

---
 drivers/mfd/wm831x-i2c.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mfd/wm831x-i2c.c +4 -0
index 781af06..2d48f41 100644
@@ -37,6 +37,10 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,
 
 	if (i2c->dev.of_node) {
 		of_id = of_match_device(wm831x_of_match, &i2c->dev);
+		if (!of_id) {
+			dev_err(&i2c->dev, "Failed to find matching id\n");
+			return -EINVAL;
+		}
 		type = (enum wm831x_parent)of_id->data;
 	} else {
 		type = (enum wm831x_parent)id->driver_data;
Signature · 1 line
2.5.0
#2 lore raw

PATCH v2 1/1 mfd: wm831x: add null check before pointer dereference

In reply to Gustavo A. R. Silva

Add NULL check before dereferencing pointer of_id in order to avoid a potential NULL pointer dereference.

Addresses-Coverity-ID: 1408829

---
Changes in v2:
Update error log and return value.

 drivers/mfd/wm831x-i2c.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mfd/wm831x-i2c.c +4 -0
index 781af06..bed66d8 100644
@@ -37,6 +37,10 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,
 
 	if (i2c->dev.of_node) {
 		of_id = of_match_device(wm831x_of_match, &i2c->dev);
+		if (!of_id) {
+			dev_err(&i2c->dev, "Failed to match device\n");
+			return -ENODEV;
+		}
 		type = (enum wm831x_parent)of_id->data;
 	} else {
 		type = (enum wm831x_parent)id->driver_data;
Signature · 1 line
2.5.0
Applied
#3 lore raw

Re: [PATCH v2] mfd: wm831x: add null check before pointer dereference

Quoted 7 lines · Gustavo A. R. Silva

Add NULL check before dereferencing pointer of_id in order to avoid a potential NULL pointer dereference.

Addresses-Coverity-ID: 1408829

Quoted 6 lines

---
Changes in v2:
Update error log and return value.

 drivers/mfd/wm831x-i2c.c | 4 ++++
 1 file changed, 4 insertions(+)

Applied, thanks.

Quoted 15 lines
drivers/mfd/wm831x-i2c.c +4 -0
index 781af06..bed66d8 100644
@@ -37,6 +37,10 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,
 
 	if (i2c->dev.of_node) {
 		of_id = of_match_device(wm831x_of_match, &i2c->dev);
+		if (!of_id) {
+			dev_err(&i2c->dev, "Failed to match device\n");
+			return -ENODEV;
+		}
 		type = (enum wm831x_parent)of_id->data;
 	} else {
 		type = (enum wm831x_parent)id->driver_data;
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog