power: supply: sysfs: Ratelimit "unavailable enum value" warning
PATCH 1/1 power: supply: sysfs: Ratelimit "unavailable enum value" warning
power_supply_show_enum_with_available() warns every time a driver reports a value that is not in its declared set of available values. For usb_type this happens on every sysfs read and on every uevent, so a driver that reports such a value and calls power_supply_changed() frequently can flood the kernel log.
This can happen with drivers that pass a firmware-provided value through unchanged, as qcom_battmgr does for usb_type. On a OnePlus 10 Pro (SM8450), whose firmware reports a vendor-specific usb_type, this produced ~128 warnings per second and kept systemd-journald at ~30% CPU.
The bug that causes the bad value needs fixing in the driver itself, but one misbehaving driver should not be able to flood the kernel log. Use dev_warn_ratelimited(), as power_supply_show_property() already does for its own errors, so the problem is still reported, just not on every read.
--- drivers/power/supply/power_supply_sysfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/power/supply/power_supply_sysfs.c +2 -1
@@ -310,7 +310,8 @@ static ssize_t power_supply_show_enum_with_available( }if (!match) { -dev_warn (dev,"driver reporting unavailable enum value %d\n" , value); +dev_warn_ratelimited (dev,"driver reporting unavailable enum value %d\n" , + value);return -EINVAL ; }
---
base-commit: 4fc88ba435dadbc05990951e3f3fbd8ccd2df140
change-id: 20261002-ratelimit-enum-warn-f360abcae8be
Best regards,
Signature · 1 line
Robert Killick <[email protected]>
Sebastian Reichel
AppliedQuoted 6 lines · Robert Killick
power_supply_show_enum_with_available()warns every time a driver reports a value that is not in its declared set of available values. Forusb_typethis happens on every sysfs read and on every uevent, so a driver that reports such a value and callspower_supply_changed()frequently can flood the kernel log.
Quoted 6 lines
This can happen with drivers that pass a firmware-provided value through unchanged, as
qcom_battmgrdoes forusb_type. On a OnePlus 10 Pro (SM8450), whose firmware reports a vendor-specificusb_type, this produced ~128 warnings per second and kept systemd-journald at ~30% CPU.[...]
Applied, thanks!
[1/1] power: supply: sysfs: Ratelimit "unavailable enum value" warning
commit: 4d49915df53ddde71556e507bdc49b81cd4609c8
Best regards,
Signature · 1 line
Sebastian Reichel <[email protected]>