[PATCH] power: supply: gpio-charger: Keep properties per device

From: raoxu

Date: Tue Nov 10 2026 - 00:54:28 EST


From: Xu Rao <raoxu@xxxxxxxxxxxxx>

gpio_charger_properties is a global array that is overwritten during
each device probe according to the optional GPIO features present on
that device. When more than one gpio-charger is registered, a later
probe can therefore change the property list referenced by an already
registered power supply.

Store the property array in struct gpio_charger so each power supply
keeps the property list built for its own device.

Fixes: 1d85f6d1b0c1 ("power: supply: gpio-charger: Make gpios optional")
Signed-off-by: Xu Rao <raoxu@xxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
drivers/power/supply/gpio-charger.c | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/power/supply/gpio-charger.c b/drivers/power/supply/gpio-charger.c
index 1dad49acc424..99c1af99dd88 100644
--- a/drivers/power/supply/gpio-charger.c
+++ b/drivers/power/supply/gpio-charger.c
@@ -30,6 +30,7 @@ struct gpio_charger {

struct power_supply *charger;
struct power_supply_desc charger_desc;
+ enum power_supply_property properties[3];
struct gpio_desc *gpiod;
struct gpio_desc *charge_status;

@@ -262,17 +263,6 @@ static int init_charge_current_limit(struct device *dev,
return 0;
}

-/*
- * The entries will be overwritten by driver's probe routine depending
- * on the available features. This list ensures, that the array is big
- * enough for all optional features.
- */
-static enum power_supply_property gpio_charger_properties[] = {
- POWER_SUPPLY_PROP_ONLINE,
- POWER_SUPPLY_PROP_STATUS,
- POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
-};
-
static int gpio_charger_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -307,7 +297,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
}

if (gpio_charger->gpiod) {
- gpio_charger_properties[num_props] = POWER_SUPPLY_PROP_ONLINE;
+ gpio_charger->properties[num_props] = POWER_SUPPLY_PROP_ONLINE;
num_props++;
}

@@ -316,7 +306,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
return PTR_ERR(charge_status);
if (charge_status) {
gpio_charger->charge_status = charge_status;
- gpio_charger_properties[num_props] = POWER_SUPPLY_PROP_STATUS;
+ gpio_charger->properties[num_props] = POWER_SUPPLY_PROP_STATUS;
num_props++;
}

@@ -324,13 +314,13 @@ static int gpio_charger_probe(struct platform_device *pdev)
if (ret < 0)
return ret;
if (gpio_charger->current_limit_map) {
- gpio_charger_properties[num_props] =
+ gpio_charger->properties[num_props] =
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;
num_props++;
}

charger_desc = &gpio_charger->charger_desc;
- charger_desc->properties = gpio_charger_properties;
+ charger_desc->properties = gpio_charger->properties;
charger_desc->num_properties = num_props;
charger_desc->get_property = gpio_charger_get_property;
charger_desc->set_property = gpio_charger_set_property;
--
2.50.1