1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 09:21:26 +03:00

sd-device: minor optimization for sd_device_new_from_device_id()

This commit is contained in:
Yu Watanabe 2021-03-07 15:24:15 +09:00
parent db2bad4368
commit ff7a8d2938

View File

@ -623,7 +623,7 @@ _public_ int sd_device_new_from_device_id(sd_device **ret, const char *id) {
struct ifreq ifr = {};
int ifindex;
r = ifr.ifr_ifindex = parse_ifindex(&id[1]);
r = ifr.ifr_ifindex = parse_ifindex(id + 1);
if (r < 0)
return r;
@ -652,15 +652,14 @@ _public_ int sd_device_new_from_device_id(sd_device **ret, const char *id) {
}
case '+': {
char subsys[PATH_MAX];
char *sysname;
char subsys[NAME_MAX+1]; /* NAME_MAX does not include the trailing NUL. */
const char *sysname;
(void) strscpy(subsys, sizeof(subsys), id + 1);
sysname = strchr(subsys, ':');
sysname = strchr(id + 1, ':');
if (!sysname)
return -EINVAL;
sysname[0] = '\0';
(void) strnscpy(subsys, sizeof(subsys), id + 1, sysname - id - 1);
sysname++;
return sd_device_new_from_subsystem_sysname(ret, subsys, sysname);