From 49eb0a6889881fcaaf3863b60c6eb8d4f8309078 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 4 Jul 2021 14:33:02 +0900 Subject: [PATCH] sd-netlink: make type_get_type_system{,_union}() return value directly --- src/libsystemd/sd-netlink/generic-netlink.c | 4 ++-- src/libsystemd/sd-netlink/netlink-message.c | 8 ++------ src/libsystemd/sd-netlink/netlink-types.c | 19 ++++++------------- src/libsystemd/sd-netlink/netlink-types.h | 4 ++-- src/libsystemd/sd-netlink/nfnl-message.c | 2 +- 5 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/libsystemd/sd-netlink/generic-netlink.c b/src/libsystemd/sd-netlink/generic-netlink.c index 69f1a0cef5..648b840771 100644 --- a/src/libsystemd/sd-netlink/generic-netlink.c +++ b/src/libsystemd/sd-netlink/generic-netlink.c @@ -53,7 +53,7 @@ static int genl_message_new(sd_netlink *nl, sd_genl_family_t family, uint16_t nl m->hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - type_get_type_system(genl_cmd_type, &type_system); + type_system = type_get_type_system(genl_cmd_type); r = type_system_get_type(type_system, &nl_type, cmd); if (r < 0) @@ -62,7 +62,7 @@ static int genl_message_new(sd_netlink *nl, sd_genl_family_t family, uint16_t nl m->hdr->nlmsg_len = size; m->hdr->nlmsg_type = nlmsg_type; - type_get_type_system(nl_type, &m->containers[0].type_system); + m->containers[0].type_system = type_get_type_system(nl_type); *(struct genlmsghdr *) NLMSG_DATA(m->hdr) = (struct genlmsghdr) { .cmd = cmd, diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c index 075d021884..f3ed96b9f6 100644 --- a/src/libsystemd/sd-netlink/netlink-message.c +++ b/src/libsystemd/sd-netlink/netlink-message.c @@ -71,7 +71,7 @@ int message_new(sd_netlink *nl, sd_netlink_message **ret, uint16_t type) { m->hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - type_get_type_system(nl_type, &m->containers[0].type_system); + m->containers[0].type_system = type_get_type_system(nl_type); m->hdr->nlmsg_len = size; m->hdr->nlmsg_type = type; @@ -1328,11 +1328,7 @@ int sd_netlink_message_rewind(sd_netlink_message *m, sd_netlink *genl) { size = type_get_size(nl_type); if (type == NETLINK_TYPE_NESTED) { - const NLTypeSystem *type_system; - - type_get_type_system(nl_type, &type_system); - - m->containers[0].type_system = type_system; + m->containers[0].type_system = type_get_type_system(nl_type); if (sd_netlink_message_is_error(m)) r = netlink_message_parse_error(m); diff --git a/src/libsystemd/sd-netlink/netlink-types.c b/src/libsystemd/sd-netlink/netlink-types.c index beb926d40b..ccece76bf8 100644 --- a/src/libsystemd/sd-netlink/netlink-types.c +++ b/src/libsystemd/sd-netlink/netlink-types.c @@ -1700,22 +1700,18 @@ size_t type_get_size(const NLType *type) { return type->size; } -void type_get_type_system(const NLType *nl_type, const NLTypeSystem **ret) { +const NLTypeSystem *type_get_type_system(const NLType *nl_type) { assert(nl_type); - assert(ret); assert(nl_type->type == NETLINK_TYPE_NESTED); assert(nl_type->type_system); - - *ret = nl_type->type_system; + return nl_type->type_system; } -void type_get_type_system_union(const NLType *nl_type, const NLTypeSystemUnion **ret) { +const NLTypeSystemUnion *type_get_type_system_union(const NLType *nl_type) { assert(nl_type); - assert(ret); assert(nl_type->type == NETLINK_TYPE_UNION); assert(nl_type->type_system_union); - - *ret = nl_type->type_system_union; + return nl_type->type_system_union; } uint16_t type_system_get_count(const NLTypeSystem *type_system) { @@ -1778,7 +1774,6 @@ int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, ui return -EOPNOTSUPP; *ret = nl_type; - return 0; } @@ -1792,7 +1787,7 @@ int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSys if (r < 0) return r; - type_get_type_system(nl_type, ret); + *ret = type_get_type_system(nl_type); return 0; } @@ -1806,7 +1801,7 @@ int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLT if (r < 0) return r; - type_get_type_system_union(nl_type, ret); + *ret = type_get_type_system_union(nl_type); return 0; } @@ -1827,7 +1822,6 @@ int type_system_union_get_type_system(const NLTypeSystemUnion *type_system_union assert(type < type_system_union->num); *ret = &type_system_union->type_systems[type]; - return 0; } @@ -1847,6 +1841,5 @@ int type_system_union_protocol_get_type_system(const NLTypeSystemUnion *type_sys return -EOPNOTSUPP; *ret = type_system; - return 0; } diff --git a/src/libsystemd/sd-netlink/netlink-types.h b/src/libsystemd/sd-netlink/netlink-types.h index 316d7f1b87..607af01391 100644 --- a/src/libsystemd/sd-netlink/netlink-types.h +++ b/src/libsystemd/sd-netlink/netlink-types.h @@ -47,8 +47,8 @@ extern const NLTypeSystem genl_family_type_system_root; uint16_t type_get_type(const NLType *type); size_t type_get_size(const NLType *type); -void type_get_type_system(const NLType *type, const NLTypeSystem **ret); -void type_get_type_system_union(const NLType *type, const NLTypeSystemUnion **ret); +const NLTypeSystem *type_get_type_system(const NLType *type); +const NLTypeSystemUnion *type_get_type_system_union(const NLType *type); const NLTypeSystem* type_system_get_root(int protocol); uint16_t type_system_get_count(const NLTypeSystem *type_system); diff --git a/src/libsystemd/sd-netlink/nfnl-message.c b/src/libsystemd/sd-netlink/nfnl-message.c index 001a7b277e..e55b480402 100644 --- a/src/libsystemd/sd-netlink/nfnl-message.c +++ b/src/libsystemd/sd-netlink/nfnl-message.c @@ -43,7 +43,7 @@ static int nft_message_new(sd_netlink *nfnl, sd_netlink_message **ret, int famil m->hdr->nlmsg_flags = NLM_F_REQUEST | flags; - type_get_type_system(nl_type, &m->containers[0].type_system); + m->containers[0].type_system = type_get_type_system(nl_type); r = type_system_get_type_system(m->containers[0].type_system, &m->containers[0].type_system,