Linux ACPI
 help / color / mirror / Atom feed
* [PATCH] acpi: battery: Sanitise model_number by dropping unprintable characters
@ 2026-07-08  7:07 Kate Hsuan
  2026-07-09 13:38 ` Rafael J. Wysocki (Intel)
  0 siblings, 1 reply; 4+ messages in thread
From: Kate Hsuan @ 2026-07-08  7:07 UTC (permalink / raw)
  To: Mark Pearson, Rafael J . Wysocki, Len Brown
  Cc: linux-acpi, linux-kernel, Kate Hsuan

The battery Embedded Controller (EC) may return the model name with
trailing unprintable or non-ASCII characters. For example, on some systems:

$ cat /sys/class/power_supply/BAT0/model_name
LNV-5B10W51864��

Strip these unprintable characters to ensure the model_name attribute
contains a valid string. If left intact, these malformed strings prevent
udev rules and hwdb from matching the attribute correctly.

Link: https://gitlab.freedesktop.org/upower/upower/-/work_items/345

Signed-off-by: Kate Hsuan <hpa@redhat.com>
---
 drivers/acpi/battery.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index f5e0eb299610..dea0c3cc5160 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -10,6 +10,7 @@
 
 #define pr_fmt(fmt) "ACPI: battery: " fmt
 
+#include <linux/ctype.h>
 #include <linux/delay.h>
 #include <linux/dmi.h>
 #include <linux/jiffies.h>
@@ -194,6 +195,21 @@ static int acpi_battery_handle_discharging(struct acpi_battery *battery)
 	return POWER_SUPPLY_STATUS_DISCHARGING;
 }
 
+static void acpi_battery_remove_special_chars(char *str)
+{
+	char *out = str;
+	unsigned int i = 0;
+
+	while (*str && i < MAX_STRING_LENGTH) {
+		unsigned char c = *str++;
+
+		if (isascii(c) && isprint(c))
+			*out++ = c;
+		i++;
+	}
+	*out = '\0';
+}
+
 static int acpi_battery_get_property(struct power_supply *psy,
 				     enum power_supply_property psp,
 				     union power_supply_propval *val)
@@ -524,6 +540,9 @@ static int extract_battery_info(const int use_bix,
 	    battery->capacity_now > battery->full_charge_capacity)
 		battery->capacity_now = battery->full_charge_capacity;
 
+	if (!result)
+		acpi_battery_remove_special_chars(battery->model_number);
+
 	return result;
 }
 
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] acpi: battery: Sanitise model_number by dropping unprintable characters
@ 2026-07-08  7:07 Kate Hsuan
  0 siblings, 0 replies; 4+ messages in thread
From: Kate Hsuan @ 2026-07-08  7:07 UTC (permalink / raw)
  To: hpa; +Cc: linux-acpi, linux-kernel

The battery Embedded Controller (EC) may return the model name with
trailing unprintable or non-ASCII characters. For example, on some systems:

$ cat /sys/class/power_supply/BAT0/model_name
LNV-5B10W51864��

Strip these unprintable characters to ensure the model_name attribute
contains a valid string. If left intact, these malformed strings prevent
udev rules and hwdb from matching the attribute correctly.

Link: https://gitlab.freedesktop.org/upower/upower/-/work_items/345

Signed-off-by: Kate Hsuan <hpa@redhat.com>
---
 drivers/acpi/battery.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index f5e0eb299610..dea0c3cc5160 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -10,6 +10,7 @@
 
 #define pr_fmt(fmt) "ACPI: battery: " fmt
 
+#include <linux/ctype.h>
 #include <linux/delay.h>
 #include <linux/dmi.h>
 #include <linux/jiffies.h>
@@ -194,6 +195,21 @@ static int acpi_battery_handle_discharging(struct acpi_battery *battery)
 	return POWER_SUPPLY_STATUS_DISCHARGING;
 }
 
+static void acpi_battery_remove_special_chars(char *str)
+{
+	char *out = str;
+	unsigned int i = 0;
+
+	while (*str && i < MAX_STRING_LENGTH) {
+		unsigned char c = *str++;
+
+		if (isascii(c) && isprint(c))
+			*out++ = c;
+		i++;
+	}
+	*out = '\0';
+}
+
 static int acpi_battery_get_property(struct power_supply *psy,
 				     enum power_supply_property psp,
 				     union power_supply_propval *val)
@@ -524,6 +540,9 @@ static int extract_battery_info(const int use_bix,
 	    battery->capacity_now > battery->full_charge_capacity)
 		battery->capacity_now = battery->full_charge_capacity;
 
+	if (!result)
+		acpi_battery_remove_special_chars(battery->model_number);
+
 	return result;
 }
 
-- 
2.55.0


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

end of thread, other threads:[~2026-07-10  7:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08  7:07 [PATCH] acpi: battery: Sanitise model_number by dropping unprintable characters Kate Hsuan
2026-07-09 13:38 ` Rafael J. Wysocki (Intel)
2026-07-10  7:02   ` Kate Hsuan
  -- strict thread matches above, loose matches on Subject: below --
2026-07-08  7:07 Kate Hsuan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox