]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: cleanup clr_config_net_nic()
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 8 Dec 2020 17:51:01 +0000 (18:51 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 9 Dec 2020 14:01:42 +0000 (15:01 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c

index cb1add0965d62b0b3a5977d3de3c79900d8281d6..f376133e889d338e18a213e615ff824e7c7f772a 100644 (file)
@@ -5152,16 +5152,16 @@ static int set_config_net_nic(const char *key, const char *value,
 static int clr_config_net_nic(const char *key, struct lxc_conf *lxc_conf,
                              void *data)
 {
+       __do_free char *deindexed_key = NULL;
+       ssize_t idx = -1;
        int ret;
        const char *idxstring;
        struct lxc_config_t *config;
        struct lxc_netdev *netdev;
-       ssize_t idx = -1;
-       char *deindexed_key = NULL;
 
        idxstring = key + 8;
        if (!isdigit(*idxstring))
-               return -1;
+               return ret_errno(EINVAL);
 
        /* The left conjunct is pretty self-explanatory. The right conjunct
         * checks whether the two pointers are equal. If they are we know that
@@ -5171,8 +5171,9 @@ static int clr_config_net_nic(const char *key, struct lxc_conf *lxc_conf,
        if (isdigit(*idxstring) && (strrchr(key, '.') == (idxstring - 1))) {
                unsigned int rmnetdevidx;
 
-               if (lxc_safe_uint(idxstring, &rmnetdevidx) < 0)
-                       return -1;
+               ret = lxc_safe_uint(idxstring, &rmnetdevidx);
+               if (ret < 0)
+                       return ret;
 
                /* Remove network from network list. */
                lxc_remove_nic_by_idx(lxc_conf, rmnetdevidx);
@@ -5181,18 +5182,13 @@ static int clr_config_net_nic(const char *key, struct lxc_conf *lxc_conf,
 
        config = get_network_config_ops(key, lxc_conf, &idx, &deindexed_key);
        if (!config || idx < 0)
-               return -1;
+               return -errno;
 
        netdev = lxc_get_netdev_by_idx(lxc_conf, (unsigned int)idx, false);
-       if (!netdev) {
-               free(deindexed_key);
-               return -1;
-       }
-
-       ret = config->clr(deindexed_key, lxc_conf, netdev);
-       free(deindexed_key);
+       if (!netdev)
+               return ret_errno(EINVAL);
 
-       return ret;
+       return config->clr(deindexed_key, lxc_conf, netdev);
 }
 
 static int clr_config_net_type(const char *key, struct lxc_conf *lxc_conf,