From: Yu Watanabe Date: Fri, 15 Apr 2022 04:29:53 +0000 (+0900) Subject: sd-device: use path_extract_filename() at one more place X-Git-Tag: v251-rc2~117^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c58e0ce677a6f8ad8b60343e900c31e8dce65bd4;p=thirdparty%2Fsystemd.git sd-device: use path_extract_filename() at one more place --- diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index cdae85675a9..ef3586ddfb5 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1171,24 +1171,13 @@ _public_ int sd_device_get_devname(sd_device *device, const char **devname) { static int device_set_sysname_and_sysnum(sd_device *device) { _cleanup_free_ char *sysname = NULL; const char *sysnum = NULL; - const char *pos; size_t len = 0; - if (!device->devpath) - return -EINVAL; - - pos = strrchr(device->devpath, '/'); - if (!pos) - return -EINVAL; - pos++; - - /* devpath is not a root directory */ - if (*pos == '\0' || pos <= device->devpath) - return -EINVAL; + assert(device); - sysname = strdup(pos); - if (!sysname) - return -ENOMEM; + r = path_extract_filename(device->devpath, &sysname); + if (r < 0) + return r; /* some devices have '!' in their name, change that to '/' */ while (sysname[len] != '\0') {