[PATCH] mfd: add null check before pointer dereference

From: Gustavo A. R. Silva
Date: Wed May 24 2017 - 04:38:38 EST


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

Addresses-Coverity-ID: 1408830
Cc: Charles Keepax <ckeepax@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Gustavo A. R. Silva <garsilva@xxxxxxxxxxxxxx>
---
drivers/mfd/wm831x-spi.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c
index c332e28..7b227c9 100644
--- a/drivers/mfd/wm831x-spi.c
+++ b/drivers/mfd/wm831x-spi.c
@@ -34,6 +34,10 @@ static int wm831x_spi_probe(struct spi_device *spi)

if (spi->dev.of_node) {
of_id = of_match_device(wm831x_of_match, &spi->dev);
+ if (!of_id) {
+ dev_err(&spi->dev, "Failed to find matching id\n");
+ return -EINVAL;
+ }
type = (enum wm831x_parent)of_id->data;
} else {
type = (enum wm831x_parent)id->driver_data;
--
2.5.0