The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko
@ 2026-12-03 16:12 Lee Jones
  2026-12-03 16:12 ` [PATCH 01/10] power: supply: bq27xxx: Check for short i2c_transfer() in bq27xxx_battery_i2c_read() Lee Jones
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-03 16:12 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, Andrew F. Davis, Mark A. Greer, Pali Rohár,
	Uwe Kleine-König (The Capable Hub),
	AngeloGioacchino Del Regno, Anish Kumar, Anton Vorontsov,
	Arun R Murthy, Bjorn Andersson, Grazvydas Ignotas, Hans de Goede,
	Ian Molton, Johan Palsson, Jonathan Cameron, Karl Komierowski,
	Ladislav Michl, Lars-Peter Clausen, Linus Walleij, linux-arm-msm,
	linux-pm, Neil Armstrong, Rhyland Klein, Sebastian Reichel,
	Svyatoslav Ryhel, Tony Lindgren, Xu Rao

These issues were reported by Sashiko.

Cc: "Andrew F. Davis" <afd@ti.com>
Cc: "Mark A. Greer" <mgreer@animalcreek.com>
Cc: "Pali Rohár" <pali@kernel.org>
Cc: "Uwe Kleine-König (The Capable Hub)" <u.kleine-koenig@baylibre.com>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cc: Anish Kumar <yesanishhere@gmail.com>
Cc: Anton Vorontsov <cbou@mail.ru>
Cc: Arun R Murthy <arun.murthy@stericsson.com>
Cc: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
Cc: Grazvydas Ignotas <notasas@gmail.com>
Cc: Hans de Goede <johannes.goede@oss.qualcomm.com>
Cc: Ian Molton <spyro@f2s.com>
Cc: Johan Palsson <johan.palsson@stericsson.com>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Karl Komierowski <karl.komierowski@stericsson.com>
Cc: Ladislav Michl <ladis@linux-mips.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Linus Walleij <linusw@kernel.org>
Cc: linux-arm-msm@vger.kernel.org
Cc: linux-pm@vger.kernel.org
Cc: Neil Armstrong <neil.armstrong@linaro.org>
Cc: Rhyland Klein <rklein@nvidia.com>
Cc: Sebastian Reichel <sre@kernel.org>
Cc: Svyatoslav Ryhel <clamor95@gmail.com>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Xu Rao <raoxu@uniontech.com>

Lee Jones (10):
  power: supply: bq27xxx: Check for short i2c_transfer() in
    bq27xxx_battery_i2c_read()
  power: supply: generic-adc-battery: Initialise bat_work before
    registering supply
  power: supply: bq24190: Manage teardown order with devm to prevent UAF
  power: supply: gpio-charger: Avoid printing uninitialised chargetype
  power: supply: ab8500_btemp: Remove unused global device list
  power: supply: core: Pack supplied_from densely and bound writes
  power: supply: core: Reject empty ocv-capacity-table properties
  power: supply: cpcap-battery: Release battery info in
    cpcap_battery_update_battery_data()
  power: supply: qcom_battmgr: Hold battmgr->lock in
    qcom_battmgr_enable_worker()
  power: supply: sbs-battery: Always cancel delayed work on suspend

 drivers/power/supply/ab8500_btemp.c        |   6 -
 drivers/power/supply/bq24190_charger.c     | 122 +++++++++++----------
 drivers/power/supply/bq27xxx_battery_i2c.c |   2 +
 drivers/power/supply/cpcap-battery.c       |   2 +
 drivers/power/supply/generic-adc-battery.c |  40 +++++--
 drivers/power/supply/gpio-charger.c        |   2 +-
 drivers/power/supply/power_supply_core.c   |  29 +++--
 drivers/power/supply/qcom_battmgr.c        |   8 +-
 drivers/power/supply/sbs-battery.c         |   3 +-
 9 files changed, 124 insertions(+), 90 deletions(-)

-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 01/10] power: supply: bq27xxx: Check for short i2c_transfer() in bq27xxx_battery_i2c_read()
  2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
@ 2026-12-03 16:12 ` Lee Jones
  2026-12-03 16:12 ` [PATCH 02/10] power: supply: generic-adc-battery: Initialise bat_work before registering supply Lee Jones
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-03 16:12 UTC (permalink / raw)
  To: lee, Pali Rohár, Sebastian Reichel,
	Uwe Kleine-König (The Capable Hub), Andrew F. Davis,
	Lars-Peter Clausen, Grazvydas Ignotas, linux-pm, linux-kernel
  Cc: stable

bq27xxx_battery_i2c_read() checks only for negative return values from
i2c_transfer().  If a short transfer occurs (ret >= 0 and ret !=
ARRAY_SIZE(msg)), the stack buffer remains uninitialised and stale
kernel stack data is returned and exposed to userspace via sysfs.

Reject any return value other than ARRAY_SIZE(msg) with -EIO.

Fixes: 9e912f452931 ("bq27x00: Use single i2c_transfer call for property read")
Closes: https://sashiko.dev/#/bug/linux-4a9ebf2e-7f83-4151-9fb9-55063a39d5da
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/power/supply/bq27xxx_battery_i2c.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c
index 715ce8b6e401..63bfc868a6df 100644
--- a/drivers/power/supply/bq27xxx_battery_i2c.c
+++ b/drivers/power/supply/bq27xxx_battery_i2c.c
@@ -61,6 +61,8 @@ static int bq27xxx_battery_i2c_read(struct bq27xxx_device_info *di, u8 reg,
 
 	if (ret < 0)
 		return ret;
+	if (ret != ARRAY_SIZE(msg))
+		return -EIO;
 
 	if (!single)
 		ret = get_unaligned_le16(data);
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 02/10] power: supply: generic-adc-battery: Initialise bat_work before registering supply
  2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
  2026-12-03 16:12 ` [PATCH 01/10] power: supply: bq27xxx: Check for short i2c_transfer() in bq27xxx_battery_i2c_read() Lee Jones
@ 2026-12-03 16:12 ` Lee Jones
  2026-12-03 16:12 ` [PATCH 03/10] power: supply: bq24190: Manage teardown order with devm to prevent UAF Lee Jones
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-03 16:12 UTC (permalink / raw)
  To: lee, Sebastian Reichel, Anish Kumar, Anton Vorontsov,
	Jonathan Cameron, linux-pm, linux-kernel
  Cc: stable

gab_probe() registers the power supply via devm_power_supply_register()
before initialising adc_bat->bat_work via devm_delayed_work_autocancel().
A concurrent supplier notification can invoke gab_ext_power_changed()
and schedule the uninitialised delayed work before initialisation runs.

Acquire the optional charged GPIO and initialise bat_work with
INIT_DELAYED_WORK() before registering the power supply, guard against a
NULL adc_bat->psy in gab_work() during the registration window, and
register a devm cleanup action calling disable_delayed_work_sync()
immediately after registration so that devres LIFO teardown disables the
work before unregistering the power supply and releasing the GPIO.

Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO")
Closes: https://sashiko.dev/#/bug/linux-189bc20e-3b41-4fbd-bae8-c44aafba891a
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 40 ++++++++++++++++------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 7a1f8188bd27..0e4d1a3baf6c 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -18,7 +18,7 @@
 #include <linux/iio/consumer.h>
 #include <linux/iio/types.h>
 #include <linux/of.h>
-#include <linux/devm-helpers.h>
+#include <linux/workqueue.h>
 
 #define JITTER_DEFAULT 10 /* hope 10ms is enough */
 
@@ -129,13 +129,18 @@ static void gab_work(struct work_struct *work)
 {
 	struct gab *adc_bat;
 	struct delayed_work *delayed_work;
+	struct power_supply *psy;
 	int status;
 
 	delayed_work = to_delayed_work(work);
 	adc_bat = container_of(delayed_work, struct gab, bat_work);
+	psy = READ_ONCE(adc_bat->psy);
+	if (!psy)
+		return;
+
 	status = adc_bat->status;
 
-	if (power_supply_am_i_supplied(adc_bat->psy) <= 0)
+	if (power_supply_am_i_supplied(psy) <= 0)
 		adc_bat->status =  POWER_SUPPLY_STATUS_DISCHARGING;
 	else if (gab_charge_finished(adc_bat))
 		adc_bat->status = POWER_SUPPLY_STATUS_NOT_CHARGING;
@@ -143,7 +148,14 @@ static void gab_work(struct work_struct *work)
 		adc_bat->status = POWER_SUPPLY_STATUS_CHARGING;
 
 	if (status != adc_bat->status)
-		power_supply_changed(adc_bat->psy);
+		power_supply_changed(psy);
+}
+
+static void gab_disable_work(void *data)
+{
+	struct gab *adc_bat = data;
+
+	disable_delayed_work_sync(&adc_bat->bat_work);
 }
 
 static irqreturn_t gab_charged(int irq, void *dev_id)
@@ -159,6 +171,7 @@ static irqreturn_t gab_charged(int irq, void *dev_id)
 static int gab_probe(struct platform_device *pdev)
 {
 	struct gab *adc_bat;
+	struct power_supply *psy;
 	struct power_supply_desc *psy_desc;
 	struct power_supply_config psy_cfg = {};
 	enum power_supply_property *properties;
@@ -234,18 +247,23 @@ static int gab_probe(struct platform_device *pdev)
 	psy_desc->properties = properties;
 	psy_desc->num_properties = index;
 
-	adc_bat->psy = devm_power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
-	if (IS_ERR(adc_bat->psy))
-		return dev_err_probe(&pdev->dev, PTR_ERR(adc_bat->psy), "Failed to register power-supply device\n");
-
-	ret = devm_delayed_work_autocancel(&pdev->dev, &adc_bat->bat_work, gab_work);
-	if (ret)
-		return dev_err_probe(&pdev->dev, ret, "Failed to register delayed work\n");
-
 	adc_bat->charge_finished = devm_gpiod_get_optional(&pdev->dev, "charged", GPIOD_IN);
 	if (IS_ERR(adc_bat->charge_finished))
 		return dev_err_probe(&pdev->dev, PTR_ERR(adc_bat->charge_finished),
 				     "failed to get charged GPIO\n");
+
+	INIT_DELAYED_WORK(&adc_bat->bat_work, gab_work);
+
+	psy = devm_power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
+	if (IS_ERR(psy))
+		return dev_err_probe(&pdev->dev, PTR_ERR(psy),
+				     "Failed to register power-supply device\n");
+	WRITE_ONCE(adc_bat->psy, psy);
+
+	ret = devm_add_action_or_reset(&pdev->dev, gab_disable_work, adc_bat);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "Failed to register delayed work cleanup\n");
+
 	if (adc_bat->charge_finished) {
 		int irq;
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 03/10] power: supply: bq24190: Manage teardown order with devm to prevent UAF
  2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
  2026-12-03 16:12 ` [PATCH 01/10] power: supply: bq27xxx: Check for short i2c_transfer() in bq27xxx_battery_i2c_read() Lee Jones
  2026-12-03 16:12 ` [PATCH 02/10] power: supply: generic-adc-battery: Initialise bat_work before registering supply Lee Jones
@ 2026-12-03 16:12 ` Lee Jones
  2026-12-03 16:12 ` [PATCH 04/10] power: supply: gpio-charger: Avoid printing uninitialised chargetype Lee Jones
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-03 16:12 UTC (permalink / raw)
  To: lee, Sebastian Reichel, Mark A. Greer, Anton Vorontsov, linux-pm,
	linux-kernel
  Cc: stable

bq24190_probe() registers input_current_limit_work, the threaded IRQ,
and the VBUS regulator using devm helpers while manually unregistering
bdi->charger and bdi->battery in bq24190_remove() and on probe error.
During unbind, the supplies are unregistered and runtime PM is disabled
before devres frees the IRQ and cancels delayed work, allowing
bq24190_irq_handler_thread() or bq24190_input_current_limit_work() to
call power_supply_changed() on freed supplies.

Unify all teardown under devres in strict LIFO order, drop
bq24190_remove(), register bdi->battery before bdi->charger followed
immediately by the work-disable action, and clear bdi->initialized and
drain runtime PM via pm_runtime_barrier() while disabling
input_current_limit_work before unregistering the supplies and resetting
the hardware.

Fixes: d7bf353fd0aa ("bq24190_charger: Add support for TI BQ24190 Battery Charger")
Closes: https://sashiko.dev/#/bug/linux-a308a73a-596a-4aaf-99a5-d3b422b19742
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/power/supply/bq24190_charger.c | 122 +++++++++++++------------
 1 file changed, 64 insertions(+), 58 deletions(-)

diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index 7a5867dd74c2..4d27d142f1c1 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -8,7 +8,6 @@
 #include <linux/module.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
-#include <linux/devm-helpers.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm_wakeirq.h>
 #include <linux/power_supply.h>
@@ -230,6 +229,7 @@ struct bq24190_dev_info {
 	struct delayed_work		input_current_limit_work;
 	char				model_name[I2C_NAME_SIZE];
 	bool				initialized;
+	bool				hw_initialized;
 	bool				irq_event;
 	bool				otg_vbus_enabled;
 	int				charge_type;
@@ -2114,6 +2114,32 @@ static const struct bq24190_chip_info bq24190_chip_info_tbl[] = {
 	},
 };
 
+static void bq24190_pm_runtime_cleanup(void *data)
+{
+	struct bq24190_dev_info *bdi = data;
+
+	if (bdi->hw_initialized) {
+		int error = pm_runtime_resume_and_get(bdi->dev);
+
+		if (error < 0)
+			dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
+		bq24190_register_reset(bdi);
+		if (error >= 0)
+			pm_runtime_put_sync(bdi->dev);
+	}
+	pm_runtime_dont_use_autosuspend(bdi->dev);
+	pm_runtime_disable(bdi->dev);
+}
+
+static void bq24190_disable_work(void *data)
+{
+	struct bq24190_dev_info *bdi = data;
+
+	WRITE_ONCE(bdi->initialized, false);
+	pm_runtime_barrier(bdi->dev);
+	disable_delayed_work_sync(&bdi->input_current_limit_work);
+}
+
 static int bq24190_probe(struct i2c_client *client)
 {
 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
@@ -2143,10 +2169,8 @@ static int bq24190_probe(struct i2c_client *client)
 	bdi->f_reg = 0;
 	bdi->ss_reg = BQ24190_REG_SS_VBUS_STAT_MASK; /* impossible state */
 
-	ret = devm_delayed_work_autocancel(dev, &bdi->input_current_limit_work,
-					   bq24190_input_current_limit_work);
-	if (ret)
-		return ret;
+	INIT_DELAYED_WORK(&bdi->input_current_limit_work,
+			  bq24190_input_current_limit_work);
 
 	i2c_set_clientdata(client, bdi);
 
@@ -2166,10 +2190,27 @@ static int bq24190_probe(struct i2c_client *client)
 	pm_runtime_enable(dev);
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, 600);
-	ret = pm_runtime_get_sync(dev);
+	ret = devm_add_action_or_reset(dev, bq24190_pm_runtime_cleanup, bdi);
+	if (ret)
+		return ret;
+
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0) {
 		dev_err(dev, "pm_runtime_get failed: %i\n", ret);
-		goto out_pmrt;
+		return ret;
+	}
+
+	/* the battery class is deprecated and will be removed. */
+	/* in the interim, this property hides it.              */
+	if (!device_property_read_bool(dev, "omit-battery-class")) {
+		battery_cfg.drv_data = bdi;
+		bdi->battery = devm_power_supply_register(dev, &bq24190_battery_desc,
+							  &battery_cfg);
+		if (IS_ERR(bdi->battery)) {
+			dev_err(dev, "Can't register battery\n");
+			ret = PTR_ERR(bdi->battery);
+			goto out_pmrt;
+		}
 	}
 
 #ifdef CONFIG_SYSFS
@@ -2181,99 +2222,65 @@ static int bq24190_probe(struct i2c_client *client)
 	charger_cfg.fwnode = dev_fwnode(dev);
 	charger_cfg.supplied_to = bq24190_charger_supplied_to;
 	charger_cfg.num_supplicants = ARRAY_SIZE(bq24190_charger_supplied_to);
-	bdi->charger = power_supply_register(dev, &bq24190_charger_desc,
-						&charger_cfg);
+	bdi->charger = devm_power_supply_register(dev, &bq24190_charger_desc,
+						  &charger_cfg);
 	if (IS_ERR(bdi->charger)) {
 		dev_err(dev, "Can't register charger\n");
 		ret = PTR_ERR(bdi->charger);
 		goto out_pmrt;
 	}
 
-	/* the battery class is deprecated and will be removed. */
-	/* in the interim, this property hides it.              */
-	if (!device_property_read_bool(dev, "omit-battery-class")) {
-		battery_cfg.drv_data = bdi;
-		bdi->battery = power_supply_register(dev, &bq24190_battery_desc,
-						     &battery_cfg);
-		if (IS_ERR(bdi->battery)) {
-			dev_err(dev, "Can't register battery\n");
-			ret = PTR_ERR(bdi->battery);
-			goto out_charger;
-		}
-	}
+	ret = devm_add_action_or_reset(dev, bq24190_disable_work, bdi);
+	if (ret)
+		goto out_pmrt;
 
 	ret = bq24190_get_config(bdi);
 	if (ret < 0) {
 		dev_err(dev, "Can't get devicetree config\n");
-		goto out_charger;
+		goto out_pmrt;
 	}
 
 	ret = bq24190_hw_init(bdi);
 	if (ret < 0) {
 		dev_err(dev, "Hardware init failed\n");
-		goto out_charger;
+		goto out_pmrt;
 	}
+	bdi->hw_initialized = true;
 
 	ret = bq24190_configure_usb_otg(bdi, bdi->ss_reg);
 	if (ret < 0)
-		goto out_charger;
+		goto out_pmrt;
 
-	bdi->initialized = true;
+	WRITE_ONCE(bdi->initialized, true);
 
 	ret = devm_request_threaded_irq(dev, client->irq, NULL,
 			bq24190_irq_handler_thread,
 			IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
 			"bq24190-charger", bdi);
 	if (ret < 0)
-		goto out_charger;
+		goto out_pmrt;
 
 	ret = bq24190_register_vbus_regulator(bdi);
 	if (ret < 0)
-		goto out_charger;
+		goto out_pmrt;
 
 	ret = devm_device_init_wakeup(dev);
 	if (ret < 0)
-		goto out_charger;
+		goto out_pmrt;
 
 	ret = devm_pm_set_wake_irq(dev, client->irq);
 	if (ret < 0)
-		goto out_charger;
+		goto out_pmrt;
 
 	pm_runtime_put_autosuspend(dev);
 
 	return 0;
 
-out_charger:
-	if (!IS_ERR_OR_NULL(bdi->battery))
-		power_supply_unregister(bdi->battery);
-	power_supply_unregister(bdi->charger);
-
 out_pmrt:
 	pm_runtime_put_sync(dev);
-	pm_runtime_dont_use_autosuspend(dev);
-	pm_runtime_disable(dev);
 	return ret;
 }
 
-static void bq24190_remove(struct i2c_client *client)
-{
-	struct bq24190_dev_info *bdi = i2c_get_clientdata(client);
-	int error;
-
-	error = pm_runtime_resume_and_get(bdi->dev);
-	if (error < 0)
-		dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
-
-	bq24190_register_reset(bdi);
-	if (bdi->battery)
-		power_supply_unregister(bdi->battery);
-	power_supply_unregister(bdi->charger);
-	if (error >= 0)
-		pm_runtime_put_sync(bdi->dev);
-	pm_runtime_dont_use_autosuspend(bdi->dev);
-	pm_runtime_disable(bdi->dev);
-}
-
 static void bq24190_shutdown(struct i2c_client *client)
 {
 	struct bq24190_dev_info *bdi = i2c_get_clientdata(client);
@@ -2287,7 +2294,7 @@ static __maybe_unused int bq24190_runtime_suspend(struct device *dev)
 	struct i2c_client *client = to_i2c_client(dev);
 	struct bq24190_dev_info *bdi = i2c_get_clientdata(client);
 
-	if (!bdi->initialized)
+	if (!READ_ONCE(bdi->initialized))
 		return 0;
 
 	dev_dbg(bdi->dev, "%s\n", __func__);
@@ -2300,7 +2307,7 @@ static __maybe_unused int bq24190_runtime_resume(struct device *dev)
 	struct i2c_client *client = to_i2c_client(dev);
 	struct bq24190_dev_info *bdi = i2c_get_clientdata(client);
 
-	if (!bdi->initialized)
+	if (!READ_ONCE(bdi->initialized))
 		return 0;
 
 	if (!bdi->irq_event) {
@@ -2379,7 +2386,6 @@ MODULE_DEVICE_TABLE(of, bq24190_of_match);
 
 static struct i2c_driver bq24190_driver = {
 	.probe		= bq24190_probe,
-	.remove		= bq24190_remove,
 	.shutdown	= bq24190_shutdown,
 	.id_table	= bq24190_i2c_ids,
 	.driver = {
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 04/10] power: supply: gpio-charger: Avoid printing uninitialised chargetype
  2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (2 preceding siblings ...)
  2026-12-03 16:12 ` [PATCH 03/10] power: supply: bq24190: Manage teardown order with devm to prevent UAF Lee Jones
@ 2026-12-03 16:12 ` Lee Jones
  2026-12-03 16:12 ` [PATCH 05/10] power: supply: ab8500_btemp: Remove unused global device list Lee Jones
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-03 16:12 UTC (permalink / raw)
  To: lee, Sebastian Reichel, Xu Rao, Lars-Peter Clausen,
	Ladislav Michl, linux-pm, linux-kernel
  Cc: stable

In gpio_charger_get_type(), dev_warn() sits outside the
device_property_read_string() block.  When the optional "charger-type"
property is absent, chargetype remains an uninitialised stack pointer
that is dereferenced by dev_warn().

Move dev_warn() inside the device_property_read_string() block so it
only runs when a string property was actually read.

Fixes: d47c1e4b2f51 ("power: supply: gpio-charger: Remove pdata from gpio_charger")
Closes: https://sashiko.dev/#/bug/linux-9f95ca8d-6d98-4727-935c-a5139913274e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/power/supply/gpio-charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/gpio-charger.c b/drivers/power/supply/gpio-charger.c
index 647f5bde38c7..684dba7b6fbe 100644
--- a/drivers/power/supply/gpio-charger.c
+++ b/drivers/power/supply/gpio-charger.c
@@ -176,8 +176,8 @@ static enum power_supply_type gpio_charger_get_type(struct device *dev)
 			return POWER_SUPPLY_TYPE_USB;
 		if (!strcmp("usb-aca", chargetype))
 			return POWER_SUPPLY_TYPE_USB;
+		dev_warn(dev, "unknown charger type %s\n", chargetype);
 	}
-	dev_warn(dev, "unknown charger type %s\n", chargetype);
 
 	return POWER_SUPPLY_TYPE_UNKNOWN;
 }
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 05/10] power: supply: ab8500_btemp: Remove unused global device list
  2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (3 preceding siblings ...)
  2026-12-03 16:12 ` [PATCH 04/10] power: supply: gpio-charger: Avoid printing uninitialised chargetype Lee Jones
@ 2026-12-03 16:12 ` Lee Jones
  2026-12-03 16:12 ` [PATCH 06/10] power: supply: core: Pack supplied_from densely and bound writes Lee Jones
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-03 16:12 UTC (permalink / raw)
  To: lee, Linus Walleij, Sebastian Reichel, Johan Palsson,
	Karl Komierowski, Arun R Murthy, Anton Vorontsov, linux-pm,
	linux-kernel
  Cc: stable

ab8500_btemp_probe() links the devm-allocated device structure into the
static ab8500_btemp_list without ever removing it on probe failure or
unbind.  A subsequent rebind traverses the freed list node and corrupts
memory.

Since ab8500_btemp_list has had no readers since BATCTRL thermal mode
was removed, delete the unused list and its node field altogether.

Fixes: 1f855824757e ("ab8500-btemp: AB8500 battery temperature driver")
Closes: https://sashiko.dev/#/bug/linux-1b556e1a-3976-4c4b-a368-b92b6f64cc8b
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/power/supply/ab8500_btemp.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/power/supply/ab8500_btemp.c b/drivers/power/supply/ab8500_btemp.c
index 1e11bbe3baaf..5dfee700d65c 100644
--- a/drivers/power/supply/ab8500_btemp.c
+++ b/drivers/power/supply/ab8500_btemp.c
@@ -76,7 +76,6 @@ struct ab8500_btemp_ranges {
 /**
  * struct ab8500_btemp - ab8500 BTEMP device information
  * @dev:		Pointer to the structure device
- * @node:		List of AB8500 BTEMPs, hence prepared for reentrance
  * @curr_source:	What current source we use, in uA
  * @bat_temp:		Dispatched battery temperature in degree Celsius
  * @prev_bat_temp	Last measured battery temperature in degree Celsius
@@ -94,7 +93,6 @@ struct ab8500_btemp_ranges {
  */
 struct ab8500_btemp {
 	struct device *dev;
-	struct list_head node;
 	int curr_source;
 	int bat_temp;
 	int prev_bat_temp;
@@ -118,8 +116,6 @@ static enum power_supply_property ab8500_btemp_props[] = {
 	POWER_SUPPLY_PROP_TEMP,
 };
 
-static LIST_HEAD(ab8500_btemp_list);
-
 /**
  * ab8500_btemp_batctrl_volt_to_res() - convert batctrl voltage to resistance
  * @di:		pointer to the ab8500_btemp structure
@@ -787,8 +783,6 @@ static int ab8500_btemp_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, di);
 
-	list_add_tail(&di->node, &ab8500_btemp_list);
-
 	return component_add(dev, &ab8500_btemp_component_ops);
 }
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 06/10] power: supply: core: Pack supplied_from densely and bound writes
  2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (4 preceding siblings ...)
  2026-12-03 16:12 ` [PATCH 05/10] power: supply: ab8500_btemp: Remove unused global device list Lee Jones
@ 2026-12-03 16:12 ` Lee Jones
  2026-12-03 16:12 ` [PATCH 07/10] power: supply: core: Reject empty ocv-capacity-table properties Lee Jones
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-03 16:12 UTC (permalink / raw)
  To: lee, Sebastian Reichel, Anton Vorontsov, Ian Molton,
	Rhyland Klein, linux-pm, linux-kernel
  Cc: stable

__power_supply_populate_supplied_from() stores matched supplier names at
the sparse firmware reference index (i - 1) while independently
incrementing psy->num_supplies.  If an earlier referenced supply
unregisters concurrently, psy->supplied_from[0] remains NULL while
psy->num_supplies is non-zero, causing __power_supply_is_supplied_by()
to dereference NULL in strcmp().  Furthermore, multiple supplies sharing
the same fwnode can increment num_supplies past the allocated array.

Pass the allocated slot count to power_supply_populate_supplied_from(),
pack entries densely at psy->supplied_from[psy->num_supplies++], and
stop before exceeding the allocation.

Fixes: f6e0b081fb30 ("power_supply: Populate supplied_from hierarchy from the device tree")
Closes: https://sashiko.dev/#/bug/linux-a0295e92-ec18-42a6-9e66-60792792613b
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/power/supply/power_supply_core.c | 27 ++++++++++++++++++------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index de15314ef954..7488c7b94f40 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -219,10 +219,16 @@ static int power_supply_check_supplies_by_name(struct power_supply *psy)
 	return 0;
 }
 
+struct psy_populate_supplied_from_data {
+	struct power_supply *psy;
+	int max_supplies;
+};
+
 static int __power_supply_populate_supplied_from(struct power_supply *epsy,
 						 void *data)
 {
-	struct power_supply *psy = data;
+	struct psy_populate_supplied_from_data *ctx = data;
+	struct power_supply *psy = ctx->psy;
 	struct fwnode_handle *np;
 	int i = 0;
 
@@ -232,11 +238,13 @@ static int __power_supply_populate_supplied_from(struct power_supply *epsy,
 			break;
 
 		if (np == epsy->dev.fwnode) {
+			fwnode_handle_put(np);
+			if (psy->num_supplies >= ctx->max_supplies)
+				break;
 			dev_dbg(&psy->dev, "%s: Found supply : %s\n",
 				psy->desc->name, epsy->desc->name);
-			psy->supplied_from[i-1] = (char *)epsy->desc->name;
-			psy->num_supplies++;
-			fwnode_handle_put(np);
+			psy->supplied_from[psy->num_supplies++] =
+				(char *)epsy->desc->name;
 			break;
 		}
 		fwnode_handle_put(np);
@@ -245,11 +253,16 @@ static int __power_supply_populate_supplied_from(struct power_supply *epsy,
 	return 0;
 }
 
-static int power_supply_populate_supplied_from(struct power_supply *psy)
+static int power_supply_populate_supplied_from(struct power_supply *psy,
+					       int max_supplies)
 {
+	struct psy_populate_supplied_from_data data = {
+		.psy = psy,
+		.max_supplies = max_supplies,
+	};
 	int error;
 
-	error = power_supply_for_each_psy(psy, __power_supply_populate_supplied_from);
+	error = power_supply_for_each_psy(&data, __power_supply_populate_supplied_from);
 
 	dev_dbg(&psy->dev, "%s %d\n", __func__, error);
 
@@ -326,7 +339,7 @@ static int power_supply_check_supplies(struct power_supply *psy)
 	if (!psy->supplied_from)
 		return -ENOMEM;
 
-	return power_supply_populate_supplied_from(psy);
+	return power_supply_populate_supplied_from(psy, cnt);
 }
 
 struct psy_am_i_supplied_data {
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 07/10] power: supply: core: Reject empty ocv-capacity-table properties
  2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (5 preceding siblings ...)
  2026-12-03 16:12 ` [PATCH 06/10] power: supply: core: Pack supplied_from densely and bound writes Lee Jones
@ 2026-12-03 16:12 ` Lee Jones
  2026-12-03 16:12 ` [PATCH 08/10] power: supply: cpcap-battery: Release battery info in cpcap_battery_update_battery_data() Lee Jones
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-03 16:12 UTC (permalink / raw)
  To: lee, Sebastian Reichel, Anton Vorontsov, Ian Molton,
	AngeloGioacchino Del Regno, Hans de Goede, linux-pm, linux-kernel
  Cc: stable

In power_supply_get_battery_info(), an empty ocv-capacity-table
property yields proplen == 0, which passes the current length check.
devm_kcalloc() then returns ZERO_SIZE_PTR and stores it in
info->ocv_table[index] with size 0, causing power_supply_ocv2cap_simple()
to dereference ZERO_SIZE_PTR when indexing table[0].

Reject proplen <= 0 with -EINVAL.

Fixes: 570ba047a654 ("power: supply: core: battery-info: fully switch to fwnode")
Closes: https://sashiko.dev/#/bug/linux-4a0a5d5f-629d-4b0d-b4be-07415bcb018e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/power/supply/power_supply_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 7488c7b94f40..4280f2aff7f7 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -910,7 +910,7 @@ int power_supply_get_battery_info(struct power_supply *psy,
 			goto out_put_node;
 		}
 		proplen = fwnode_property_count_u32(fwnode, propname);
-		if (proplen < 0 || proplen % 2 != 0) {
+		if (proplen <= 0 || proplen % 2 != 0) {
 			dev_err(&psy->dev, "failed to get %s\n", propname);
 			power_supply_put_battery_info(psy, info);
 			err = -EINVAL;
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 08/10] power: supply: cpcap-battery: Release battery info in cpcap_battery_update_battery_data()
  2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (6 preceding siblings ...)
  2026-12-03 16:12 ` [PATCH 07/10] power: supply: core: Reject empty ocv-capacity-table properties Lee Jones
@ 2026-12-03 16:12 ` Lee Jones
  2026-12-03 16:12 ` [PATCH 09/10] power: supply: qcom_battmgr: Hold battmgr->lock in qcom_battmgr_enable_worker() Lee Jones
  2026-12-03 16:12 ` [PATCH 10/10] power: supply: sbs-battery: Always cancel delayed work on suspend Lee Jones
  9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-03 16:12 UTC (permalink / raw)
  To: lee, Sebastian Reichel, Tony Lindgren, Svyatoslav Ryhel, linux-pm,
	linux-kernel
  Cc: stable

cpcap_battery_update_battery_data() allocates battery info via
power_supply_get_battery_info(), copies five integer fields, and
returns without calling power_supply_put_battery_info().  When the
nvmem device is absent, repeated sysfs reads invoke this helper and
continuously leak devres allocations.

Release the temporary battery info via power_supply_put_battery_info()
before returning.

Fixes: f0c8407c83a5 ("power: supply: cpcap-battery: pass static battery cell data from device tree")
Closes: https://sashiko.dev/#/bug/linux-02b35419-d9a3-425a-9d0f-1b01b1ec2adc
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/power/supply/cpcap-battery.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index 808714c6ce95..1981d52a3ed8 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -426,6 +426,8 @@ static void cpcap_battery_update_battery_data(struct cpcap_battery_ddata *ddata)
 	if (info->constant_charge_voltage_max_uv > 0)
 		ddata->config.bat.constant_charge_voltage_max_uv =
 			info->constant_charge_voltage_max_uv;
+
+	power_supply_put_battery_info(ddata->psy, info);
 }
 
 static void cpcap_battery_detect_battery_type(struct cpcap_battery_ddata *ddata)
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 09/10] power: supply: qcom_battmgr: Hold battmgr->lock in qcom_battmgr_enable_worker()
  2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (7 preceding siblings ...)
  2026-12-03 16:12 ` [PATCH 08/10] power: supply: cpcap-battery: Release battery info in cpcap_battery_update_battery_data() Lee Jones
@ 2026-12-03 16:12 ` Lee Jones
  2026-12-03 16:12 ` [PATCH 10/10] power: supply: sbs-battery: Always cancel delayed work on suspend Lee Jones
  9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-03 16:12 UTC (permalink / raw)
  To: lee, Sebastian Reichel, Bjorn Andersson, Neil Armstrong,
	linux-arm-msm, linux-pm, linux-kernel
  Cc: stable

qcom_battmgr_enable_worker() calls qcom_battmgr_request() without
acquiring battmgr->lock, racing with concurrent sysfs property queries
that also use battmgr->ack and battmgr->error and sending overlapping
requests to PMIC GLINK firmware.

Acquire battmgr->lock around qcom_battmgr_request() in
qcom_battmgr_enable_worker() and assert the lock in
qcom_battmgr_request().

Fixes: 29e8142b5623 ("power: supply: Introduce Qualcomm PMIC GLINK power supply")
Closes: https://sashiko.dev/#/bug/linux-35b68138-5485-48e9-a9ab-df314c5c19ec
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/power/supply/qcom_battmgr.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
index 0789303a5965..4a86c3b5235c 100644
--- a/drivers/power/supply/qcom_battmgr.c
+++ b/drivers/power/supply/qcom_battmgr.c
@@ -351,10 +351,8 @@ static int qcom_battmgr_request(struct qcom_battmgr *battmgr, void *data, size_t
 	unsigned long left;
 	int ret;
 
-	/*
-	 * Callers hold @lock, except enable_work, which is disabled before
-	 * client_gone is set.
-	 */
+	lockdep_assert_held(&battmgr->lock);
+
 	if (battmgr->client_gone)
 		return -ENODEV;
 
@@ -1748,7 +1746,9 @@ static void qcom_battmgr_enable_worker(struct work_struct *work)
 	};
 	int ret;
 
+	mutex_lock(&battmgr->lock);
 	ret = qcom_battmgr_request(battmgr, &req, sizeof(req));
+	mutex_unlock(&battmgr->lock);
 	if (ret)
 		dev_err(battmgr->dev, "failed to request power notifications\n");
 }
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 10/10] power: supply: sbs-battery: Always cancel delayed work on suspend
  2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (8 preceding siblings ...)
  2026-12-03 16:12 ` [PATCH 09/10] power: supply: qcom_battmgr: Hold battmgr->lock in qcom_battmgr_enable_worker() Lee Jones
@ 2026-12-03 16:12 ` Lee Jones
  9 siblings, 0 replies; 11+ messages in thread
From: Lee Jones @ 2026-12-03 16:12 UTC (permalink / raw)
  To: lee, Sebastian Reichel, Anton Vorontsov, Rhyland Klein, linux-pm,
	linux-kernel
  Cc: stable

sbs_external_power_changed() schedules chip->work unconditionally, even
when chip->poll_retry_count (and therefore chip->poll_time) is 0, and
the final retry in sbs_delayed_work() also leaves chip->poll_time at 0
while chip->work is pending.  Guarding cancel_delayed_work_sync() with
chip->poll_time > 0 in sbs_suspend() allows sbs_delayed_work() to issue
I2C transfers over a suspended bus.

Unconditionally cancel chip->work in sbs_suspend().

Fixes: 58ddafae2d71 ("bq20z75: Add support for external notification")
Closes: https://sashiko.dev/#/bug/linux-cf247db7-fc5a-40ee-b341-0d7814f58458
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/power/supply/sbs-battery.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c
index f8b194c58a62..0b68f9835719 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -1253,8 +1253,7 @@ static int sbs_suspend(struct device *dev)
 	struct sbs_info *chip = i2c_get_clientdata(client);
 	int ret;
 
-	if (chip->poll_time > 0)
-		cancel_delayed_work_sync(&chip->work);
+	cancel_delayed_work_sync(&chip->work);
 
 	if (chip->flags & SBS_FLAGS_TI_BQ20ZX5) {
 		/* Write to manufacturer access with sleep command. */
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-12-03 16:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 16:12 ` [PATCH 01/10] power: supply: bq27xxx: Check for short i2c_transfer() in bq27xxx_battery_i2c_read() Lee Jones
2026-12-03 16:12 ` [PATCH 02/10] power: supply: generic-adc-battery: Initialise bat_work before registering supply Lee Jones
2026-12-03 16:12 ` [PATCH 03/10] power: supply: bq24190: Manage teardown order with devm to prevent UAF Lee Jones
2026-12-03 16:12 ` [PATCH 04/10] power: supply: gpio-charger: Avoid printing uninitialised chargetype Lee Jones
2026-12-03 16:12 ` [PATCH 05/10] power: supply: ab8500_btemp: Remove unused global device list Lee Jones
2026-12-03 16:12 ` [PATCH 06/10] power: supply: core: Pack supplied_from densely and bound writes Lee Jones
2026-12-03 16:12 ` [PATCH 07/10] power: supply: core: Reject empty ocv-capacity-table properties Lee Jones
2026-12-03 16:12 ` [PATCH 08/10] power: supply: cpcap-battery: Release battery info in cpcap_battery_update_battery_data() Lee Jones
2026-12-03 16:12 ` [PATCH 09/10] power: supply: qcom_battmgr: Hold battmgr->lock in qcom_battmgr_enable_worker() Lee Jones
2026-12-03 16:12 ` [PATCH 10/10] power: supply: sbs-battery: Always cancel delayed work on suspend Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox