linux/drivers/power/supply
Hans de Goede 5c34c0aef1 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: 740b755a3b ("bq27x00: Poll battery state")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2023-05-08 15:29:11 +02:00
..
88pm860x_battery.c
88pm860x_charger.c power: supply: 88pm860x: simplify using devm 2022-11-17 23:47:23 +01:00
ab8500_bmdata.c power: supply: ab8500: Standardize BTI resistance 2022-02-28 11:34:31 +01:00
ab8500_btemp.c power: supply: ab8500: Fix external_power_changed race 2023-05-08 15:03:50 +02:00
ab8500_chargalg.c power: supply: ab8500: remove unused static local variable 2022-10-05 23:47:04 +02:00
ab8500_charger.c power: supply: ab8500: Fix error handling in ab8500_charger_init() 2022-11-26 23:14:32 +01:00
ab8500_fg.c power: supply: ab8500: Fix external_power_changed race 2023-05-08 15:03:50 +02:00
ab8500-bm.h power: supply: ab8500: Standardize BTI resistance 2022-02-28 11:34:31 +01:00
ab8500-chargalg.h power: supply: ab8500: Drop external charger leftovers 2022-07-17 00:51:35 +02:00
acer_a500_battery.c
act8945a_charger.c
adp5061.c power: supply: adp5061: Convert to i2c's .probe_new() 2022-11-20 20:12:16 +01:00
apm_power.c
axp20x_ac_power.c power: supply: axp20x_ac_power: fix platform_get_irq.cocci warning 2022-03-04 22:20:32 +01:00
axp20x_battery.c power: supply: axp20x_battery: properly report current when discharging 2022-02-01 11:18:47 +01:00
axp20x_usb_power.c power: supply: axp20x_usb_power: fix platform_get_irq.cocci warnings 2022-03-04 22:20:32 +01:00
axp288_charger.c power: supply: axp288_charger: Use alt usb-id extcon on some x86 android tablets 2023-04-01 23:01:42 +02:00
axp288_fuel_gauge.c power: supply: axp288_fuel_gauge: Fix external_power_changed race 2023-05-08 15:04:53 +02:00
bd99954-charger.c power: supply: bd99954: Use LINEAR_RANGE() 2022-11-01 01:01:50 +01:00
bd99954-charger.h
bq27xxx_battery_hdq.c
bq27xxx_battery_i2c.c power: supply: bq27xxx: Convert to i2c's .probe_new() 2022-11-20 20:12:16 +01:00
bq27xxx_battery.c power: supply: bq27xxx: Fix bq27xxx_battery_update() race condition 2023-05-08 15:29:11 +02:00
bq256xx_charger.c power: supply: bq256xx: Support to disable charger 2023-03-12 23:47:54 +01:00
bq2415x_charger.c power: supply: use sysfs_emit() instead of sprintf() for sysfs show() 2023-01-02 09:13:37 +01:00
bq2515x_charger.c power: supply: bq2515x: Convert to i2c's .probe_new() 2022-11-20 20:12:16 +01:00
bq24190_charger.c power: supply: bq24190: Fix use after free bug in bq24190_remove due to race condition 2023-03-10 00:35:20 +01:00
bq24257_charger.c power: supply: bq24257_charger: mark OF related data as maybe unused 2023-03-12 23:13:14 +01:00
bq24735-charger.c power: supply: bq24735: Convert to i2c's .probe_new() 2022-11-20 20:12:16 +01:00
bq25890_charger.c power: supply: bq25890: Fix external_power_changed race 2023-05-08 15:05:23 +02:00
bq25980_charger.c power: supply: bq25980: Convert to i2c's .probe_new() 2022-11-20 20:12:16 +01:00
bq25980_charger.h
charger-manager.c power: supply: charger-manager: Use of_property_read_bool() for boolean properties 2023-03-12 23:33:43 +01:00
collie_battery.c power: supply: collie_battery: Convert to GPIO descriptors (part 2) 2023-02-03 13:28:59 +01:00
cpcap-battery.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_320.RULE 2022-06-10 14:51:36 +02:00
cpcap-charger.c power: supply: cpcap-charger: fix repeated words in comments 2022-09-11 10:52:05 +02:00
cros_peripheral_charger.c power: supply: cros_peripheral: Use struct_size() helper in kzalloc() 2022-06-09 22:03:27 +02:00
cros_usbpd-charger.c power: supply: cros_usbpd: reclassify "default case!" as debug 2023-03-10 00:20:43 +01:00
cw2015_battery.c power: supply: cw2015: Fix potential null-ptr-deref in cw_bat_probe() 2022-11-24 23:00:00 +01:00
da9030_battery.c
da9052-battery.c
da9150-charger.c power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition 2023-03-12 23:28:04 +01:00
da9150-fg.c power: supply: da9150-fg: Remove unnecessary print function dev_err() 2022-03-04 22:20:33 +01:00
ds2760_battery.c ARM: pxa: remove unused board files 2023-01-20 11:23:44 +01:00
ds2780_battery.c power: supply: use sysfs_emit() instead of sprintf() for sysfs show() 2023-01-02 09:13:37 +01:00
ds2781_battery.c power: supply: use sysfs_emit() instead of sprintf() for sysfs show() 2023-01-02 09:13:37 +01:00
ds2782_battery.c power: supply: ds2782: Convert to i2c's .probe_new() 2022-11-20 20:12:16 +01:00
generic-adc-battery.c power: supply: generic-adc-battery: style fixes 2023-03-29 22:38:57 +02:00
goldfish_battery.c power: supply: Remove unnecessary print function dev_err() 2022-06-09 20:27:21 +02:00
gpio-charger.c
ingenic-battery.c power: supply_core: Pass pointer to battery info 2022-01-03 18:53:10 +01:00
ip5xxx_power.c power: supply: ip5xxx: Fix integer overflow in current_now calculation 2022-11-01 00:02:36 +01:00
ipaq_micro_battery.c
isp1704_charger.c
Kconfig ARM: SoC drivers for 6.3 2023-02-27 10:04:49 -08:00
lego_ev3_battery.c
lp8727_charger.c power: supply: lp8727_charger: mark OF related data as maybe unused 2023-03-12 23:13:14 +01:00
lp8788-charger.c power: supply: use sysfs_emit() instead of scnprintf() for sysfs show() 2023-01-02 08:54:07 +01:00
lt3651-charger.c
ltc2941-battery-gauge.c power: supply: ltc2941: Convert to i2c's .probe_new() 2022-11-20 20:12:16 +01:00
ltc4162-l-charger.c power: supply: ltc4162-l-charger: mark OF related data as maybe unused 2023-03-12 23:13:14 +01:00
Makefile ARM: SoC drivers for 6.3 2023-02-27 10:04:49 -08:00
max1721x_battery.c power: supply: max1721x: Use strscpy() is more robust and safer 2023-02-03 13:58:41 +01:00
max8903_charger.c
max8925_power.c
max8997_charger.c extcon: Fix extcon_get_extcon_dev() error handling 2022-05-13 17:03:40 +09:00
max8998_charger.c
max14577_charger.c power: supply: use sysfs_emit() instead of scnprintf() for sysfs show() 2023-01-02 08:54:07 +01:00
max14656_charger_detector.c power: supply: max14656: Convert to i2c's .probe_new() 2022-11-20 20:12:16 +01:00
max17040_battery.c power: supply: max17040: Convert to i2c's .probe_new() 2022-11-20 20:12:16 +01:00
max17042_battery.c power: supply: max17042_battery: Convert to i2c's .probe_new() 2022-11-20 20:12:16 +01:00
max77650-charger.c power: supply: max77650: Make max77650_charger_disable() return void 2023-02-13 21:20:39 +01:00
max77693_charger.c power: supply: use sysfs_emit() instead of scnprintf() for sysfs show() 2023-01-02 08:54:07 +01:00
max77976_charger.c power: supply: max77976: update Luca Ceresoli's e-mail address 2022-06-09 19:27:14 +02:00
mp2629_charger.c power: supply: use sysfs_emit() instead of sprintf() for sysfs show() 2023-01-02 09:13:37 +01:00
mt6360_charger.c power: supply: mt6360: Use LINEAR_RANGE_IDX() 2022-11-01 01:01:50 +01:00
mt6370-charger.c power: supply: mt6370: Fix return value check in mt6370_chg_probe() 2022-10-01 22:17:45 +02:00
olpc_battery.c power: supply: use sysfs_emit() instead of sprintf() for sysfs show() 2023-01-02 09:13:37 +01:00
pcf50633-charger.c power: supply: use sysfs_emit() instead of sprintf() for sysfs show() 2023-01-02 09:13:37 +01:00
pmu_battery.c
power_supply_core.c power supply and reset changes for the v6.4 series 2023-04-29 17:37:02 -07:00
power_supply_hwmon.c power: supply: core: Simplify hwmon memory allocation 2022-02-11 19:45:52 +01:00
power_supply_leds.c power: supply: leds: Fix blink to LED on transition 2023-05-08 15:13:19 +02:00
power_supply_sysfs.c power: supply: core: auto-exposure of simple-battery data 2023-03-29 22:38:56 +02:00
power_supply.h driver core: make struct class.dev_uevent() take a const * 2022-11-24 17:12:15 +01:00
qcom_battmgr.c power: supply: qcom_battmgr: remove bogus do_div() 2023-03-01 10:41:18 -08:00
qcom_smbb.c power: supply: qcom_smbb: support pm8226 2021-11-30 11:34:27 +01:00
rk817_charger.c power: supply: rk817: Fix low SOC bugs 2023-04-08 00:30:05 +02:00
rn5t618_power.c power: supply: rn5t618: Add voltage_now property 2021-08-13 18:38:17 +02:00
rt5033_battery.c power: supply: rt5033_battery: Convert to i2c's .probe_new() 2022-11-20 20:12:17 +01:00
rt9455_charger.c power: supply: rt9455_charger: mark OF related data as maybe unused 2023-03-12 23:13:14 +01:00
rt9467-charger.c power: supply: rt9467: Fix spelling mistake "attache" -> "attach" 2023-02-13 21:29:33 +01:00
rt9471.c power: supply: rt9471: fix using wrong ce_gpio in rt9471_probe() 2023-02-13 21:28:56 +01:00
rx51_battery.c
samsung-sdi-battery.c power: supply: samsung-sdi-battery: Add missing charge restart voltages 2022-04-13 12:05:22 +02:00
samsung-sdi-battery.h power: supply: Static data for Samsung batteries 2022-03-04 22:20:18 +01:00
sbs-battery.c power: supply: sbs-battery: add support for time_to_empty_now attribute 2021-08-06 23:48:51 +02:00
sbs-charger.c power: supply: sbs: Convert to i2c's .probe_new() 2022-11-20 20:12:17 +01:00
sbs-manager.c power: supply: sbs-manager: Convert to i2c's .probe_new() 2022-11-20 20:12:17 +01:00
sc27xx_fuel_gauge.c power: supply: sc27xx: Fix external_power_changed race 2023-05-08 15:06:12 +02:00
sc2731_charger.c power: supply_core: Pass pointer to battery info 2022-01-03 18:53:10 +01:00
smb347-charger.c power: supply: smb347: Convert to i2c's .probe_new() 2022-11-20 20:12:17 +01:00
surface_battery.c platform/surface: aggregator: Enforce use of target-ID enum in device ID macros 2023-02-02 22:48:20 +01:00
surface_charger.c platform/surface: aggregator: Enforce use of target-ID enum in device ID macros 2023-02-02 22:48:20 +01:00
test_power.c power: supply: test-power: use strscpy() instead of strncpy() 2023-02-03 13:43:48 +01:00
tps65090-charger.c
tps65217_charger.c power: supply: tps65217: Fix comments typo 2022-09-11 12:09:10 +02:00
twl4030_charger.c power: supply: twl4030_charger: mark OF related data as maybe unused 2023-03-12 23:13:14 +01:00
twl4030_madc_battery.c
ucs1002_power.c power: supply: ucs1002: Convert to i2c's .probe_new() 2022-11-20 20:12:17 +01:00
ug3105_battery.c power: supply: ug3105_battery: Add driver for uPI uG3105 battery monitor 2022-02-11 19:08:35 +01:00
wilco-charger.c
wm97xx_battery.c power: supply: remove MODULE_LICENSE in non-modules 2023-04-13 13:13:53 -07:00
wm831x_backup.c
wm831x_power.c power: supply: wm831x_power: fix spelling mistake on function name 2021-10-02 17:31:15 +02:00
wm8350_power.c power: supply: use sysfs_emit() instead of sprintf() for sysfs show() 2023-01-02 09:13:37 +01:00