FAILED: patch "[PATCH] power: supply: core: Honor supplied-from with CONFIG_OF=y" failed to apply to 6.12-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 6bd80f22c764fe8c56c62c118387f86a3ca98cff
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 6bd80f22c764fe8c56c62c118387f86a3ca98cff Mon Sep 17 00:00:00 2001
From: Maurizio Casciano <[email protected]>
Date: Fri, 25 Sep 2026 00:51:52 +0200
Subject: [PATCH] power: supply: core: Honor supplied-from with CONFIG_OF=y
The supplied-from device property is the name-based counterpart to firmware-node power-supplies references. It was added for non-DT platforms, but its parser is compiled only when CONFIG_OF is disabled. CONFIG_OF is a global kernel option, so x86 systems commonly enable it even when individual power supplies are described by software nodes.
Consequently, these consumers never populate supplied_from and supplier notifications do not reach their external_power_changed() callbacks. On a Lenovo Yoga Book YB1-X91L, ftrace showed the Whiskey Cove supplier notification running without invoking the BQ25892 callback, leaving the input current limit at its boot-time value.
Use a single power_supply_check_supplies() implementation for all configurations. Preserve firmware-node power-supplies references as the preferred firmware description and use the name-based supplied-from property only when no references are specified. Continue to honor an explicitly provided supplied_from list first and propagate errors from specified firmware references.
With the fix, ftrace shows the BQ25892 callback on hotplug. A boot-offline test changes its input current limit from 500 mA to 2 A.
--- drivers/power/supply/power_supply_core.c | 84 ++++++++++++------------ 1 file changed, 42 insertions(+), 42 deletions(-)
drivers/power/supply/power_supply_core.c +42 -42
@@ -190,7 +190,35 @@ static void power_supply_deferred_register_work(struct work_struct *work)device_unlock (psy->dev.parent); } -#ifdef CONFIG_OF +static int power_supply_check_supplies_by_name (struct power_supply *psy) +{ +struct device *parent = psy->dev.parent; +int nval, ret; + +if (!parent) +return 0 ; + + nval =device_property_string_array_count (parent,"supplied-from" ); +if (nval <=0 ) +return 0 ; + + psy->supplied_from =devm_kmalloc_array (&psy->dev, nval, +sizeof (*psy->supplied_from), +GFP_KERNEL ); +if (!psy->supplied_from) +return -ENOMEM ; + + ret =device_property_read_string_array (parent,"supplied-from" , + (const char **)psy->supplied_from, + nval); +if (ret <0 ) +return ret; + + psy->num_supplies = nval; + +return 0 ; +} +static int __power_supply_populate_supplied_from (struct power_supply *epsy,void *data) {
@@ -262,22 +290,21 @@ static int power_supply_find_supply_from_fwnode(struct fwnode_handle *supply_nodstatic int power_supply_check_supplies (struct power_supply *psy) {struct fwnode_handle *np; -int cnt =0 ; +int cnt, ret;/* If there is already a list honor it */ if (psy->supplied_from && psy->num_supplies >0 )return 0 ; -/* No device node found, nothing to do */ -if (!psy->dev.fwnode) -return 0 ; - - do { - int ret; +for (cnt =0 ; psy->dev.fwnode; cnt++) { + np =fwnode_find_reference (psy->dev.fwnode,"power-supplies" , cnt); +if (IS_ERR (np)) { + ret =PTR_ERR (np); +if (ret != -ENOENT ) +return ret; - np = fwnode_find_reference(psy->dev.fwnode, "power-supplies", cnt++); - if (IS_ERR(np))break ; + } ret =power_supply_find_supply_from_fwnode (np);fwnode_handle_put (np);
@@ -286,48 +313,21 @@ static int power_supply_check_supplies(struct power_supply *psy)dev_dbg (&psy->dev,"Failed to find supply!\n" );return ret; } - }while (!IS_ERR (np)); + } -/* Missing valid "power-supplies" entries */ -if (cnt ==1 ) -return 0 ; +/* Fall back to the name-based property if no references were specified. */ +if (!cnt) +return power_supply_check_supplies_by_name (psy);/* All supplies found, allocate char * array for filling */ psy->supplied_from =devm_kcalloc (&psy->dev, - cnt -1 ,sizeof (*psy->supplied_from), + cnt,sizeof (*psy->supplied_from),GFP_KERNEL );if (!psy->supplied_from)return -ENOMEM ;return power_supply_populate_supplied_from (psy); } -#else -static int power_supply_check_supplies (struct power_supply *psy) -{ -int nval, ret; - -if (!psy->dev.parent) -return 0 ; - - nval =device_property_string_array_count (psy->dev.parent,"supplied-from" ); -if (nval <=0 ) -return 0 ; - - psy->supplied_from =devm_kmalloc_array (&psy->dev, nval, -sizeof (char *),GFP_KERNEL ); -if (!psy->supplied_from) -return -ENOMEM ; - - ret =device_property_read_string_array (psy->dev.parent, -"supplied-from" , (const char **)psy->supplied_from, nval); -if (ret <0 ) -return ret; - - psy->num_supplies = nval; - -return 0 ; -} -#endif struct psy_am_i_supplied_data {struct power_supply *psy;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/4 power: supply: core: introduce power_supply_for_each_psy()
From: Thomas Weißschuh <[email protected]>
[ Upstream commit 9029409d1a250da19f1086ab1113752411c5163d ]
All existing callers of power_supply_for_each_device() want to iterate over 'struct power_supply', not 'struct device'.
The power_supply_for_each_device() forces each caller to duplicate the logic to go from one to the other.
Introduce power_supply_for_each_psy() to simplify the callers.
Stable-dep-of: 6bd80f22c764 ("power: supply: core: Honor supplied-from with CONFIG_OF=y")
--- drivers/power/supply/power_supply_core.c | 24 ++++++++++++++++++++++++ include/linux/power_supply.h | 1 + 2 files changed, 25 insertions(+)
drivers/power/supply/power_supply_core.c +24 -0
@@ -122,6 +122,30 @@ int power_supply_for_each_device(void *data, int (*fn)(struct device *dev, void }EXPORT_SYMBOL_GPL (power_supply_for_each_device); +struct psy_for_each_psy_cb_data { +int (*fn)(struct power_supply *psy,void *data); +void *data; +}; + +static int psy_for_each_psy_cb (struct device *dev,void *data) +{ +struct psy_for_each_psy_cb_data *cb_data = data; +struct power_supply *psy =dev_get_drvdata (dev); + +return cb_data->fn (psy, cb_data->data); +} + +int power_supply_for_each_psy (void *data,int (*fn)(struct power_supply *psy,void *data)) +{ +struct psy_for_each_psy_cb_data cb_data = { + .fn = fn, + .data = data, + }; + +return power_supply_for_each_device (&cb_data, psy_for_each_psy_cb); +} +EXPORT_SYMBOL_GPL (power_supply_for_each_psy); +void power_supply_changed (struct power_supply *psy) {unsigned long flags;
include/linux/power_supply.h +1 -0
@@ -890,6 +890,7 @@ extern int power_supply_powers(struct power_supply *psy, struct device *dev);extern void *power_supply_get_drvdata (struct power_supply *psy);extern int power_supply_for_each_device (void *data,int (*fn)(struct device *dev,void *data)); +extern int power_supply_for_each_psy (void *data,int (*fn)(struct power_supply *psy,void *data));static inline bool power_supply_is_amp_property (enum power_supply_property psp) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 power: supply: core: use power_supply_for_each_psy()
From: Thomas Weißschuh <[email protected]>
[ Upstream commit 68abaf7323ae857db7ec56a174b7bbf5fc687d47 ]
Simplify the callbacks by removing the need to convert a 'struct device' into a 'struct power_supply'.
Stable-dep-of: 6bd80f22c764 ("power: supply: core: Honor supplied-from with CONFIG_OF=y")
--- drivers/power/supply/power_supply_core.c | 36 ++++++++++-------------- 1 file changed, 15 insertions(+), 21 deletions(-)
drivers/power/supply/power_supply_core.c +15 -21
@@ -66,10 +66,9 @@ static bool __power_supply_is_supplied_by(struct power_supply *supplier,return false; } -static int __power_supply_changed_work (struct device *dev,void *data) +static int __power_supply_changed_work (struct power_supply *pst,void *data) {struct power_supply *psy = data; -struct power_supply *pst =dev_get_drvdata (dev);if (__power_supply_is_supplied_by (psy, pst)) {if (pst->desc->external_power_changed)
@@ -98,7 +97,7 @@ static void power_supply_changed_work(struct work_struct *work)if (likely (psy->changed)) { psy->changed = false;spin_unlock_irqrestore (&psy->changed_lock, flags); -power_supply_for_each_device (psy, __power_supply_changed_work); +power_supply_for_each_psy (psy, __power_supply_changed_work);power_supply_update_leds (psy);blocking_notifier_call_chain (&power_supply_notifier,PSY_EVENT_PROP_CHANGED , psy);
@@ -190,11 +189,10 @@ static void power_supply_deferred_register_work(struct work_struct *work) }#ifdef CONFIG_OF -static int __power_supply_populate_supplied_from (struct device *dev, +static int __power_supply_populate_supplied_from (struct power_supply *epsy,void *data) {struct power_supply *psy = data; -struct power_supply *epsy =dev_get_drvdata (dev);struct device_node *np;int i =0 ;
@@ -221,20 +219,19 @@ static int power_supply_populate_supplied_from(struct power_supply *psy) {int error; - error =power_supply_for_each_device (psy, __power_supply_populate_supplied_from); + error =power_supply_for_each_psy (psy, __power_supply_populate_supplied_from);dev_dbg (&psy->dev,"%s %d\n" , __func__, error);return error; } -static int __power_supply_find_supply_from_node (struct device *dev, +static int __power_supply_find_supply_from_node (struct power_supply *epsy,void *data) {struct device_node *np = data; -struct power_supply *epsy =dev_get_drvdata (dev); -/* returning non-zero breaks out of power_supply_for_each_device loop */ +/* returning non-zero breaks out of power_supply_for_each_psy loop */ if (epsy->of_node == np)return 1 ;
@@ -246,16 +243,16 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)int error;/* -* power_supply_for_each_device() either returns its own errors or values +* power_supply_for_each_psy() either returns its own errors or values * returned by __power_supply_find_supply_from_node(). * * __power_supply_find_supply_from_node() will return 0 (no match) * or 1 (match). * -* We return 0 if power_supply_for_each_device() returned 1, -EPROBE_DEFER if +* We return 0 if power_supply_for_each_psy() returned 1, -EPROBE_DEFER if * it returned 0, or error as returned by it. */ - error =power_supply_for_each_device (supply_node, __power_supply_find_supply_from_node); + error =power_supply_for_each_psy (supply_node, __power_supply_find_supply_from_node);return error ? (error ==1 ?0 : error) : -EPROBE_DEFER ; }
@@ -335,10 +332,9 @@ struct psy_am_i_supplied_data {unsigned int count; }; -static int __power_supply_am_i_supplied (struct device *dev,void *_data) +static int __power_supply_am_i_supplied (struct power_supply *epsy,void *_data) {union power_supply_propval ret = {0 ,}; -struct power_supply *epsy =dev_get_drvdata (dev);struct psy_am_i_supplied_data *data = _data;if (__power_supply_is_supplied_by (epsy, data->psy)) {
@@ -356,7 +352,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)struct psy_am_i_supplied_data data = { psy,0 };int error; - error =power_supply_for_each_device (&data, __power_supply_am_i_supplied); + error =power_supply_for_each_psy (&data, __power_supply_am_i_supplied);dev_dbg (&psy->dev,"%s count %u err %d\n" , __func__, data.count, error);
@@ -367,10 +363,9 @@ int power_supply_am_i_supplied(struct power_supply *psy) }EXPORT_SYMBOL_GPL (power_supply_am_i_supplied); -static int __power_supply_is_system_supplied (struct device *dev,void *data) +static int __power_supply_is_system_supplied (struct power_supply *psy,void *data) {union power_supply_propval ret = {0 ,}; -struct power_supply *psy =dev_get_drvdata (dev);unsigned int *count = data;if (!psy->desc->get_property (psy,POWER_SUPPLY_PROP_SCOPE , &ret))
@@ -391,7 +386,7 @@ int power_supply_is_system_supplied(void)int error;unsigned int count =0 ; - error =power_supply_for_each_device (&count, __power_supply_is_system_supplied); + error =power_supply_for_each_psy (&count, __power_supply_is_system_supplied);/* * If no system scope power class device was found at all, most probably we
@@ -410,9 +405,8 @@ struct psy_get_supplier_prop_data {union power_supply_propval *val; }; -static int __power_supply_get_supplier_property (struct device *dev,void *_data) +static int __power_supply_get_supplier_property (struct power_supply *epsy,void *_data) { -struct power_supply *epsy =dev_get_drvdata (dev);struct psy_get_supplier_prop_data *data = _data;if (__power_supply_is_supplied_by (epsy, data->psy))
@@ -437,7 +431,7 @@ int power_supply_get_property_from_supplier(struct power_supply *psy,* This function is not intended for use with a supply with multiple * suppliers, we simply pick the first supply to report the psp. */ - ret =power_supply_for_each_device (&data, __power_supply_get_supplier_property); + ret =power_supply_for_each_psy (&data, __power_supply_get_supplier_property);if (ret <0 )return ret;if (ret ==0 )
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/4 power: supply: core: get rid of of_node
In reply to Sasha LevinFrom: Sebastian Reichel <[email protected]>
[ Upstream commit 134254038739a6c6ecb7548a2f895d89a0dc9d2a ]
This removes .of_node from 'struct power_supply', since there is already a copy in .dev.of_node and there is no need to have two copies.
Stable-dep-of: 6bd80f22c764 ("power: supply: core: Honor supplied-from with CONFIG_OF=y")
--- drivers/power/supply/power_supply_core.c | 17 ++++++++--------- include/linux/power_supply.h | 1 - 2 files changed, 8 insertions(+), 10 deletions(-)
drivers/power/supply/power_supply_core.c +8 -9
@@ -197,11 +197,11 @@ static int __power_supply_populate_supplied_from(struct power_supply *epsy,int i =0 ; do { - np = of_parse_phandle(psy->of_node, "power-supplies", i++); + np = of_parse_phandle(psy->dev.of_node, "power-supplies", i++); if (!np) break; - if (np == epsy->of_node) { + if (np == epsy->dev.of_node) { dev_dbg(&psy->dev, "%s: Found supply : %s\n", psy->desc->name, epsy->desc->name); psy->supplied_from[i-1] = (char *)epsy->desc->name;
@@ -232,7 +232,7 @@ static int __power_supply_find_supply_from_node(struct power_supply *epsy,struct device_node *np = data;/* returning non-zero breaks out of power_supply_for_each_psy loop */ -if (epsy->of_node == np) +if (epsy->dev.of_node == np)return 1 ;return 0 ;
@@ -267,13 +267,13 @@ static int power_supply_check_supplies(struct power_supply *psy)return 0 ;/* No device node found, nothing to do */ -if (!psy->of_node) +if (!psy->dev.of_node)return 0 ; do { int ret; - np = of_parse_phandle(psy->of_node, "power-supplies", cnt++); + np = of_parse_phandle(psy->dev.of_node, "power-supplies", cnt++); if (!np) break;
@@ -598,8 +598,8 @@ int power_supply_get_battery_info(struct power_supply *psy,const __be32 *list;u32 min_max[2 ]; -if (psy->of_node) { - battery_np =of_parse_phandle (psy->of_node,"monitored-battery" ,0 ); +if (psy->dev.of_node) { + battery_np =of_parse_phandle (psy->dev.of_node,"monitored-battery" ,0 );if (!battery_np)return -ENODEV ;
@@ -1384,9 +1384,8 @@ __power_supply_register(struct device *parent,if (cfg) { dev->groups = cfg->attr_grp; psy->drv_data = cfg->drv_data; - psy->of_node = + dev->of_node = cfg->fwnode ?to_of_node (cfg->fwnode) : cfg->of_node; - dev->of_node = psy->of_node; psy->supplied_to = cfg->supplied_to; psy->num_supplicants = cfg->num_supplicants; }
include/linux/power_supply.h +0 -1
@@ -287,7 +287,6 @@ struct power_supply {char **supplied_from;size_t num_supplies; -struct device_node *of_node;/* Driver private data */ void *drv_data;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/4 power: supply: core: Honor supplied-from with CONFIG_OF=y
In reply to Sasha LevinFrom: Maurizio Casciano <[email protected]>
[ Upstream commit 6bd80f22c764fe8c56c62c118387f86a3ca98cff ]
The supplied-from device property is the name-based counterpart to firmware-node power-supplies references. It was added for non-DT platforms, but its parser is compiled only when CONFIG_OF is disabled. CONFIG_OF is a global kernel option, so x86 systems commonly enable it even when individual power supplies are described by software nodes.
Consequently, these consumers never populate supplied_from and supplier notifications do not reach their external_power_changed() callbacks. On a Lenovo Yoga Book YB1-X91L, ftrace showed the Whiskey Cove supplier notification running without invoking the BQ25892 callback, leaving the input current limit at its boot-time value.
Use a single power_supply_check_supplies() implementation for all configurations. Preserve firmware-node power-supplies references as the preferred firmware description and use the name-based supplied-from property only when no references are specified. Continue to honor an explicitly provided supplied_from list first and propagate errors from specified firmware references.
With the fix, ftrace shows the BQ25892 callback on hotplug. A boot-offline test changes its input current limit from 500 mA to 2 A.
--- drivers/power/supply/power_supply_core.c | 90 ++++++++++++------------ 1 file changed, 45 insertions(+), 45 deletions(-)
drivers/power/supply/power_supply_core.c +45 -45
@@ -188,7 +188,35 @@ static void power_supply_deferred_register_work(struct work_struct *work)mutex_unlock (&psy->dev.parent->mutex); } -#ifdef CONFIG_OF +static int power_supply_check_supplies_by_name (struct power_supply *psy) +{ +struct device *parent = psy->dev.parent; +int nval, ret; + +if (!parent) +return 0 ; + + nval =device_property_string_array_count (parent,"supplied-from" ); +if (nval <=0 ) +return 0 ; + + psy->supplied_from =devm_kmalloc_array (&psy->dev, nval, +sizeof (*psy->supplied_from), +GFP_KERNEL ); +if (!psy->supplied_from) +return -ENOMEM ; + + ret =device_property_read_string_array (parent,"supplied-from" , + (const char **)psy->supplied_from, + nval); +if (ret <0 ) +return ret; + + psy->num_supplies = nval; + +return 0 ; +} +static int __power_supply_populate_supplied_from (struct power_supply *epsy,void *data) {
@@ -259,73 +287,45 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)static int power_supply_check_supplies (struct power_supply *psy) { -struct device_node *np; -int cnt =0 ; +struct of_phandle_args args; +int cnt, ret;/* If there is already a list honor it */ if (psy->supplied_from && psy->num_supplies >0 )return 0 ; -/* No device node found, nothing to do */ -if (!psy->dev.of_node) -return 0 ; - -do { -int ret; +for (cnt =0 ; psy->dev.of_node; cnt++) { + ret =of_parse_phandle_with_fixed_args (psy->dev.of_node, +"power-supplies" ,0 , cnt, &args); +if (ret) { +if (ret != -ENOENT ) +return ret; - np =of_parse_phandle (psy->dev.of_node,"power-supplies" , cnt++); -if (!np)break ; + } - ret =power_supply_find_supply_from_node (np); -of_node_put (np); + ret =power_supply_find_supply_from_node (args.np); +of_node_put (args.np);if (ret) {dev_dbg (&psy->dev,"Failed to find supply!\n" );return ret; } - }while (np); + } -/* Missing valid "power-supplies" entries */ -if (cnt ==1 ) -return 0 ; +/* Fall back to the name-based property if no references were specified. */ +if (!cnt) +return power_supply_check_supplies_by_name (psy);/* All supplies found, allocate char * array for filling */ psy->supplied_from =devm_kcalloc (&psy->dev, - cnt -1 ,sizeof (*psy->supplied_from), + cnt,sizeof (*psy->supplied_from),GFP_KERNEL );if (!psy->supplied_from)return -ENOMEM ;return power_supply_populate_supplied_from (psy); } -#else -static int power_supply_check_supplies (struct power_supply *psy) -{ -int nval, ret; - -if (!psy->dev.parent) -return 0 ; - - nval =device_property_string_array_count (psy->dev.parent,"supplied-from" ); -if (nval <=0 ) -return 0 ; - - psy->supplied_from =devm_kmalloc_array (&psy->dev, nval, -sizeof (char *),GFP_KERNEL ); -if (!psy->supplied_from) -return -ENOMEM ; - - ret =device_property_read_string_array (psy->dev.parent, -"supplied-from" , (const char **)psy->supplied_from, nval); -if (ret <0 ) -return ret; - - psy->num_supplies = nval; - -return 0 ; -} -#endif struct psy_am_i_supplied_data {struct power_supply *psy;
Signature · 1 line
2.53.0