Skip to content

Commit d352381

Browse files
committed
udev-builtin-net_id: split out get_bcma_specifier() from names_bcma()
This contains redundant copy of BCMA identifier, but that will be dropped in the next commit. No functional change, just refactoring and preparation for later commits.
1 parent f7ae5d1 commit d352381

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

src/udev/udev-builtin-net_id.c

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -998,36 +998,56 @@ static int names_usb(sd_device *dev, const char *prefix, NetNames *names, bool t
998998
return 0;
999999
}
10001000

1001-
static int names_bcma(sd_device *dev, NetNames *names) {
1002-
sd_device *bcmadev;
1003-
unsigned core;
1001+
static int get_bcma_specifier(sd_device *dev, char **ret) {
10041002
const char *sysname;
1003+
char *buf = NULL;
1004+
unsigned core;
10051005
int r;
10061006

10071007
assert(dev);
1008-
assert(names);
1009-
1010-
r = sd_device_get_parent_with_subsystem_devtype(dev, "bcma", NULL, &bcmadev);
1011-
if (r < 0)
1012-
return log_device_debug_errno(dev, r, "sd_device_get_parent_with_subsystem_devtype() failed: %m");
1008+
assert(ret);
10131009

1014-
r = sd_device_get_sysname(bcmadev, &sysname);
1010+
r = sd_device_get_sysname(dev, &sysname);
10151011
if (r < 0)
1016-
return log_device_debug_errno(dev, r, "sd_device_get_sysname() failed: %m");
1012+
return log_device_debug_errno(dev, r, "Failed to get sysname: %m");
10171013

10181014
/* bus num:core num */
10191015
r = sscanf(sysname, "bcma%*u:%u", &core);
1020-
log_device_debug(dev, "Parsing bcma device information from sysname \"%s\": %s",
1021-
sysname, r == 1 ? "success" : "failure");
10221016
if (r != 1)
1023-
return -EINVAL;
1017+
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
1018+
"Failed to parse bcma device information.");
1019+
10241020
/* suppress the common core == 0 */
1025-
if (core > 0)
1026-
xsprintf(names->bcma_core, "b%u", core);
1021+
if (core > 0 && asprintf(&buf, "b%u", core) < 0)
1022+
return log_oom_debug();
10271023

1028-
names->type = NET_BCMA;
10291024
log_device_debug(dev, "BCMA core identifier: core=%u %s \"%s\"",
1030-
core, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), names->bcma_core);
1025+
core, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), strna(buf));
1026+
1027+
*ret = buf;
1028+
return 0;
1029+
}
1030+
1031+
static int names_bcma(sd_device *dev, NetNames *names) {
1032+
_cleanup_free_ char *suffix = NULL;
1033+
sd_device *bcmadev;
1034+
int r;
1035+
1036+
assert(dev);
1037+
assert(names);
1038+
1039+
r = sd_device_get_parent_with_subsystem_devtype(dev, "bcma", NULL, &bcmadev);
1040+
if (r < 0)
1041+
return log_device_debug_errno(dev, r, "Could not get bcma parent device: %m");
1042+
1043+
r = get_bcma_specifier(bcmadev, &suffix);
1044+
if (r < 0)
1045+
return r;
1046+
1047+
size_t l = strscpy(names->bcma_core, sizeof(names->bcma_core), strempty(suffix));
1048+
if (l != 0)
1049+
names->type = NET_BCMA;
1050+
10311051
return 0;
10321052
}
10331053

0 commit comments

Comments
 (0)