Commit 5c34c0a
power: supply: bq27xxx: Fix bq27xxx_battery_update() race condition
bq27xxx_battery_update() assumes / requires that it is only run once,
not multiple times at the same time. But there are 3 possible callers:
1. bq27xxx_battery_poll() delayed_work item handler
2. bq27xxx_battery_irq_handler_thread() I2C IRQ handler
3. bq27xxx_battery_setup()
And there is no protection against these racing with each other,
fix this race condition by making all callers take di->lock:
- Rename bq27xxx_battery_update() to bq27xxx_battery_update_unlocked()
- Add new bq27xxx_battery_update() which takes di->lock and then calls
bq27xxx_battery_update_unlocked()
- Make stale cache check code in bq27xxx_battery_get_property(), which
already takes di->lock directly to check the jiffies, call
bq27xxx_battery_update_unlocked() instead of messing with
the delayed_work item
- Make bq27xxx_battery_update_unlocked() mod the delayed-work item
so that the next poll is delayed to poll_interval milliseconds after
the last update independent of the source of the update
Fixes: 740b755 ("bq27x00: Poll battery state")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>1 parent e448464 commit 5c34c0a
1 file changed
Lines changed: 13 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1761 | 1761 | | |
1762 | 1762 | | |
1763 | 1763 | | |
1764 | | - | |
| 1764 | + | |
1765 | 1765 | | |
1766 | 1766 | | |
1767 | 1767 | | |
| |||
1800 | 1800 | | |
1801 | 1801 | | |
1802 | 1802 | | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
1803 | 1813 | | |
1804 | 1814 | | |
1805 | 1815 | | |
| |||
1810 | 1820 | | |
1811 | 1821 | | |
1812 | 1822 | | |
1813 | | - | |
1814 | | - | |
1815 | | - | |
1816 | 1823 | | |
1817 | 1824 | | |
1818 | 1825 | | |
| |||
1985 | 1992 | | |
1986 | 1993 | | |
1987 | 1994 | | |
1988 | | - | |
1989 | | - | |
1990 | | - | |
1991 | | - | |
| 1995 | + | |
| 1996 | + | |
1992 | 1997 | | |
1993 | 1998 | | |
1994 | 1999 | | |
| |||
0 commit comments