udev: use device_get_sysnum_unsigned() where applicable

This commit is contained in:
Yu Watanabe
2025-02-08 01:38:02 +09:00
parent 7543ae05e3
commit d083799a2c
2 changed files with 6 additions and 17 deletions
+2 -6
View 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");
+4 -11
View 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;
}