summaryrefslogtreecommitdiff
path: root/src/platform/wpan
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-02-15 11:33:57 +0100
committerThomas Haller <thaller@redhat.com>2019-02-22 09:58:09 +0100
commit6f8208c0d452c616bae02adff8dd8c707d722a07 (patch)
treefbf6bcee993b410760d87df96953076ff29cbfeb /src/platform/wpan
parentcf22d28c2e7479617dc38b5b0fbd8847893baea6 (diff)
downloadNetworkManager-6f8208c0d452c616bae02adff8dd8c707d722a07.tar.gz
platform/netlink: cleanup nla_parse*() code by using safer macros
- drop explicit MAX sizes like static const struct nla_policy policy[IFLA_INET6_MAX+1] = { The compiler will deduce that. It saves redundant information (which is possibly wrong). Also, the max define might be larger than we actually need it, so we just waste a few bytes of static memory and do unnecesary steps during validation. Also, the compiler will catch bugs, if the array size of policy/tb is too short for what we access later (-Warray-bounds). - avoid redundant size specifiers like: static const struct nla_policy policy[IFLA_INET6_MAX+1] = { ... struct nlattr *tb[IFLA_INET6_MAX+1]; ... err = nla_parse_nested (tb, IFLA_INET6_MAX, attr, policy); - use the nla_parse*_arr() macros that determine the maxtype based on the argument types. - move declaration of "static const struct nla_policy policy" variable to the beginning, before auto variables. - drop unneeded temporay error variables.
Diffstat (limited to 'src/platform/wpan')
-rw-r--r--src/platform/wpan/nm-wpan-utils.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/platform/wpan/nm-wpan-utils.c b/src/platform/wpan/nm-wpan-utils.c
index 4ae1770ffe..b7a51e9bf2 100644
--- a/src/platform/wpan/nm-wpan-utils.c
+++ b/src/platform/wpan/nm-wpan-utils.c
@@ -153,17 +153,19 @@ struct nl802154_interface {
static int
nl802154_get_interface_handler (struct nl_msg *msg, void *arg)
{
+ static const struct nla_policy nl802154_policy[] = {
+ [NL802154_ATTR_PAN_ID] = { .type = NLA_U16 },
+ [NL802154_ATTR_SHORT_ADDR] = { .type = NLA_U16 },
+ };
+ struct nlattr *tb[G_N_ELEMENTS (nl802154_policy)];
struct nl802154_interface *info = arg;
struct genlmsghdr *gnlh = nlmsg_data (nlmsg_hdr (msg));
- struct nlattr *tb[NL802154_ATTR_MAX + 1] = { 0, };
- static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX + 1] = {
- [NL802154_ATTR_PAN_ID] = { .type = NLA_U16 },
- [NL802154_ATTR_SHORT_ADDR] = { .type = NLA_U16 },
- };
- if (nla_parse (tb, NL802154_ATTR_MAX, genlmsg_attrdata (gnlh, 0),
- genlmsg_attrlen (gnlh, 0), nl802154_policy) < 0)
- return NL_SKIP;
+ if (nla_parse_arr (tb,
+ genlmsg_attrdata (gnlh, 0),
+ genlmsg_attrlen (gnlh, 0),
+ nl802154_policy) < 0)
+ return NL_SKIP;
if (tb[NL802154_ATTR_PAN_ID])
info->pan_id = le16toh (nla_get_u16 (tb[NL802154_ATTR_PAN_ID]));