From ec35c656a8d44e845f6b5bf3580554bc851a158d Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Tue, 8 Dec 2020 18:51:01 +0100 Subject: [PATCH] confile: cleanup clr_config_net_nic() Signed-off-by: Christian Brauner --- src/lxc/confile.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/lxc/confile.c b/src/lxc/confile.c index cb1add096..f376133e8 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -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, -- 2.47.2