1 From 2d435d52c63e4dd544938bad638ecd518cc04d1c Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Tue, 26 Oct 2010 20:13:40 +0200
4 Subject: [PATCH] POWER: jz4740-battery: Protect against concurrent battery readings
6 We can not handle more then one ADC request at a time to the battery. The patch
7 adds a mutex around the ADC read code to ensure this.
9 Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
11 jz4740-battery: Add missing kfree(jz_battery) in jz_battery_remove()
13 Signed-off-by: Axel Lin <axel.lin@gmail.com>
14 Acked-By: Lars-Peter Clausen <lars@metafoo.de>
15 Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
17 drivers/power/jz4740-battery.c | 8 ++++++++
18 1 files changed, 8 insertions(+), 0 deletions(-)
20 --- a/drivers/power/jz4740-battery.c
21 +++ b/drivers/power/jz4740-battery.c
22 @@ -47,6 +47,8 @@ struct jz_battery {
24 struct power_supply battery;
25 struct delayed_work work;
30 static inline struct jz_battery *psy_to_jz_battery(struct power_supply *psy)
31 @@ -68,6 +70,8 @@ static long jz_battery_read_voltage(stru
35 + mutex_lock(&battery->lock);
37 INIT_COMPLETION(battery->read_completion);
39 enable_irq(battery->irq);
40 @@ -91,6 +95,8 @@ static long jz_battery_read_voltage(stru
41 battery->cell->disable(battery->pdev);
42 disable_irq(battery->irq);
44 + mutex_unlock(&battery->lock);
49 @@ -291,6 +297,7 @@ static int __devinit jz_battery_probe(st
50 jz_battery->pdev = pdev;
52 init_completion(&jz_battery->read_completion);
53 + mutex_init(&jz_battery->lock);
55 INIT_DELAYED_WORK(&jz_battery->work, jz_battery_work);
57 @@ -383,6 +390,7 @@ static int __devexit jz_battery_remove(s
59 iounmap(jz_battery->base);
60 release_mem_region(jz_battery->mem->start, resource_size(jz_battery->mem));