Skip to content

Commit 0aab8e4

Browse files
kengiterjacek-anaszewski
authored andcommitted
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: fa4191a ("leds: pca9532: Add device tree support") Signed-off-by: Kangjie Lu <kjlu@umn.edu> Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
1 parent 4cb6560 commit 0aab8e4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/leds/leds-pca9532.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ static int pca9532_probe(struct i2c_client *client,
513513
const struct i2c_device_id *id)
514514
{
515515
int devid;
516+
const struct of_device_id *of_id;
516517
struct pca9532_data *data = i2c_get_clientdata(client);
517518
struct pca9532_platform_data *pca9532_pdata =
518519
dev_get_platdata(&client->dev);
@@ -528,8 +529,11 @@ static int pca9532_probe(struct i2c_client *client,
528529
dev_err(&client->dev, "no platform data\n");
529530
return -EINVAL;
530531
}
531-
devid = (int)(uintptr_t)of_match_device(
532-
of_pca9532_leds_match, &client->dev)->data;
532+
of_id = of_match_device(of_pca9532_leds_match,
533+
&client->dev);
534+
if (unlikely(!of_id))
535+
return -EINVAL;
536+
devid = (int)(uintptr_t) of_id->data;
533537
} else {
534538
devid = id->driver_data;
535539
}

0 commit comments

Comments
 (0)