From d083799a2c13a83e6b34438454a29653e6cd264b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 8 Feb 2025 01:31:04 +0900 Subject: [PATCH] udev: use device_get_sysnum_unsigned() where applicable --- src/udev/udev-builtin-net_id.c | 8 ++------ src/udev/udev-builtin-path_id.c | 15 ++++----------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 44c202760ed..9b3f62ee691 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -1237,7 +1237,7 @@ static int names_mac(UdevEvent *event, const char *prefix) { static int names_netdevsim(UdevEvent *event, const char *prefix) { sd_device *netdevsimdev, *dev = ASSERT_PTR(ASSERT_PTR(event)->dev); - const char *sysnum, *phys_port_name; + const char *phys_port_name; unsigned addr; int r; @@ -1252,14 +1252,10 @@ static int names_netdevsim(UdevEvent *event, const char *prefix) { if (r < 0) return r; - r = sd_device_get_sysnum(netdevsimdev, &sysnum); + r = device_get_sysnum_unsigned(netdevsimdev, &addr); if (r < 0) return log_device_debug_errno(netdevsimdev, r, "Failed to get device sysnum: %m"); - r = safe_atou(sysnum, &addr); - if (r < 0) - return log_device_debug_errno(netdevsimdev, r, "Failed to parse device sysnum: %m"); - r = device_get_sysattr_value_filtered(dev, "phys_port_name", &phys_port_name); if (r < 0) return log_device_debug_errno(dev, r, "Failed to get 'phys_port_name' attribute: %m"); diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index d6ea4714821..f85ad9b4357 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -59,25 +59,18 @@ static void path_prepend(char **path, const char *fmt, ...) { ** See drivers/scsi/scsi_scan.c::scsilun_to_int() for more details. */ static int format_lun_number(sd_device *dev, char **path) { - const char *sysnum; - unsigned long lun; + unsigned lun; int r; - r = sd_device_get_sysnum(dev, &sysnum); - if (r < 0) - return r; - if (!sysnum) - return -ENOENT; - - r = safe_atolu_full(sysnum, 10, &lun); + r = device_get_sysnum_unsigned(dev, &lun); if (r < 0) return r; if (lun < 256) /* address method 0, peripheral device addressing with bus id of zero */ - path_prepend(path, "lun-%lu", lun); + path_prepend(path, "lun-%u", lun); else /* handle all other lun addressing methods by using a variant of the original lun format */ - path_prepend(path, "lun-0x%04lx%04lx00000000", lun & 0xffff, (lun >> 16) & 0xffff); + path_prepend(path, "lun-0x%04x%04x00000000", lun & 0xffff, (lun >> 16) & 0xffff); return 0; } -- 2.47.3