Package: libsensors5
Version: 1:3.6.0-7.1 arm64
Severity: normal
Tags: patch upstream
X-Debbugs-Cc: michael.lettr...@cern.ch, federico.v...@cern.ch

Dear Maintainer,

we have found an issue in libsensors that occurs when parsing the chip
address of ISA sensors resulting in an incorrect ISA address.

The ISA sensor chip address of a sensor is obtained by parsing the
"device" symlink of an hwmon device. The regular expression extracting
the device address will fail if the "device" symlink contains dashes
and sets the address to 0. If multiple instances of the same board are
plugged into the same system, cards can no longer be distinguished, as
they all will  be incorrectly be assigned an address of 0.

Example: 
const char* dev_name = "ucsi-source-psy-USBC000:001";
int addr = -1;
/* current regex */
if (sscanf(dev_name, "%*[a-zA-Z0-9_]%*1[.:]%d", &addr) != 1)
   addr= 0;
printf("addr: %d\n", addr); /* prints 0 */
addr = -1;
/* proposed regex */
if (sscanf(dev_name, "%*[a-zA-Z0-9_-]%*1[.:]%d", &addr) != 1)
   addr= 0;
printf("addr: %d\n", addr); /* prints 1 */


We propose to add dashes to the regular expression, so that device
names with dashes will be correctly recognized, and provide it as a
patch. Note that we already opened an issue upstream at 
https://github.com/lm-sensors/lm-sensors/pull/529
It seems though, that the package is abandoned for a few years now. It
would be great if we could at least fix things in Debian.

Kind regards

-- System Information:
Debian Release: 12.10
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500,
'stable')
Architecture: arm64 (aarch64)

Kernel: Linux 5.15.36-00005-g64d029e108ce (SMP w/2 CPU threads)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
(ignored: LC_ALL set to en_US.UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages libsensors5 depends on:
ii  libc6              2.36-9+deb12u10
ii  libsensors-config  1:3.6.0-7.1

libsensors5 recommends no packages.

Versions of packages libsensors5 suggests:
ii  lm-sensors  1:3.6.0-7.1

-- no debconf information

From 0536186011d2106d048c3f051a39a4a0ebed4cd3 Mon Sep 17 00:00:00 2001
From: Michael Lettrich <michael.lettr...@cern.ch>
Date: Tue, 25 Mar 2025 10:19:29 +0100
Subject: [PATCH] [FIX] ISA sysfs address parsing

The ISA sensor chip address is obtained by parsing the hwmon
`/sysfs` device path. The regular expression extracting the
device address will fail if the device name contains dashes and
sets the address to 0. If  multiple instances of the same
board are plugged into the same system, cards can no longer be
distinguished, because their addresses will be set to 0 incorrectly.

This fix changes the address-parsing regular expression to recognize
device names with dashes.
---
 lib/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/sysfs.c b/lib/sysfs.c
index 9516cec4b..120830f9c 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -663,7 +663,7 @@ static int classify_device(const char *dev_name,
 	if ((!subsys || !strcmp(subsys, "platform") ||
 			!strcmp(subsys, "of_platform"))) {
 		/* must be new ISA (platform driver) */
-		if (sscanf(dev_name, "%*[a-zA-Z0-9_]%*1[.:]%d", &entry->chip.addr) != 1)
+		if (sscanf(dev_name, "%*[a-zA-Z0-9_-]%*1[.:]%d", &entry->chip.addr) != 1)
 			entry->chip.addr = 0;
 		entry->chip.bus.type = SENSORS_BUS_TYPE_ISA;
 		entry->chip.bus.nr = 0;

Reply via email to