linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: fix a potential NULL pointer dereference
@ 2019-03-09  6:04 Kangjie Lu
  2019-03-10 20:27 ` Jacek Anaszewski
  0 siblings, 1 reply; 8+ messages in thread
From: Kangjie Lu @ 2019-03-09  6:04 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Riku Voipio, Jacek Anaszewski, Pavel Machek,
	linux-leds, linux-kernel

In case of_match_device cannot find a match, the fixes returns
-EINVAL to avoid NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/leds/leds-pca9532.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index 7fea18b0c15d..4b0335591728 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -513,6 +513,7 @@ static int pca9532_probe(struct i2c_client *client,
 	const struct i2c_device_id *id)
 {
 	int devid;
+	const struct of_device_id *of_id;
 	struct pca9532_data *data = i2c_get_clientdata(client);
 	struct pca9532_platform_data *pca9532_pdata =
 			dev_get_platdata(&client->dev);
@@ -528,8 +529,11 @@ static int pca9532_probe(struct i2c_client *client,
 			dev_err(&client->dev, "no platform data\n");
 			return -EINVAL;
 		}
-		devid = (int)(uintptr_t)of_match_device(
-			of_pca9532_leds_match, &client->dev)->data;
+		of_id = of_match_device(of_pca9532_leds_match,
+				&client->dev);
+		if (unlikely(!of_id))
+			return -EINVAL;
+		devid = (int)of_id->data;
 	} else {
 		devid = id->driver_data;
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-04-02 18:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-09  6:04 [PATCH] leds: fix a potential NULL pointer dereference Kangjie Lu
2019-03-10 20:27 ` Jacek Anaszewski
2019-03-11 10:09   ` Enrico Weigelt, metux IT consult
2019-03-31  9:06   ` Geert Uytterhoeven
2019-03-31 10:52     ` Jacek Anaszewski
2019-03-31 11:01     ` Jacek Anaszewski
2019-04-01  7:08       ` Geert Uytterhoeven
2019-04-02 18:48         ` Jacek Anaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).