Skip to content

Commit

Permalink
power_supply: ipaq_micro_battery: Check return values in probe
Browse files Browse the repository at this point in the history
The return values of create_singlethread_workqueue() and
power_supply_register() calls were not checked and even on error probe()
function returned 0.

1. If allocation of workqueue failed (returning NULL) then further
   accesses could lead to NULL pointer dereference. The
   queue_delayed_work() expects workqueue to be non-NULL.

2. If registration of power supply failed then during unbind the driver
   tried to unregister power supply which was not actually registered.
   This could lead to memory corruption because
   power_supply_unregister() unconditionally cleans up given power
   supply.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Fixes: 00a588f ("power: add driver for battery reading on iPaq h3xxx")
Cc: <stable@vger.kernel.org>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
  • Loading branch information
Krzysztof Kozlowski authored and Sebastian Reichel committed Feb 25, 2015
1 parent f852ec4 commit a2c1d53
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions drivers/power/ipaq_micro_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,38 @@ static struct power_supply micro_ac_power = {
static int micro_batt_probe(struct platform_device *pdev)
{
struct micro_battery *mb;
int ret;

mb = devm_kzalloc(&pdev->dev, sizeof(*mb), GFP_KERNEL);
if (!mb)
return -ENOMEM;

mb->micro = dev_get_drvdata(pdev->dev.parent);
mb->wq = create_singlethread_workqueue("ipaq-battery-wq");
if (!mb->wq)
return -ENOMEM;

INIT_DELAYED_WORK(&mb->update, micro_battery_work);
platform_set_drvdata(pdev, mb);
queue_delayed_work(mb->wq, &mb->update, 1);
power_supply_register(&pdev->dev, &micro_batt_power);
power_supply_register(&pdev->dev, &micro_ac_power);

ret = power_supply_register(&pdev->dev, &micro_batt_power);
if (ret < 0)
goto batt_err;

ret = power_supply_register(&pdev->dev, &micro_ac_power);
if (ret < 0)
goto ac_err;

dev_info(&pdev->dev, "iPAQ micro battery driver\n");
return 0;

ac_err:
power_supply_unregister(&micro_ac_power);
batt_err:
cancel_delayed_work_sync(&mb->update);
destroy_workqueue(mb->wq);
return ret;
}

static int micro_batt_remove(struct platform_device *pdev)
Expand Down

0 comments on commit a2c1d53

Please sign in to comment.