]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-net_id: split out get_bcma_specifier() from names_bcma()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Aug 2023 05:08:35 +0000 (14:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Aug 2023 14:35:34 +0000 (23:35 +0900)
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.

src/udev/udev-builtin-net_id.c

index e002369da394a03e9986ae94c9ef01e42b863131..d61ed0cd7a2e18271b529a76fa101b432099f00e 100644 (file)
@@ -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;
 }