of_match_device can return NULL if no matching device is found. The patches
avoids a scenario causing null pointer dereference.

Signed-off-by: Aditya Pakki <pakki...@umn.edu>
---
 drivers/mfd/mc13xxx-i2c.c | 2 ++
 drivers/mfd/mc13xxx-spi.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/mfd/mc13xxx-i2c.c b/drivers/mfd/mc13xxx-i2c.c
index 67e4c9aa7d18..1fbc9713bb9a 100644
--- a/drivers/mfd/mc13xxx-i2c.c
+++ b/drivers/mfd/mc13xxx-i2c.c
@@ -80,6 +80,8 @@ static int mc13xxx_i2c_probe(struct i2c_client *client,
        if (client->dev.of_node) {
                const struct of_device_id *of_id =
                        of_match_device(mc13xxx_dt_ids, &client->dev);
+               if (!of_id)
+                       return -ENODEV;
                mc13xxx->variant = of_id->data;
        } else {
                mc13xxx->variant = (void *)id->driver_data;
diff --git a/drivers/mfd/mc13xxx-spi.c b/drivers/mfd/mc13xxx-spi.c
index ee3411cc5ce4..c044a02bdb64 100644
--- a/drivers/mfd/mc13xxx-spi.c
+++ b/drivers/mfd/mc13xxx-spi.c
@@ -158,6 +158,8 @@ static int mc13xxx_spi_probe(struct spi_device *spi)
        if (spi->dev.of_node) {
                const struct of_device_id *of_id =
                        of_match_device(mc13xxx_dt_ids, &spi->dev);
+               if (!of_id)
+                       return -ENODEV;
 
                mc13xxx->variant = of_id->data;
        } else {
-- 
2.17.1

Reply via email to