]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
power: supply: bq2415x: check for NULL acpi_id to avoid null pointer dereference
authorColin Ian King <colin.king@canonical.com>
Fri, 20 Jan 2017 13:25:06 +0000 (13:25 +0000)
committerSebastian Reichel <sre@kernel.org>
Sat, 21 Jan 2017 02:35:07 +0000 (03:35 +0100)
acpi_match_device can potentially return NULL, so it is prudent to
check if acpi_id is null before it is dereferenced.  Add a check
and an error message to indicate the failure.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
drivers/power/supply/bq2415x_charger.c

index 73e2f0b79dd4f9c67c8c4f70a5d596f46bfe4cb7..c4770a94cc8e66a744e5ea4639873e2249e32d5e 100644 (file)
@@ -1569,6 +1569,11 @@ static int bq2415x_probe(struct i2c_client *client,
                acpi_id =
                        acpi_match_device(client->dev.driver->acpi_match_table,
                                          &client->dev);
+               if (!acpi_id) {
+                       dev_err(&client->dev, "failed to match device name\n");
+                       ret = -ENODEV;
+                       goto error_1;
+               }
                name = kasprintf(GFP_KERNEL, "%s-%d", acpi_id->id, num);
        }
        if (!name) {