From: Axel Lin Date: Thu, 16 May 2013 09:31:00 +0000 (+0800) Subject: pm2301_charger: Fix NULL pointer dereference X-Git-Tag: firefly_0821_release~176^2~5739^2~15 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=df311333a8c13f3ffe2537a4ff507887208cb863;p=firefly-linux-kernel-4.4.55.git pm2301_charger: Fix NULL pointer dereference Add checking pl_data in probe, this prevent possible NULL pointer dereference. Also fix NULL pointer deference in dev_err when allocate memory for pm2 fails. Signed-off-by: Axel Lin Acked-by: Linus Walleij Signed-off-by: Anton Vorontsov --- diff --git a/drivers/power/pm2301_charger.c b/drivers/power/pm2301_charger.c index fef56e2041b3..bb346becd7b4 100644 --- a/drivers/power/pm2301_charger.c +++ b/drivers/power/pm2301_charger.c @@ -1007,9 +1007,14 @@ static int pm2xxx_wall_charger_probe(struct i2c_client *i2c_client, u8 val; int i; + if (!pl_data) { + dev_err(&i2c_client->dev, "No platform data supplied\n"); + return -EINVAL; + } + pm2 = kzalloc(sizeof(struct pm2xxx_charger), GFP_KERNEL); if (!pm2) { - dev_err(pm2->dev, "pm2xxx_charger allocation failed\n"); + dev_err(&i2c_client->dev, "pm2xxx_charger allocation failed\n"); return -ENOMEM; }