Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2663959a authored by Kangjie Lu's avatar Kangjie Lu Committed by Greg Kroah-Hartman
Browse files

leds: pca9532: fix a potential NULL pointer dereference



[ Upstream commit 0aab8e4df4702b31314a27ec4b0631dfad0fae0a ]

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

Fixes: fa4191a6 ("leds: pca9532: Add device tree support")
Signed-off-by: default avatarKangjie Lu <kjlu@umn.edu>
Signed-off-by: default avatarJacek Anaszewski <jacek.anaszewski@gmail.com>
Signed-off-by: default avatarSasha Levin (Microsoft) <sashal@kernel.org>
parent 13a6a6dd
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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)(uintptr_t) of_id->data;
	} else {
		devid = id->driver_data;
	}