]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: use device_get_sysnum_unsigned() where applicable
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 7 Feb 2025 16:31:04 +0000 (01:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 7 Feb 2025 16:38:02 +0000 (01:38 +0900)
src/udev/udev-builtin-net_id.c
src/udev/udev-builtin-path_id.c

index 44c202760ed1d6e7309acfdd8945c9ca2422e3db..9b3f62ee6912e6e9d24f9ad162c4af972c5b6514 100644 (file)
@@ -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");
index d6ea47148217ed0159a398f7755fbf34d226edcb..f85ad9b4357a1a1eabddde11751c0def0b4b2139 100644 (file)
@@ -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;
 }