Skip to contentSkip to conversation

Patch "power_supply: ipaq_micro_battery: Check return values in probe" has been added to the 3.19-stable tree

PATCH [email protected] 1 participant 1 message May 2, 2015 Stable branch

lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

power_supply: ipaq_micro_battery: Check return values in probe

to the 3.19-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
power_supply-ipaq_micro_battery-check-return-values-in-probe.patch
and it can be found in the queue-3.19 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From a2c1d531854c4319610f1d83351213b47a633969 Mon Sep 17 00:00:00 2001

From: Krzysztof Kozlowski <[email protected]>
Date: Fri, 20 Feb 2015 14:32:24 +0100
Subject: power_supply: ipaq_micro_battery: Check return values in probe

From: Krzysztof Kozlowski <[email protected]>

commit a2c1d531854c4319610f1d83351213b47a633969 upstream.

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.

Fixes 00a588f9d27f ("power: add driver for battery reading on iPaq h3xxx")
---
 drivers/power/ipaq_micro_battery.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/power/ipaq_micro_battery.c +19 -2
@@ -226,6 +226,7 @@ static struct power_supply micro_ac_powe
 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)
@@ -233,14 +234,30 @@ static int micro_batt_probe(struct platf
 
 	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)

Patches currently in stable-queue which might be from [email protected] are

queue-3.19/compal-laptop-fix-leaking-hwmon-device.patch queue-3.19/compal-laptop-check-return-value-of-power_supply_register.patch queue-3.19/power_supply-twl4030_madc-check-return-value-of-power_supply_register.patch queue-3.19/power_supply-ipaq_micro_battery-fix-leaking-workqueue.patch queue-3.19/power_supply-lp8788-charger-fix-leaked-power-supply-on-probe-fail.patch queue-3.19/power_supply-ipaq_micro_battery-check-return-values-in-probe.patch