Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

jz4740-battery: Protect against concurrent battery readings

We can not handle more then one ADC request at a time to the battery.
The patch adds a mutex around the ADC read code to ensure this.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: stable@kernel.org
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>

authored by

Lars-Peter Clausen and committed by
Anton Vorontsov
8ec98fe0 86af9503

+7
+7
drivers/power/jz4740-battery.c
··· 47 47 48 48 struct power_supply battery; 49 49 struct delayed_work work; 50 + 51 + struct mutex lock; 50 52 }; 51 53 52 54 static inline struct jz_battery *psy_to_jz_battery(struct power_supply *psy) ··· 69 67 unsigned long t; 70 68 unsigned long val; 71 69 long voltage; 70 + 71 + mutex_lock(&battery->lock); 72 72 73 73 INIT_COMPLETION(battery->read_completion); 74 74 ··· 94 90 95 91 battery->cell->disable(battery->pdev); 96 92 disable_irq(battery->irq); 93 + 94 + mutex_unlock(&battery->lock); 97 95 98 96 return voltage; 99 97 } ··· 297 291 jz_battery->pdev = pdev; 298 292 299 293 init_completion(&jz_battery->read_completion); 294 + mutex_init(&jz_battery->lock); 300 295 301 296 INIT_DELAYED_WORK(&jz_battery->work, jz_battery_work); 302 297