In both cases, it is expected that the symlink targets do not end with '/'.
Addresses https://github.com/systemd/systemd/pull/23089#discussion_r853007218.
r = path_extract_filename(device->devpath, &sysname);
if (r < 0)
return r;
+ if (r == O_DIRECTORY)
+ return -EINVAL;
/* some devices have '!' in their name, change that to '/' */
for (p = strchrnul(sysname, '!'); *p != '\0'; p = strchrnul(p, '!'))
r = path_extract_filename(device->devpath, &sysname);
if (r < 0)
return r;
+ if (r == O_DIRECTORY)
+ return -EINVAL;
if (streq(subsystem, "drivers")) {
/* the 'drivers' pseudo-subsystem is special, and needs the real