All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/5] power_supply: errno, hwmon rollback and docs/ABI sync
@ 2026-08-31 15:53 Iván Ezequiel Rodriguez
  2026-08-31 15:53 ` [PATCH v1 1/5] power: return -ENOMEM on OCV table alloc failure Iván Ezequiel Rodriguez
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Iván Ezequiel Rodriguez @ 2026-08-31 15:53 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux-pm, linux-kernel, Rafael J . Wysocki,
	Iván Ezequiel Rodriguez

Hi,

Small power_supply hygiene on top of v7.3-rc1.

Patch 1 returns -ENOMEM when OCV table allocation fails (was -EINVAL).
Patch 2 best-effort recreates hwmon after register_extension() rolls
back a failed update_sysfs_and_hwmon() that already removed the old
hwmon group.
Patches 3-4 align Documentation/power/power_supply_class.rst and the
sysfs-class-power ABI type values with the current enums/strings.
Patch 5 replaces spaces with tabs in get_property_direct().

Base: v7.3-rc1

Tested: built drivers/power/supply/power_supply_core.o with
CONFIG_POWER_SUPPLY=y; checkpatch clean on 0001-0005.

Thanks,
Iván

Iván Ezequiel Rodriguez (5):
  power: return -ENOMEM on OCV table alloc failure
  power: restore hwmon if extension update fails
  docs: power: fix power_supply_class.rst status, health and time_to
  docs: ABI: complete power_supply type valid values
  power: use tabs in power_supply_get_property_direct

 Documentation/ABI/testing/sysfs-class-power |  4 +++-
 Documentation/power/power_supply_class.rst  | 26 +++++++++++++-------------
 drivers/power/supply/power_supply_core.c    | 14 ++++++++++++--
 3 files changed, 28 insertions(+), 16 deletions(-)

-- 
2.43.0

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

* [PATCH v1 1/5] power: return -ENOMEM on OCV table alloc failure
  2026-08-31 15:53 [PATCH v1 0/5] power_supply: errno, hwmon rollback and docs/ABI sync Iván Ezequiel Rodriguez
@ 2026-08-31 15:53 ` Iván Ezequiel Rodriguez
  2026-08-31 15:53 ` [PATCH v1 2/5] power: restore hwmon if extension update fails Iván Ezequiel Rodriguez
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Iván Ezequiel Rodriguez @ 2026-08-31 15:53 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux-pm, linux-kernel, Rafael J . Wysocki,
	Iván Ezequiel Rodriguez

power_supply_get_battery_info() maps a failed kcalloc() for the OCV
capacity table to -EINVAL. Return -ENOMEM instead, matching the
resistance-temp-table allocation path in the same function.

Signed-off-by: Iván Ezequiel Rodriguez <ivanrwcm25@gmail.com>
---
 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 00d8bc98d588..f550f70ca586 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -907,7 +907,7 @@ int power_supply_get_battery_info(struct power_supply *psy,
 		u32 *propdata __free(kfree) = kcalloc(proplen, sizeof(*propdata), GFP_KERNEL);
 		if (!propdata) {
 			power_supply_put_battery_info(psy, info);
-			err = -EINVAL;
+			err = -ENOMEM;
 			goto out_put_node;
 		}
 		err = fwnode_property_read_u32_array(fwnode, propname, propdata, proplen);
-- 
2.43.0


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

* [PATCH v1 2/5] power: restore hwmon if extension update fails
  2026-08-31 15:53 [PATCH v1 0/5] power_supply: errno, hwmon rollback and docs/ABI sync Iván Ezequiel Rodriguez
  2026-08-31 15:53 ` [PATCH v1 1/5] power: return -ENOMEM on OCV table alloc failure Iván Ezequiel Rodriguez
@ 2026-08-31 15:53 ` Iván Ezequiel Rodriguez
  2026-08-31 15:53 ` [PATCH v1 3/5] docs: power: fix power_supply_class.rst status, health and time_to Iván Ezequiel Rodriguez
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Iván Ezequiel Rodriguez @ 2026-08-31 15:53 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux-pm, linux-kernel, Rafael J . Wysocki,
	Iván Ezequiel Rodriguez

power_supply_update_sysfs_and_hwmon() removes the existing hwmon group
before recreating it. If recreation fails, register_extension() rolled
back the extension but left hwmon absent.

After tearing down the failed extension, best-effort recreate hwmon so
the supply keeps its previous monitoring attributes when possible.

Signed-off-by: Iván Ezequiel Rodriguez <ivanrwcm25@gmail.com>
---
 drivers/power/supply/power_supply_core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index f550f70ca586..c041806f4f9e 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -1595,6 +1595,16 @@ int power_supply_register_extension(struct power_supply *psy, const struct power
 
 sysfs_hwmon_failed:
 	power_supply_sysfs_remove_extension(psy, ext);
+	list_del(&reg->list_head);
+	kfree(reg);
+	/*
+	 * update_sysfs_and_hwmon() may have already torn down hwmon before
+	 * failing to recreate it. Recreate without the failed extension.
+	 */
+	if (power_supply_add_hwmon_sysfs(psy))
+		dev_warn(&psy->dev, "failed to restore hwmon after extension error\n");
+	return ret;
+
 sysfs_add_failed:
 	list_del(&reg->list_head);
 	kfree(reg);
-- 
2.43.0


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

* [PATCH v1 3/5] docs: power: fix power_supply_class.rst status, health and time_to
  2026-08-31 15:53 [PATCH v1 0/5] power_supply: errno, hwmon rollback and docs/ABI sync Iván Ezequiel Rodriguez
  2026-08-31 15:53 ` [PATCH v1 1/5] power: return -ENOMEM on OCV table alloc failure Iván Ezequiel Rodriguez
  2026-08-31 15:53 ` [PATCH v1 2/5] power: restore hwmon if extension update fails Iván Ezequiel Rodriguez
@ 2026-08-31 15:53 ` Iván Ezequiel Rodriguez
  2026-08-31 15:53 ` [PATCH v1 4/5] docs: ABI: complete power_supply type valid values Iván Ezequiel Rodriguez
  2026-08-31 15:53 ` [PATCH v1 5/5] power: use tabs in power_supply_get_property_direct Iván Ezequiel Rodriguez
  4 siblings, 0 replies; 6+ messages in thread
From: Iván Ezequiel Rodriguez @ 2026-08-31 15:53 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux-pm, linux-kernel, Rafael J . Wysocki,
	Iván Ezequiel Rodriguez

Correct STATUS/HEALTH references to POWER_SUPPLY_* enums in
include/linux/power_supply.h instead of the nonexistent battery.h
macros. Document TIME_TO_{EMPTY,FULL}_{NOW,AVG}, fix the "operatable"
typo, and note that MODEL_NAME and MANUFACTURER already exist.

Signed-off-by: Iván Ezequiel Rodriguez <ivanrwcm25@gmail.com>
---
 Documentation/power/power_supply_class.rst | 26 +++++++++++-----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/Documentation/power/power_supply_class.rst b/Documentation/power/power_supply_class.rst
index 6d11f8c594a0..c60aa7ce717b 100644
--- a/Documentation/power/power_supply_class.rst
+++ b/Documentation/power/power_supply_class.rst
@@ -82,7 +82,8 @@ _NOW
 STATUS
   this attribute represents operating status (charging, full,
   discharging (i.e., powering a load), etc.). This corresponds to
-  `BATTERY_STATUS_*` values, as defined in battery.h.
+  `POWER_SUPPLY_STATUS_*` values, as defined in
+  include/linux/power_supply.h.
 
 CHARGE_TYPE
   batteries can typically charge at different rates.
@@ -95,8 +96,8 @@ AUTHENTIC
   to the platform is authentic(1) or non-authentic(0).
 
 HEALTH
-  represents health of the battery. Values corresponds to
-  POWER_SUPPLY_HEALTH_*, defined in battery.h.
+  represents health of the battery. Values correspond to
+  POWER_SUPPLY_HEALTH_*, defined in include/linux/power_supply.h.
 
 VOLTAGE_OCV
   open circuit voltage of the battery.
@@ -202,16 +203,17 @@ TEMP_AMBIENT_ALERT_MIN
 TEMP_AMBIENT_ALERT_MAX
   maximum ambient temperature alert.
 TEMP_MIN
-  minimum operatable temperature
+  minimum operable temperature
 TEMP_MAX
-  maximum operatable temperature
+  maximum operable temperature
 
-TIME_TO_EMPTY
+TIME_TO_EMPTY_NOW, TIME_TO_EMPTY_AVG
   seconds left for battery to be considered empty
-  (i.e., while battery powers a load)
-TIME_TO_FULL
+  (i.e., while battery powers a load). *_NOW is a
+  momentary reading; *_AVG is averaged over a fixed period.
+TIME_TO_FULL_NOW, TIME_TO_FULL_AVG
   seconds left for battery to be considered full
-  (i.e., while battery is charging)
+  (i.e., while battery is charging). Same now/avg distinction.
 
 
 Battery <-> external power supply interaction
@@ -251,10 +253,8 @@ A:
    to add it and send a patch along with your driver.
 
    The attributes available currently are the ones currently provided by the
-   drivers written.
-
-   Good candidates to add in future: model/part#, cycle_time, manufacturer,
-   etc.
+   drivers written. MODEL_NAME and MANUFACTURER are already part of the
+   standard attribute set.
 
 
 Q:
-- 
2.43.0


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

* [PATCH v1 4/5] docs: ABI: complete power_supply type valid values
  2026-08-31 15:53 [PATCH v1 0/5] power_supply: errno, hwmon rollback and docs/ABI sync Iván Ezequiel Rodriguez
                   ` (2 preceding siblings ...)
  2026-08-31 15:53 ` [PATCH v1 3/5] docs: power: fix power_supply_class.rst status, health and time_to Iván Ezequiel Rodriguez
@ 2026-08-31 15:53 ` Iván Ezequiel Rodriguez
  2026-08-31 15:53 ` [PATCH v1 5/5] power: use tabs in power_supply_get_property_direct Iván Ezequiel Rodriguez
  4 siblings, 0 replies; 6+ messages in thread
From: Iván Ezequiel Rodriguez @ 2026-08-31 15:53 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux-pm, linux-kernel, Rafael J . Wysocki,
	Iván Ezequiel Rodriguez

sysfs type already exposes USB_DCP/CDP/ACA, USB_C, USB_PD,
USB_PD_DRP, BrickID and Unknown via POWER_SUPPLY_TYPE_TEXT[]. Update
the ABI document so Valid values match the implementation.

Signed-off-by: Iván Ezequiel Rodriguez <ivanrwcm25@gmail.com>
---
 Documentation/ABI/testing/sysfs-class-power | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power
index 5641f1fd5fd6..08afb75973d2 100644
--- a/Documentation/ABI/testing/sysfs-class-power
+++ b/Documentation/ABI/testing/sysfs-class-power
@@ -34,7 +34,9 @@ Description:
 		Describes the main type of the supply.
 
 		Access: Read
-		Valid values: "Battery", "UPS", "Mains", "USB", "Wireless"
+		Valid values: "Unknown", "Battery", "UPS", "Mains", "USB",
+		"USB_DCP", "USB_CDP", "USB_ACA", "USB_C", "USB_PD",
+		"USB_PD_DRP", "BrickID", "Wireless"
 
 **Battery and USB properties**
 
-- 
2.43.0


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

* [PATCH v1 5/5] power: use tabs in power_supply_get_property_direct
  2026-08-31 15:53 [PATCH v1 0/5] power_supply: errno, hwmon rollback and docs/ABI sync Iván Ezequiel Rodriguez
                   ` (3 preceding siblings ...)
  2026-08-31 15:53 ` [PATCH v1 4/5] docs: ABI: complete power_supply type valid values Iván Ezequiel Rodriguez
@ 2026-08-31 15:53 ` Iván Ezequiel Rodriguez
  4 siblings, 0 replies; 6+ messages in thread
From: Iván Ezequiel Rodriguez @ 2026-08-31 15:53 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux-pm, linux-kernel, Rafael J . Wysocki,
	Iván Ezequiel Rodriguez

The return statement was indented with spaces; use tabs to match
kernel coding style and silence checkpatch.

Signed-off-by: Iván Ezequiel Rodriguez <ivanrwcm25@gmail.com>
---
 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 c041806f4f9e..8f464583c5b0 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -1442,7 +1442,7 @@ EXPORT_SYMBOL_GPL(power_supply_get_property);
 int power_supply_get_property_direct(struct power_supply *psy, enum power_supply_property psp,
 				     union power_supply_propval *val)
 {
-        return __power_supply_get_property(psy, psp, val, false);
+	return __power_supply_get_property(psy, psp, val, false);
 }
 EXPORT_SYMBOL_GPL(power_supply_get_property_direct);
 
-- 
2.43.0


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

end of thread, other threads:[~2026-08-31 15:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 15:53 [PATCH v1 0/5] power_supply: errno, hwmon rollback and docs/ABI sync Iván Ezequiel Rodriguez
2026-08-31 15:53 ` [PATCH v1 1/5] power: return -ENOMEM on OCV table alloc failure Iván Ezequiel Rodriguez
2026-08-31 15:53 ` [PATCH v1 2/5] power: restore hwmon if extension update fails Iván Ezequiel Rodriguez
2026-08-31 15:53 ` [PATCH v1 3/5] docs: power: fix power_supply_class.rst status, health and time_to Iván Ezequiel Rodriguez
2026-08-31 15:53 ` [PATCH v1 4/5] docs: ABI: complete power_supply type valid values Iván Ezequiel Rodriguez
2026-08-31 15:53 ` [PATCH v1 5/5] power: use tabs in power_supply_get_property_direct Iván Ezequiel Rodriguez

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.