From cc28e17100a6b051ef966de81bb2d4a97b2a6645 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 13 Apr 2012 10:15:49 +0200 Subject: ab8500_charger: Harden platform data check 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. Acked-by: Arun Murthy Signed-off-by: Linus Walleij Signed-off-by: Anton Vorontsov --- drivers/power/ab8500_charger.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers/power/ab8500_charger.c') diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c index e2b4accbec88..79dc584a53ed 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; -- cgit v1.2.3 From 2aac3de19b72608f474c90034185c2be4908728f Mon Sep 17 00:00:00 2001 From: Lee Jones Date: Sat, 5 May 2012 04:38:19 -0700 Subject: ab8500: Clean up probe routines These patches clean up some ugliness and brings the variable initialisation formatting more into line with other drivers. Signed-off-by: Lee Jones Signed-off-by: Anton Vorontsov --- drivers/power/ab8500_btemp.c | 16 ++++++++++------ drivers/power/ab8500_charger.c | 16 ++++++++++------ drivers/power/ab8500_fg.c | 16 ++++++++++------ 3 files changed, 30 insertions(+), 18 deletions(-) (limited to 'drivers/power/ab8500_charger.c') diff --git a/drivers/power/ab8500_btemp.c b/drivers/power/ab8500_btemp.c index e266f038a110..bba3ccac72fe 100644 --- a/drivers/power/ab8500_btemp.c +++ b/drivers/power/ab8500_btemp.c @@ -964,10 +964,15 @@ static int __devinit ab8500_btemp_probe(struct platform_device *pdev) { int irq, i, ret = 0; u8 val; - struct abx500_bm_plat_data *plat_data; + struct abx500_bm_plat_data *plat_data = pdev->dev.platform_data; + struct ab8500_btemp *di; + + if (!plat_data) { + dev_err(&pdev->dev, "No platform data\n"); + return -EINVAL; + } - struct ab8500_btemp *di = - kzalloc(sizeof(struct ab8500_btemp), GFP_KERNEL); + di = kzalloc(sizeof(*di), GFP_KERNEL); if (!di) return -ENOMEM; @@ -977,13 +982,12 @@ static int __devinit ab8500_btemp_probe(struct platform_device *pdev) di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); /* get btemp specific platform data */ - plat_data = pdev->dev.platform_data; - if (!plat_data || !plat_data->btemp) { + di->pdata = plat_data->btemp; + if (!di->pdata) { dev_err(di->dev, "no btemp platform data supplied\n"); ret = -EINVAL; goto free_device_info; } - di->pdata = plat_data->btemp; /* get battery specific platform data */ di->bat = plat_data->battery; diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c index 79dc584a53ed..d2303d0b7c75 100644 --- a/drivers/power/ab8500_charger.c +++ b/drivers/power/ab8500_charger.c @@ -2534,10 +2534,15 @@ static int __devexit ab8500_charger_remove(struct platform_device *pdev) static int __devinit ab8500_charger_probe(struct platform_device *pdev) { int irq, i, charger_status, ret = 0; - struct abx500_bm_plat_data *plat_data; + struct abx500_bm_plat_data *plat_data = pdev->dev.platform_data; + struct ab8500_charger *di; - struct ab8500_charger *di = - kzalloc(sizeof(struct ab8500_charger), GFP_KERNEL); + if (!plat_data) { + dev_err(&pdev->dev, "No platform data\n"); + return -EINVAL; + } + + di = kzalloc(sizeof(*di), GFP_KERNEL); if (!di) return -ENOMEM; @@ -2550,13 +2555,12 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev) spin_lock_init(&di->usb_state.usb_lock); /* get charger specific platform data */ - plat_data = pdev->dev.platform_data; - if (!plat_data || !plat_data->charger) { + di->pdata = plat_data->charger; + if (!di->pdata) { 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; diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c index 0ebea39e73fe..bf022255994c 100644 --- a/drivers/power/ab8500_fg.c +++ b/drivers/power/ab8500_fg.c @@ -2446,10 +2446,15 @@ static int __devinit ab8500_fg_probe(struct platform_device *pdev) { int i, irq; int ret = 0; - struct abx500_bm_plat_data *plat_data; + struct abx500_bm_plat_data *plat_data = pdev->dev.platform_data; + struct ab8500_fg *di; + + if (!plat_data) { + dev_err(&pdev->dev, "No platform data\n"); + return -EINVAL; + } - struct ab8500_fg *di = - kzalloc(sizeof(struct ab8500_fg), GFP_KERNEL); + di = kzalloc(sizeof(*di), GFP_KERNEL); if (!di) return -ENOMEM; @@ -2461,13 +2466,12 @@ static int __devinit ab8500_fg_probe(struct platform_device *pdev) di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); /* get fg specific platform data */ - plat_data = pdev->dev.platform_data; - if (!plat_data || !plat_data->fg) { + di->pdata = plat_data->fg; + if (!di->pdata) { dev_err(di->dev, "no fg platform data supplied\n"); ret = -EINVAL; goto free_device_info; } - di->pdata = plat_data->fg; /* get battery specific platform data */ di->bat = plat_data->battery; -- cgit v1.2.3