https://bugzilla.kernel.org/show_bug.cgi?id=219956

            Bug ID: 219956
           Summary: Duplicate `POWER_SUPPLY_TYPE` Entries in Battery
                    Uevent on Linux 6.14.0
           Product: ACPI
           Version: 2.5
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P3
         Component: Power-Battery
          Assignee: acpi_power-batt...@kernel-bugs.osdl.org
          Reporter: grazzol...@archlinux.org
        Regression: No

## Issue Description

On Linux kernel **6.14.0** (observed on Arch Linux 6.14.0-arch1-1), the
battery's uevent file (`/sys/class/power_supply/BAT0/uevent`) contains
**duplicate entries** for the key `POWER_SUPPLY_TYPE`. This means the line
`POWER_SUPPLY_TYPE=Battery` appears twice. The issue was discovered when a
user-space battery monitoring tool (using Python’s ConfigParser to parse the
uevent content) failed due to encountering a repeated key (ConfigParser throws
an error on duplicate keys). 

This **regression** appears to be introduced in kernel 6.14.0, likely related
to the **supply: Introduce a mechanism for drivers to extend the properties
implemented by a power supply** that landed in 6.14.0. The new
uevent-generation code in the power supply subsystem adds the battery **type**
field twice – once explicitly and once again when iterating through all
properties – leading to the duplicate `POWER_SUPPLY_TYPE` entry
([linux/drivers/power/supply/power_supply_sysfs.c at master · torvalds/linux ·
GitHub](https://github.com/torvalds/linux/blob/master/drivers/power/supply/power_supply_sysfs.c#:~:text=ret%20%3D%20add_prop_uevent,prop_buf)).
Previous kernels (e.g. 6.13) did not exhibit this behavior.

## Steps to Reproduce

1. Boot into a system running Linux **6.14.0** (e.g. Arch Linux 6.14.0-arch1-1)
with an ACPI-managed battery (standard laptop battery driver).  
2. View the battery uevent data, for example by running:  
   ```bash
   cat /sys/class/power_supply/BAT0/uevent
   ```  
3. Observe that the output contains **two lines** for `POWER_SUPPLY_TYPE` (both
showing `Battery`), whereas each key should normally appear only once.

## Example Uevent Output

Below is an excerpt of the `BAT0/uevent` output on kernel 6.14.0, demonstrating
the duplicated **POWER_SUPPLY_TYPE** lines:

```text
POWER_SUPPLY_NAME=BAT0  
POWER_SUPPLY_TYPE=Battery  
POWER_SUPPLY_STATUS=Not charging  
POWER_SUPPLY_PRESENT=1  
POWER_SUPPLY_TECHNOLOGY=Li-ion  
POWER_SUPPLY_CYCLE_COUNT=100  
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11400000  
POWER_SUPPLY_VOLTAGE_NOW=11530000  
POWER_SUPPLY_ENERGY_FULL_DESIGN=40000000  
POWER_SUPPLY_ENERGY_FULL=32000000  
POWER_SUPPLY_ENERGY_NOW=18000000  
POWER_SUPPLY_CAPACITY=56  
POWER_SUPPLY_CAPACITY_LEVEL=Normal  
POWER_SUPPLY_MODEL_NAME=ABC1234  
POWER_SUPPLY_MANUFACTURER=BatteryCo  
POWER_SUPPLY_SERIAL_NUMBER=1234  
POWER_SUPPLY_TYPE=Battery   # <-- appears again, duplicate
```

*(Note: The numeric values above are examples; the key point is that
`POWER_SUPPLY_TYPE=Battery` is listed twice.)*

## System Details

- **OS / Distro:** Arch Linux (x86_64)  
- **Kernel Version:** 6.14.0-arch1-1 (based on mainline 6.14.0)  
- **Subsystem:** ACPI battery (power supply class driver for a laptop battery)  
- **Hardware:** Lenovo ThinkPad (internal battery) – ACPI `BAT0` device.  
- **Regression:** This issue was not present on earlier kernels (the uevent
output had unique keys on 6.13.x and below). It likely arose from changes in
the power supply class in 6.14.0.

## Analysis

The duplicate key appears to be caused by a change in the **power supply
class’s uevent formatting** introduced in 6.14. In the power supply core code
(`drivers/power/supply/power_supply_sysfs.c`), the kernel now generates uevent
entries by first adding the `POWER_SUPPLY_TYPE` and then iterating through all
properties. If the **Type** property isn’t excluded from the loop, it gets
added a second time. This corresponds with the new “power supply property
extensions” feature in 6.14 ([Linux_6.14 - Linux Kernel
Newbies](https://kernelnewbies.org/Linux_6.14#:~:text=,commit%2C%20commit%2C%20commit%2C%20commit)).
The relevant code shows that `POWER_SUPPLY_TYPE` is added unconditionally and
then all properties (including type) are added in a loop, causing the
duplication ([linux/drivers/power/supply/power_supply_sysfs.c at master ·
torvalds/linux ·
GitHub](https://github.com/torvalds/linux/blob/master/drivers/power/supply/power_supply_sysfs.c#:~:text=ret%20%3D%20add_prop_uevent,prop_buf)).
 

**Impact on Users:** Most users wouldn’t manually notice the duplicate line,
but programs that parse this file may break. For example, Python’s
`configparser` or other INI/sysfs parsers typically expect unique keys; a
duplicate `POWER_SUPPLY_TYPE` entry can lead to parse errors or incorrect
behavior in power management tools.

**Expected Behavior:** Each key in the uevent sysfs output should appear only
**once**. There should be a single `POWER_SUPPLY_TYPE=Battery` line. Duplicate
entries are not expected and serve no purpose, and they violate the assumption
of unique key-value pairs in the uevent data.

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

_______________________________________________
acpi-bugzilla mailing list
acpi-bugzilla@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/acpi-bugzilla

Reply via email to