From: Yu Watanabe Date: Tue, 1 Aug 2023 05:08:35 +0000 (+0900) Subject: udev-builtin-net_id: split out get_bcma_specifier() from names_bcma() X-Git-Tag: v255-rc1~843^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d3523818e86f36d23b69aab765c4d9a85223ed88;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index e002369da39..d61ed0cd7a2 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -998,36 +998,56 @@ static int names_usb(sd_device *dev, const char *prefix, NetNames *names, bool t return 0; } -static int names_bcma(sd_device *dev, NetNames *names) { - sd_device *bcmadev; - unsigned core; +static int get_bcma_specifier(sd_device *dev, char **ret) { const char *sysname; + char *buf = NULL; + unsigned core; int r; assert(dev); - assert(names); - - r = sd_device_get_parent_with_subsystem_devtype(dev, "bcma", NULL, &bcmadev); - if (r < 0) - return log_device_debug_errno(dev, r, "sd_device_get_parent_with_subsystem_devtype() failed: %m"); + assert(ret); - r = sd_device_get_sysname(bcmadev, &sysname); + r = sd_device_get_sysname(dev, &sysname); if (r < 0) - return log_device_debug_errno(dev, r, "sd_device_get_sysname() failed: %m"); + return log_device_debug_errno(dev, r, "Failed to get sysname: %m"); /* bus num:core num */ r = sscanf(sysname, "bcma%*u:%u", &core); - log_device_debug(dev, "Parsing bcma device information from sysname \"%s\": %s", - sysname, r == 1 ? "success" : "failure"); if (r != 1) - return -EINVAL; + return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), + "Failed to parse bcma device information."); + /* suppress the common core == 0 */ - if (core > 0) - xsprintf(names->bcma_core, "b%u", core); + if (core > 0 && asprintf(&buf, "b%u", core) < 0) + return log_oom_debug(); - names->type = NET_BCMA; log_device_debug(dev, "BCMA core identifier: core=%u %s \"%s\"", - core, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), names->bcma_core); + core, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), strna(buf)); + + *ret = buf; + return 0; +} + +static int names_bcma(sd_device *dev, NetNames *names) { + _cleanup_free_ char *suffix = NULL; + sd_device *bcmadev; + int r; + + assert(dev); + assert(names); + + r = sd_device_get_parent_with_subsystem_devtype(dev, "bcma", NULL, &bcmadev); + if (r < 0) + return log_device_debug_errno(dev, r, "Could not get bcma parent device: %m"); + + r = get_bcma_specifier(bcmadev, &suffix); + if (r < 0) + return r; + + size_t l = strscpy(names->bcma_core, sizeof(names->bcma_core), strempty(suffix)); + if (l != 0) + names->type = NET_BCMA; + return 0; }