power: supply: ab8500: Fix external_power_changed race
Subsystems (2)
Sasha Levin
maintainerPATCH 1/37 power: supply: ab8500: Fix external_power_changed race
From: Hans de Goede <[email protected]>
[ Upstream commit a5299ce4e96f3e8930e9c051b28d8093ada87b08 ]
ab8500_btemp_external_power_changed() dereferences di->btemp_psy, which gets sets in ab8500_btemp_probe() like this:
di->btemp_psy = devm_power_supply_register(dev, &ab8500_btemp_desc,
&psy_cfg);As soon as devm_power_supply_register() has called device_add() the external_power_changed callback can get called. So there is a window where ab8500_btemp_external_power_changed() may get called while di->btemp_psy has not been set yet leading to a NULL pointer dereference.
Fixing this is easy. The external_power_changed callback gets passed the power_supply which will eventually get stored in di->btemp_psy, so ab8500_btemp_external_power_changed() can simply directly use the passed in psy argument which is always valid.
And the same applies to ab8500_fg_external_power_changed().
--- drivers/power/supply/ab8500_btemp.c | 6 ++---- drivers/power/supply/ab8500_fg.c | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-)
drivers/power/supply/ab8500_btemp.c +2 -4
@@ -624,10 +624,8 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)*/ static void ab8500_btemp_external_power_changed (struct power_supply *psy) { -struct ab8500_btemp *di =power_supply_get_drvdata (psy); - -class_for_each_device (power_supply_class,NULL , - di->btemp_psy, ab8500_btemp_get_ext_psy_data); +class_for_each_device (power_supply_class,NULL , psy, + ab8500_btemp_get_ext_psy_data); }/* ab8500 btemp driver interrupts and their respective isr */
drivers/power/supply/ab8500_fg.c +2 -4
@@ -2407,10 +2407,8 @@ static int ab8500_fg_init_hw_registers(struct ab8500_fg *di)*/ static void ab8500_fg_external_power_changed (struct power_supply *psy) { -struct ab8500_fg *di =power_supply_get_drvdata (psy); - -class_for_each_device (power_supply_class,NULL , - di->fg_psy, ab8500_fg_get_ext_psy_data); +class_for_each_device (power_supply_class,NULL , psy, + ab8500_fg_get_ext_psy_data); }/**
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 2/37 power: supply: sc27xx: Fix external_power_changed race
From: Hans de Goede <[email protected]>
[ Upstream commit 4d5c129d6c8993fe96e9ae712141eedcb9ca68c2 ]
sc27xx_fgu_external_power_changed() dereferences data->battery, which gets sets in ab8500_btemp_probe() like this:
data->battery = devm_power_supply_register(dev, &sc27xx_fgu_desc,
&fgu_cfg);As soon as devm_power_supply_register() has called device_add() the external_power_changed callback can get called. So there is a window where sc27xx_fgu_external_power_changed() may get called while data->battery has not been set yet leading to a NULL pointer dereference.
Fixing this is easy. The external_power_changed callback gets passed the power_supply which will eventually get stored in data->battery, so sc27xx_fgu_external_power_changed() can simply directly use the passed in psy argument which is always valid.
After this change sc27xx_fgu_external_power_changed() is reduced to just "power_supply_changed(psy);" and it has the same prototype. While at it simply replace it with making the external_power_changed callback directly point to power_supply_changed.
--- drivers/power/supply/sc27xx_fuel_gauge.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/power/supply/sc27xx_fuel_gauge.c +1 -8
@@ -733,13 +733,6 @@ static int sc27xx_fgu_set_property(struct power_supply *psy,return ret; } -static void sc27xx_fgu_external_power_changed (struct power_supply *psy) -{ -struct sc27xx_fgu_data *data =power_supply_get_drvdata (psy); - -power_supply_changed (data->battery); -} -static int sc27xx_fgu_property_is_writeable (struct power_supply *psy,enum power_supply_property psp) {
@@ -774,7 +767,7 @@ static const struct power_supply_desc sc27xx_fgu_desc = { .num_properties = ARRAY_SIZE(sc27xx_fgu_props), .get_property = sc27xx_fgu_get_property, .set_property = sc27xx_fgu_set_property, - .external_power_changed = sc27xx_fgu_external_power_changed, + .external_power_changed = power_supply_changed, .property_is_writeable = sc27xx_fgu_property_is_writeable, .no_thermal = true, };
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 3/37 power: supply: bq27xxx: Use mod_delayed_work() instead of cancel() + schedule()
In reply to Sasha LevinFrom: Hans de Goede <[email protected]>
[ Upstream commit 59dddea9879713423c7b2ade43c423bb71e0d216 ]
Use mod_delayed_work() instead of separate cancel_delayed_work_sync() + schedule_delayed_work() calls.
--- drivers/power/supply/bq27xxx_battery.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/power/supply/bq27xxx_battery.c +2 -4
@@ -1083,10 +1083,8 @@ static int poll_interval_param_set(const char *val, const struct kernel_param *kreturn ret;mutex_lock (&bq27xxx_list_lock); -list_for_each_entry (di, &bq27xxx_battery_devices, list) { -cancel_delayed_work_sync (&di->work); -schedule_delayed_work (&di->work,0 ); - } +list_for_each_entry (di, &bq27xxx_battery_devices, list) +mod_delayed_work (system_wq, &di->work,0 );mutex_unlock (&bq27xxx_list_lock);return ret;
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 4/37 ARM: dts: vexpress: add missing cache properties
In reply to Sasha LevinFrom: Krzysztof Kozlowski <[email protected]>
[ Upstream commit 328acc5657c6197753238d7ce0a6924ead829347 ]
As all level 2 and level 3 caches are unified, add required cache-unified property to fix warnings like:
vexpress-v2p-ca5s.dtb: cache-controller@2c0f0000: 'cache-unified' is a required property
--- arch/arm/boot/dts/vexpress-v2p-ca5s.dts | 1 + 1 file changed, 1 insertion(+)
arch/arm/boot/dts/vexpress-v2p-ca5s.dts +1 -0
@@ -132,6 +132,7 @@ L2: cache-controller@2c0f0000 { reg = <0x2c0f0000 0x1000>; interrupts = <0 84 4>; cache-level = <2>; + cache-unified; }; pmu {
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 6/37 tools: gpio: fix debounce_period_us output of lsgpio
In reply to Sasha LevinFrom: Milo Spadacini <[email protected]>
[ Upstream commit eb4b8eca1bad98f4b8574558a74f041f9acb5a54 ]
Fix incorrect output that could occur when more attributes are used and GPIO_V2_LINE_ATTR_ID_DEBOUNCE is not the first one.
--- tools/gpio/lsgpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/gpio/lsgpio.c +1 -1
@@ -94,7 +94,7 @@ static void print_attributes(struct gpio_v2_line_info *info)for (i =0 ; i < info->num_attrs; i++) {if (info->attrs[i].id ==GPIO_V2_LINE_ATTR_ID_DEBOUNCE )fprintf (stdout,", debounce_period=%dusec" , - info->attrs[0 ].debounce_period_us); + info->attrs[i].debounce_period_us); } }
Signature · 1 line
2.39.2
Sasha Levin
maintainerPATCH 5/37 arm64: dts: arm: add missing cache properties
In reply to Sasha LevinFrom: Krzysztof Kozlowski <[email protected]>
[ Upstream commit 55b37d9c8ba23d28c584aef0801fb1e60e4a817c ]
As all level 2 and level 3 caches are unified, add required cache-unified properties to fix warnings like:
foundation-v8.dtb: l2-cache0: 'cache-unified' is a required property
--- arch/arm64/boot/dts/arm/foundation-v8.dtsi | 1 + arch/arm64/boot/dts/arm/rtsm_ve-aemv8a.dts | 1 + arch/arm64/boot/dts/arm/vexpress-v2f-1xv7-ca53x2.dts | 1 + 3 files changed, 3 insertions(+)
arch/arm64/boot/dts/arm/foundation-v8.dtsi +1 -0
@@ -59,6 +59,7 @@ cpu3: cpu@3 { L2_0: l2-cache0 { compatible = "cache"; cache-level = <2>; + cache-unified; }; };
arch/arm64/boot/dts/arm/rtsm_ve-aemv8a.dts +1 -0
@@ -72,6 +72,7 @@ cpu@3 { L2_0: l2-cache0 { compatible = "cache"; cache-level = <2>; + cache-unified; }; };
arch/arm64/boot/dts/arm/vexpress-v2f-1xv7-ca53x2.dts +1 -0
@@ -58,6 +58,7 @@ cpu@1 { L2_0: l2-cache0 { compatible = "cache"; cache-level = <2>; + cache-unified; }; };
Signature · 1 line
2.39.2
Hi!
I do not see complete series in my inbox (only see patches 1-6).
But then I see another thread which seems to be complete.
Date: Wed, 31 May 2023 09:39:43 -0400
Subject: [PATCH AUTOSEL 6.3 01/37] power: supply: ab8500: Fix external_power_changed race
Best regards,
Pavel
Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.