Skip to content

Commit

Permalink
leds: pca9532: fix a potential NULL pointer dereference
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
kengiter authored and jacek-anaszewski committed Mar 30, 2019
1 parent 4cb6560 commit 0aab8e4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/leds/leds-pca9532.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)(uintptr_t) of_id->data;
} else {
devid = id->driver_data;
}
Expand Down

0 comments on commit 0aab8e4

Please sign in to comment.