Skip to contentSkip to conversation

power_supply: errno, hwmon rollback and docs/ABI sync

PATCH Applied Iván Ezequiel Rodriguez 2 participants 8 messages Aug 31 – Oct 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover power_supply: errno, hwmon rollback and docs/ABI sync

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(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/5 power: return -ENOMEM on OCV table alloc failure

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.

---
 drivers/power/supply/power_supply_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/power_supply_core.c +1 -1
index 00d8bc98d588..f550f70ca586 100644
@@ -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);
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/5 power: restore hwmon if extension update fails

In reply to 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.

---
 drivers/power/supply/power_supply_core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/power/supply/power_supply_core.c +10 -0
index f550f70ca586..c041806f4f9e 100644
@@ -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);
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/5 docs: power: fix power_supply_class.rst status, health and time_to

In reply to 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.

---
 Documentation/power/power_supply_class.rst | 26 +++++++++++-----------
 1 file changed, 13 insertions(+), 13 deletions(-)
Documentation/power/power_supply_class.rst +13 -13
index 6d11f8c594a0..c60aa7ce717b 100644
@@ -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:
Signature · 1 line
2.43.0
#4 lore raw

PATCH 4/5 docs: ABI: complete power_supply type valid values

In reply to 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.

---
 Documentation/ABI/testing/sysfs-class-power | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-class-power +3 -1
index 5641f1fd5fd6..08afb75973d2 100644
@@ -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**
 
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v1 4/5] docs: ABI: complete power_supply type valid values

Hi,

Quoted 14 lines · 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.

---
 Documentation/ABI/testing/sysfs-class-power | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-class-power +0 -0
index 5641f1fd5fd6..08afb75973d2 100644

Documentation/ABI/testing/sysfs-class-power Description: · line 39

Quoted 7 lines
Documentation/ABI/testing/sysfs-class-power +3 -1
@@ -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"

The USB sub-types should have a marking, that they are deprecated in favour of using just "USB" and additionally exposing USB_TYPE. There is only a small amount of legacy drivers still using the subtypes directly.

Greetings,

-- Sebastian

#6 lore raw

PATCH 5/5 power: use tabs in power_supply_get_property_direct

In reply to Iván Ezequiel Rodriguez

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

---
 drivers/power/supply/power_supply_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/power_supply_core.c +1 -1
index c041806f4f9e..8f464583c5b0 100644
@@ -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);
 
Signature · 1 line
2.43.0
#7 lore raw

Re: (subset) [PATCH v1 0/5] power_supply: errno, hwmon rollback and docs/ABI sync

In reply to Iván Ezequiel Rodriguez
Quoted 11 lines · Iván Ezequiel Rodriguez

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().

[...]

Applied, thanks!

[1/5] power: return -ENOMEM on OCV table alloc failure

      commit: 2648e3d4ca08014eb6125d96acb177e767d7c807
[2/5] power: restore hwmon if extension update fails
      commit: c996fa11ce8616aa3e8f5ebc34aa31a73dafac60
[3/5] docs: power: fix power_supply_class.rst status, health and time_to
      commit: 420a1e2763b5df3ed90f92d97cf30fe43822bba8
[5/5] power: use tabs in power_supply_get_property_direct
      commit: 27049920d0cf0396242f517dfdf2694e7b8daa67

Best regards,

Signature · 1 line
Sebastian Reichel <[email protected]>