[PATCH 1/3] power/ab8500_charger: harden platform data check

From: Linus Walleij
Date: Fri Apr 13 2012 - 04:16:22 EST


From: Linus Walleij <linus.walleij@xxxxxxxxxx>

If no platform data at all is supplied the driver crashes,
extend the checks to be more careful so we can compile in the
driver and boot also without platform data present.

Cc: Arun Murthy <arun.murthy@xxxxxxxxxxxxxx>
Signed-off-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
---
drivers/power/ab8500_charger.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c
index e2b4acc..79dc584 100644
--- a/drivers/power/ab8500_charger.c
+++ b/drivers/power/ab8500_charger.c
@@ -2551,13 +2551,12 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)

/* get charger specific platform data */
plat_data = pdev->dev.platform_data;
- di->pdata = plat_data->charger;
-
- if (!di->pdata) {
+ if (!plat_data || !plat_data->charger) {
dev_err(di->dev, "no charger platform data supplied\n");
ret = -EINVAL;
goto free_device_info;
}
+ di->pdata = plat_data->charger;

/* get battery specific platform data */
di->bat = plat_data->battery;
--
1.7.9.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/