From: Yu Watanabe Date: Mon, 25 Feb 2019 02:53:57 +0000 (+0900) Subject: udev/net: use structured initializer at one more place X-Git-Tag: v242-rc1~252^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6cdab9f17f7a8066abc97519dbb8e15a4d012efe;p=thirdparty%2Fsystemd.git udev/net: use structured initializer at one more place --- diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 9b422fde434..7065ec7432e 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -119,6 +119,7 @@ int link_config_ctx_new(link_config_ctx **ret) { static int load_link(link_config_ctx *ctx, const char *filename) { _cleanup_(link_config_freep) link_config *link = NULL; _cleanup_fclose_ FILE *file = NULL; + _cleanup_free_ char *name = NULL; size_t i; int r; @@ -134,15 +135,22 @@ static int load_link(link_config_ctx *ctx, const char *filename) { return 0; } - link = new0(link_config, 1); + name = strdup(filename); + if (!name) + return -ENOMEM; + + link = new(link_config, 1); if (!link) return -ENOMEM; - link->mac_policy = _MACPOLICY_INVALID; - link->wol = _WOL_INVALID; - link->duplex = _DUP_INVALID; - link->port = _NET_DEV_PORT_INVALID; - link->autonegotiation = -1; + *link = (link_config) { + .filename = TAKE_PTR(name), + .mac_policy = _MACPOLICY_INVALID, + .wol = _WOL_INVALID, + .duplex = _DUP_INVALID, + .port = _NET_DEV_PORT_INVALID, + .autonegotiation = -1, + }; for (i = 0; i < ELEMENTSOF(link->features); i++) link->features[i] = -1; @@ -153,15 +161,11 @@ static int load_link(link_config_ctx *ctx, const char *filename) { CONFIG_PARSE_WARN, link); if (r < 0) return r; - else - log_debug("Parsed configuration file %s", filename); if (link->speed > UINT_MAX) return -ERANGE; - link->filename = strdup(filename); - if (!link->filename) - return -ENOMEM; + log_debug("Parsed configuration file %s", filename); LIST_PREPEND(links, ctx->links, link); link = NULL;