aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKangjie Lu <kjlu@umn.edu>2019-03-09 01:04:11 -0500
committerJacek Anaszewski <jacek.anaszewski@gmail.com>2019-03-30 13:50:00 -0400
commit0aab8e4df4702b31314a27ec4b0631dfad0fae0a (patch)
treeb6c1a7919caf3c642e674ec56ae2b1f85bdb6566
parent4cb6560514fa19d556954b88128f3846fee66a03 (diff)
leds: pca9532: fix a potential NULL pointer dereference
In case of_match_device cannot find a match, return -EINVAL to avoid NULL pointer dereference. Fixes: fa4191a609f2 ("leds: pca9532: Add device tree support") Signed-off-by: Kangjie Lu <kjlu@umn.edu> Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
-rw-r--r--drivers/leds/leds-pca9532.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index 7fea18b0c15d..7cb4d685a1f1 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,
513 const struct i2c_device_id *id) 513 const struct i2c_device_id *id)
514{ 514{
515 int devid; 515 int devid;
516 const struct of_device_id *of_id;
516 struct pca9532_data *data = i2c_get_clientdata(client); 517 struct pca9532_data *data = i2c_get_clientdata(client);
517 struct pca9532_platform_data *pca9532_pdata = 518 struct pca9532_platform_data *pca9532_pdata =
518 dev_get_platdata(&client->dev); 519 dev_get_platdata(&client->dev);
@@ -528,8 +529,11 @@ static int pca9532_probe(struct i2c_client *client,
528 dev_err(&client->dev, "no platform data\n"); 529 dev_err(&client->dev, "no platform data\n");
529 return -EINVAL; 530 return -EINVAL;
530 } 531 }
531 devid = (int)(uintptr_t)of_match_device( 532 of_id = of_match_device(of_pca9532_leds_match,
532 of_pca9532_leds_match, &client->dev)->data; 533 &client->dev);
534 if (unlikely(!of_id))
535 return -EINVAL;
536 devid = (int)(uintptr_t) of_id->data;
533 } else { 537 } else {
534 devid = id->driver_data; 538 devid = id->driver_data;
535 } 539 }