Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: convert to nla_get_*_default()

Most of the original conversion is from the spatch below,
but I edited some and left out other instances that were
either buggy after conversion (where default values don't
fit into the type) or just looked strange.

@@
expression attr, def;
expression val;
identifier fn =~ "^nla_get_.*";
fresh identifier dfn = fn ## "_default";
@@
(
-if (attr)
- val = fn(attr);
-else
- val = def;
+val = dfn(attr, def);
|
-if (!attr)
- val = def;
-else
- val = fn(attr);
+val = dfn(attr, def);
|
-if (!attr)
- return def;
-return fn(attr);
+return dfn(attr, def);
|
-attr ? fn(attr) : def
+dfn(attr, def)
|
-!attr ? def : fn(attr)
+dfn(attr, def)
)

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Reviewed-by: Toke Høiland-Jørgensen <toke@kernel.org>
Link: https://patch.msgid.link/20241108114145.0580b8684e7f.I740beeaa2f70ebfc19bfca1045a24d6151992790@changeid
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Johannes Berg and committed by
Jakub Kicinski
a885a6b2 7f4b3960

+124 -234
+4 -8
drivers/net/amt.c
··· 3206 3206 goto err; 3207 3207 } 3208 3208 3209 - if (data[IFLA_AMT_RELAY_PORT]) 3210 - amt->relay_port = nla_get_be16(data[IFLA_AMT_RELAY_PORT]); 3211 - else 3212 - amt->relay_port = htons(IANA_AMT_UDP_PORT); 3209 + amt->relay_port = nla_get_be16_default(data[IFLA_AMT_RELAY_PORT], 3210 + htons(IANA_AMT_UDP_PORT)); 3213 3211 3214 - if (data[IFLA_AMT_GATEWAY_PORT]) 3215 - amt->gw_port = nla_get_be16(data[IFLA_AMT_GATEWAY_PORT]); 3216 - else 3217 - amt->gw_port = htons(IANA_AMT_UDP_PORT); 3212 + amt->gw_port = nla_get_be16_default(data[IFLA_AMT_GATEWAY_PORT], 3213 + htons(IANA_AMT_UDP_PORT)); 3218 3214 3219 3215 if (!amt->relay_port) { 3220 3216 NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_AMT_DISCOVERY_IP],
+4 -12
drivers/net/gtp.c
··· 1491 1491 } 1492 1492 gtp->role = role; 1493 1493 1494 - if (!data[IFLA_GTP_RESTART_COUNT]) 1495 - gtp->restart_count = 0; 1496 - else 1497 - gtp->restart_count = nla_get_u8(data[IFLA_GTP_RESTART_COUNT]); 1494 + gtp->restart_count = nla_get_u8_default(data[IFLA_GTP_RESTART_COUNT], 1495 + 0); 1498 1496 1499 1497 gtp->net = src_net; 1500 1498 ··· 1827 1829 1828 1830 version = nla_get_u32(info->attrs[GTPA_VERSION]); 1829 1831 1830 - if (info->attrs[GTPA_FAMILY]) 1831 - family = nla_get_u8(info->attrs[GTPA_FAMILY]); 1832 - else 1833 - family = AF_INET; 1832 + family = nla_get_u8_default(info->attrs[GTPA_FAMILY], AF_INET); 1834 1833 1835 1834 #if !IS_ENABLED(CONFIG_IPV6) 1836 1835 if (family == AF_INET6) ··· 2064 2069 struct gtp_dev *gtp; 2065 2070 int family; 2066 2071 2067 - if (nla[GTPA_FAMILY]) 2068 - family = nla_get_u8(nla[GTPA_FAMILY]); 2069 - else 2070 - family = AF_INET; 2072 + family = nla_get_u8_default(nla[GTPA_FAMILY], AF_INET); 2071 2073 2072 2074 gtp = gtp_find_dev(net, nla); 2073 2075 if (!gtp)
+3 -3
drivers/net/macsec.c
··· 4299 4299 } 4300 4300 } 4301 4301 4302 - es = data[IFLA_MACSEC_ES] ? nla_get_u8(data[IFLA_MACSEC_ES]) : false; 4303 - sci = data[IFLA_MACSEC_INC_SCI] ? nla_get_u8(data[IFLA_MACSEC_INC_SCI]) : false; 4304 - scb = data[IFLA_MACSEC_SCB] ? nla_get_u8(data[IFLA_MACSEC_SCB]) : false; 4302 + es = nla_get_u8_default(data[IFLA_MACSEC_ES], false); 4303 + sci = nla_get_u8_default(data[IFLA_MACSEC_INC_SCI], false); 4304 + scb = nla_get_u8_default(data[IFLA_MACSEC_SCB], false); 4305 4305 4306 4306 if ((sci && (scb || es)) || (scb && es)) 4307 4307 return -EINVAL;
+1 -4
drivers/net/vxlan/vxlan_core.c
··· 1232 1232 *ifindex = 0; 1233 1233 } 1234 1234 1235 - if (tb[NDA_NH_ID]) 1236 - *nhid = nla_get_u32(tb[NDA_NH_ID]); 1237 - else 1238 - *nhid = 0; 1235 + *nhid = nla_get_u32_default(tb[NDA_NH_ID], 0); 1239 1236 1240 1237 return 0; 1241 1238 }
+2 -4
net/8021q/vlan_netlink.c
··· 161 161 return -ENODEV; 162 162 } 163 163 164 - if (data[IFLA_VLAN_PROTOCOL]) 165 - proto = nla_get_be16(data[IFLA_VLAN_PROTOCOL]); 166 - else 167 - proto = htons(ETH_P_8021Q); 164 + proto = nla_get_be16_default(data[IFLA_VLAN_PROTOCOL], 165 + htons(ETH_P_8021Q)); 168 166 169 167 vlan->vlan_proto = proto; 170 168 vlan->vlan_id = nla_get_u16(data[IFLA_VLAN_ID]);
+1 -2
net/core/fib_rules.c
··· 558 558 nlrule->pref = fib_default_rule_pref(ops); 559 559 } 560 560 561 - nlrule->proto = tb[FRA_PROTOCOL] ? 562 - nla_get_u8(tb[FRA_PROTOCOL]) : RTPROT_UNSPEC; 561 + nlrule->proto = nla_get_u8_default(tb[FRA_PROTOCOL], RTPROT_UNSPEC); 563 562 564 563 if (tb[FRA_IIFNAME]) { 565 564 struct net_device *dev;
+1 -4
net/core/rtnetlink.c
··· 2940 2940 const char *pat = ifname[0] ? ifname : NULL; 2941 2941 int new_ifindex; 2942 2942 2943 - if (tb[IFLA_NEW_IFINDEX]) 2944 - new_ifindex = nla_get_s32(tb[IFLA_NEW_IFINDEX]); 2945 - else 2946 - new_ifindex = 0; 2943 + new_ifindex = nla_get_s32_default(tb[IFLA_NEW_IFINDEX], 0); 2947 2944 2948 2945 err = __dev_change_net_namespace(dev, tgt_net, pat, new_ifindex); 2949 2946 if (err)
+2 -4
net/devlink/dev.c
··· 531 531 return err; 532 532 } 533 533 534 - if (info->attrs[DEVLINK_ATTR_RELOAD_ACTION]) 535 - action = nla_get_u8(info->attrs[DEVLINK_ATTR_RELOAD_ACTION]); 536 - else 537 - action = DEVLINK_RELOAD_ACTION_DRIVER_REINIT; 534 + action = nla_get_u8_default(info->attrs[DEVLINK_ATTR_RELOAD_ACTION], 535 + DEVLINK_RELOAD_ACTION_DRIVER_REINIT); 538 536 539 537 if (!devlink_reload_action_is_supported(devlink, action)) { 540 538 NL_SET_ERR_MSG(info->extack, "Requested reload action is not supported by the driver");
+1 -4
net/hsr/hsr_netlink.c
··· 82 82 return -EINVAL; 83 83 } 84 84 85 - if (!data[IFLA_HSR_MULTICAST_SPEC]) 86 - multicast_spec = 0; 87 - else 88 - multicast_spec = nla_get_u8(data[IFLA_HSR_MULTICAST_SPEC]); 85 + multicast_spec = nla_get_u8_default(data[IFLA_HSR_MULTICAST_SPEC], 0); 89 86 90 87 if (data[IFLA_HSR_PROTOCOL]) 91 88 proto = nla_get_u8(data[IFLA_HSR_PROTOCOL]);
+3 -12
net/ieee802154/nl-mac.c
··· 202 202 addr.pan_id = nla_get_shortaddr( 203 203 info->attrs[IEEE802154_ATTR_COORD_PAN_ID]); 204 204 205 - if (info->attrs[IEEE802154_ATTR_PAGE]) 206 - page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]); 207 - else 208 - page = 0; 205 + page = nla_get_u8_default(info->attrs[IEEE802154_ATTR_PAGE], 0); 209 206 210 207 ret = ieee802154_mlme_ops(dev)->assoc_req(dev, &addr, 211 208 nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]), ··· 335 338 blx = nla_get_u8(info->attrs[IEEE802154_ATTR_BAT_EXT]); 336 339 coord_realign = nla_get_u8(info->attrs[IEEE802154_ATTR_COORD_REALIGN]); 337 340 338 - if (info->attrs[IEEE802154_ATTR_PAGE]) 339 - page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]); 340 - else 341 - page = 0; 341 + page = nla_get_u8_default(info->attrs[IEEE802154_ATTR_PAGE], 0); 342 342 343 343 if (addr.short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST)) { 344 344 ieee802154_nl_start_confirm(dev, IEEE802154_NO_SHORT_ADDRESS); ··· 382 388 channels = nla_get_u32(info->attrs[IEEE802154_ATTR_CHANNELS]); 383 389 duration = nla_get_u8(info->attrs[IEEE802154_ATTR_DURATION]); 384 390 385 - if (info->attrs[IEEE802154_ATTR_PAGE]) 386 - page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]); 387 - else 388 - page = 0; 391 + page = nla_get_u8_default(info->attrs[IEEE802154_ATTR_PAGE], 0); 389 392 390 393 ret = ieee802154_mlme_ops(dev)->scan_req(dev, type, channels, 391 394 page, duration);
+10 -16
net/ieee802154/nl802154.c
··· 1438 1438 } 1439 1439 1440 1440 /* Use current page by default */ 1441 - if (info->attrs[NL802154_ATTR_PAGE]) 1442 - request->page = nla_get_u8(info->attrs[NL802154_ATTR_PAGE]); 1443 - else 1444 - request->page = wpan_phy->current_page; 1441 + request->page = nla_get_u8_default(info->attrs[NL802154_ATTR_PAGE], 1442 + wpan_phy->current_page); 1445 1443 1446 1444 /* Scan all supported channels by default */ 1447 - if (info->attrs[NL802154_ATTR_SCAN_CHANNELS]) 1448 - request->channels = nla_get_u32(info->attrs[NL802154_ATTR_SCAN_CHANNELS]); 1449 - else 1450 - request->channels = wpan_phy->supported.channels[request->page]; 1445 + request->channels = 1446 + nla_get_u32_default(info->attrs[NL802154_ATTR_SCAN_CHANNELS], 1447 + wpan_phy->supported.channels[request->page]); 1451 1448 1452 1449 /* Use maximum duration order by default */ 1453 - if (info->attrs[NL802154_ATTR_SCAN_DURATION]) 1454 - request->duration = nla_get_u8(info->attrs[NL802154_ATTR_SCAN_DURATION]); 1455 - else 1456 - request->duration = IEEE802154_MAX_SCAN_DURATION; 1450 + request->duration = 1451 + nla_get_u8_default(info->attrs[NL802154_ATTR_SCAN_DURATION], 1452 + IEEE802154_MAX_SCAN_DURATION); 1457 1453 1458 1454 err = rdev_trigger_scan(rdev, request); 1459 1455 if (err) { ··· 1594 1598 request->wpan_phy = wpan_phy; 1595 1599 1596 1600 /* Use maximum duration order by default */ 1597 - if (info->attrs[NL802154_ATTR_BEACON_INTERVAL]) 1598 - request->interval = nla_get_u8(info->attrs[NL802154_ATTR_BEACON_INTERVAL]); 1599 - else 1600 - request->interval = IEEE802154_MAX_SCAN_DURATION; 1601 + request->interval = nla_get_u8_default(info->attrs[NL802154_ATTR_BEACON_INTERVAL], 1602 + IEEE802154_MAX_SCAN_DURATION); 1601 1603 1602 1604 err = rdev_send_beacons(rdev, request); 1603 1605 if (err) {
+1 -2
net/ipv4/devinet.c
··· 926 926 927 927 ifa->ifa_prefixlen = ifm->ifa_prefixlen; 928 928 ifa->ifa_mask = inet_make_mask(ifm->ifa_prefixlen); 929 - ifa->ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : 930 - ifm->ifa_flags; 929 + ifa->ifa_flags = nla_get_u32_default(tb[IFA_FLAGS], ifm->ifa_flags); 931 930 ifa->ifa_scope = ifm->ifa_scope; 932 931 ifa->ifa_local = nla_get_in_addr(tb[IFA_LOCAL]); 933 932 ifa->ifa_address = nla_get_in_addr(tb[IFA_ADDRESS]);
+3 -3
net/ipv4/ipmr.c
··· 2546 2546 if (err < 0) 2547 2547 goto errout; 2548 2548 2549 - src = tb[RTA_SRC] ? nla_get_in_addr(tb[RTA_SRC]) : 0; 2550 - grp = tb[RTA_DST] ? nla_get_in_addr(tb[RTA_DST]) : 0; 2551 - tableid = tb[RTA_TABLE] ? nla_get_u32(tb[RTA_TABLE]) : 0; 2549 + src = nla_get_in_addr_default(tb[RTA_SRC], 0); 2550 + grp = nla_get_in_addr_default(tb[RTA_DST], 0); 2551 + tableid = nla_get_u32_default(tb[RTA_TABLE], 0); 2552 2552 2553 2553 mrt = ipmr_get_table(net, tableid ? tableid : RT_TABLE_DEFAULT); 2554 2554 if (!mrt) {
+3 -10
net/ipv4/nexthop.c
··· 3247 3247 return -EINVAL; 3248 3248 } 3249 3249 3250 - if (op_flags) { 3251 - if (tb[NHA_OP_FLAGS]) 3252 - *op_flags = nla_get_u32(tb[NHA_OP_FLAGS]); 3253 - else 3254 - *op_flags = 0; 3255 - } 3250 + if (op_flags) 3251 + *op_flags = nla_get_u32_default(tb[NHA_OP_FLAGS], 0); 3256 3252 3257 3253 return 0; 3258 3254 } ··· 3429 3433 if (err < 0) 3430 3434 return err; 3431 3435 3432 - if (tb[NHA_OP_FLAGS]) 3433 - filter->op_flags = nla_get_u32(tb[NHA_OP_FLAGS]); 3434 - else 3435 - filter->op_flags = 0; 3436 + filter->op_flags = nla_get_u32_default(tb[NHA_OP_FLAGS], 0); 3436 3437 3437 3438 return __nh_valid_dump_req(nlh, tb, filter, cb->extack); 3438 3439 }
+5 -5
net/ipv4/route.c
··· 3231 3231 return err; 3232 3232 3233 3233 rtm = nlmsg_data(nlh); 3234 - src = tb[RTA_SRC] ? nla_get_in_addr(tb[RTA_SRC]) : 0; 3235 - dst = tb[RTA_DST] ? nla_get_in_addr(tb[RTA_DST]) : 0; 3236 - iif = tb[RTA_IIF] ? nla_get_u32(tb[RTA_IIF]) : 0; 3237 - mark = tb[RTA_MARK] ? nla_get_u32(tb[RTA_MARK]) : 0; 3234 + src = nla_get_in_addr_default(tb[RTA_SRC], 0); 3235 + dst = nla_get_in_addr_default(tb[RTA_DST], 0); 3236 + iif = nla_get_u32_default(tb[RTA_IIF], 0); 3237 + mark = nla_get_u32_default(tb[RTA_MARK], 0); 3238 3238 if (tb[RTA_UID]) 3239 3239 uid = make_kuid(current_user_ns(), nla_get_u32(tb[RTA_UID])); 3240 3240 else ··· 3260 3260 fl4.daddr = dst; 3261 3261 fl4.saddr = src; 3262 3262 fl4.flowi4_tos = rtm->rtm_tos & INET_DSCP_MASK; 3263 - fl4.flowi4_oif = tb[RTA_OIF] ? nla_get_u32(tb[RTA_OIF]) : 0; 3263 + fl4.flowi4_oif = nla_get_u32_default(tb[RTA_OIF], 0); 3264 3264 fl4.flowi4_mark = mark; 3265 3265 fl4.flowi4_uid = uid; 3266 3266 if (sport)
+2 -5
net/ipv6/addrconf.c
··· 4793 4793 if (!pfx) 4794 4794 return -EINVAL; 4795 4795 4796 - ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags; 4796 + ifa_flags = nla_get_u32_default(tb[IFA_FLAGS], ifm->ifa_flags); 4797 4797 4798 4798 /* We ignore other flags so far. */ 4799 4799 ifa_flags &= IFA_F_MANAGETEMPADDR; ··· 5018 5018 return -ENODEV; 5019 5019 } 5020 5020 5021 - if (tb[IFA_FLAGS]) 5022 - cfg.ifa_flags = nla_get_u32(tb[IFA_FLAGS]); 5023 - else 5024 - cfg.ifa_flags = ifm->ifa_flags; 5021 + cfg.ifa_flags = nla_get_u32_default(tb[IFA_FLAGS], ifm->ifa_flags); 5025 5022 5026 5023 /* We ignore other flags so far. */ 5027 5024 cfg.ifa_flags &= IFA_F_NODAD | IFA_F_HOMEADDRESS |
+4 -9
net/ipv6/ila/ila_xlat.c
··· 105 105 xp->ip.locator_match.v64 = (__force __be64)nla_get_u64( 106 106 info->attrs[ILA_ATTR_LOCATOR_MATCH]); 107 107 108 - if (info->attrs[ILA_ATTR_CSUM_MODE]) 109 - xp->ip.csum_mode = nla_get_u8(info->attrs[ILA_ATTR_CSUM_MODE]); 110 - else 111 - xp->ip.csum_mode = ILA_CSUM_NO_ACTION; 108 + xp->ip.csum_mode = nla_get_u8_default(info->attrs[ILA_ATTR_CSUM_MODE], 109 + ILA_CSUM_NO_ACTION); 112 110 113 - if (info->attrs[ILA_ATTR_IDENT_TYPE]) 114 - xp->ip.ident_type = nla_get_u8( 115 - info->attrs[ILA_ATTR_IDENT_TYPE]); 116 - else 117 - xp->ip.ident_type = ILA_ATYPE_USE_FORMAT; 111 + xp->ip.ident_type = nla_get_u8_default(info->attrs[ILA_ATTR_IDENT_TYPE], 112 + ILA_ATYPE_USE_FORMAT); 118 113 119 114 if (info->attrs[ILA_ATTR_IFINDEX]) 120 115 xp->ifindex = nla_get_s32(info->attrs[ILA_ATTR_IFINDEX]);
+4 -8
net/ipv6/ioam6.c
··· 135 135 136 136 ns->id = id; 137 137 138 - if (!info->attrs[IOAM6_ATTR_NS_DATA]) 139 - data32 = IOAM6_U32_UNAVAILABLE; 140 - else 141 - data32 = nla_get_u32(info->attrs[IOAM6_ATTR_NS_DATA]); 138 + data32 = nla_get_u32_default(info->attrs[IOAM6_ATTR_NS_DATA], 139 + IOAM6_U32_UNAVAILABLE); 142 140 143 - if (!info->attrs[IOAM6_ATTR_NS_DATA_WIDE]) 144 - data64 = IOAM6_U64_UNAVAILABLE; 145 - else 146 - data64 = nla_get_u64(info->attrs[IOAM6_ATTR_NS_DATA_WIDE]); 141 + data64 = nla_get_u64_default(info->attrs[IOAM6_ATTR_NS_DATA_WIDE], 142 + IOAM6_U64_UNAVAILABLE); 147 143 148 144 ns->data = cpu_to_be32(data32); 149 145 ns->data_wide = cpu_to_be64(data64);
+2 -4
net/ipv6/ioam6_iptunnel.c
··· 142 142 } 143 143 } 144 144 145 - if (!tb[IOAM6_IPTUNNEL_MODE]) 146 - mode = IOAM6_IPTUNNEL_MODE_INLINE; 147 - else 148 - mode = nla_get_u8(tb[IOAM6_IPTUNNEL_MODE]); 145 + mode = nla_get_u8_default(tb[IOAM6_IPTUNNEL_MODE], 146 + IOAM6_IPTUNNEL_MODE_INLINE); 149 147 150 148 if (tb[IOAM6_IPTUNNEL_SRC] && mode == IOAM6_IPTUNNEL_MODE_INLINE) { 151 149 NL_SET_ERR_MSG(extack, "no tunnel src expected with this mode");
+1 -1
net/ipv6/ip6mr.c
··· 2560 2560 src = nla_get_in6_addr(tb[RTA_SRC]); 2561 2561 if (tb[RTA_DST]) 2562 2562 grp = nla_get_in6_addr(tb[RTA_DST]); 2563 - tableid = tb[RTA_TABLE] ? nla_get_u32(tb[RTA_TABLE]) : 0; 2563 + tableid = nla_get_u32_default(tb[RTA_TABLE], 0); 2564 2564 2565 2565 mrt = ip6mr_get_table(net, tableid ?: RT_TABLE_DEFAULT); 2566 2566 if (!mrt) {
+1 -4
net/netfilter/ipvs/ip_vs_ctl.c
··· 3662 3662 nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr)); 3663 3663 udest->port = nla_get_be16(nla_port); 3664 3664 3665 - if (nla_addr_family) 3666 - udest->af = nla_get_u16(nla_addr_family); 3667 - else 3668 - udest->af = 0; 3665 + udest->af = nla_get_u16_default(nla_addr_family, 0); 3669 3666 3670 3667 /* If a full entry was requested, check for the additional fields */ 3671 3668 if (full_entry) {
+2 -4
net/netfilter/nf_nat_core.c
··· 1090 1090 range->flags |= NF_NAT_RANGE_MAP_IPS; 1091 1091 } 1092 1092 1093 - if (tb[CTA_NAT_V4_MAXIP]) 1094 - range->max_addr.ip = nla_get_be32(tb[CTA_NAT_V4_MAXIP]); 1095 - else 1096 - range->max_addr.ip = range->min_addr.ip; 1093 + range->max_addr.ip = nla_get_be32_default(tb[CTA_NAT_V4_MAXIP], 1094 + range->min_addr.ip); 1097 1095 1098 1096 return 0; 1099 1097 }
+1 -4
net/netfilter/nft_tunnel.c
··· 497 497 } 498 498 if (tb[NFTA_TUNNEL_KEY_TOS]) 499 499 info.key.tos = nla_get_u8(tb[NFTA_TUNNEL_KEY_TOS]); 500 - if (tb[NFTA_TUNNEL_KEY_TTL]) 501 - info.key.ttl = nla_get_u8(tb[NFTA_TUNNEL_KEY_TTL]); 502 - else 503 - info.key.ttl = U8_MAX; 500 + info.key.ttl = nla_get_u8_default(tb[NFTA_TUNNEL_KEY_TTL], U8_MAX); 504 501 505 502 if (tb[NFTA_TUNNEL_KEY_OPTS]) { 506 503 err = nft_tunnel_obj_opts_init(ctx, tb[NFTA_TUNNEL_KEY_OPTS],
+4 -9
net/netlabel/netlabel_mgmt.c
··· 107 107 108 108 switch (entry->def.type) { 109 109 case NETLBL_NLTYPE_UNLABELED: 110 - if (info->attrs[NLBL_MGMT_A_FAMILY]) 111 - entry->family = 112 - nla_get_u16(info->attrs[NLBL_MGMT_A_FAMILY]); 113 - else 114 - entry->family = AF_UNSPEC; 110 + entry->family = 111 + nla_get_u16_default(info->attrs[NLBL_MGMT_A_FAMILY], 112 + AF_UNSPEC); 115 113 break; 116 114 case NETLBL_NLTYPE_CIPSOV4: 117 115 if (!info->attrs[NLBL_MGMT_A_CV4DOI]) ··· 599 601 struct netlbl_dom_map *entry; 600 602 u16 family; 601 603 602 - if (info->attrs[NLBL_MGMT_A_FAMILY]) 603 - family = nla_get_u16(info->attrs[NLBL_MGMT_A_FAMILY]); 604 - else 605 - family = AF_INET; 604 + family = nla_get_u16_default(info->attrs[NLBL_MGMT_A_FAMILY], AF_INET); 606 605 607 606 ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 608 607 if (ans_skb == NULL)
+4 -6
net/openvswitch/datapath.c
··· 1828 1828 parms.dp = dp; 1829 1829 parms.port_no = OVSP_LOCAL; 1830 1830 parms.upcall_portids = a[OVS_DP_ATTR_UPCALL_PID]; 1831 - parms.desired_ifindex = a[OVS_DP_ATTR_IFINDEX] 1832 - ? nla_get_s32(a[OVS_DP_ATTR_IFINDEX]) : 0; 1831 + parms.desired_ifindex = nla_get_s32_default(a[OVS_DP_ATTR_IFINDEX], 0); 1833 1832 1834 1833 /* So far only local changes have been made, now need the lock. */ 1835 1834 ovs_lock(); ··· 2265 2266 if (a[OVS_VPORT_ATTR_IFINDEX] && parms.type != OVS_VPORT_TYPE_INTERNAL) 2266 2267 return -EOPNOTSUPP; 2267 2268 2268 - port_no = a[OVS_VPORT_ATTR_PORT_NO] 2269 - ? nla_get_u32(a[OVS_VPORT_ATTR_PORT_NO]) : 0; 2269 + port_no = nla_get_u32_default(a[OVS_VPORT_ATTR_PORT_NO], 0); 2270 2270 if (port_no >= DP_MAX_PORTS) 2271 2271 return -EFBIG; 2272 2272 ··· 2302 2304 parms.dp = dp; 2303 2305 parms.port_no = port_no; 2304 2306 parms.upcall_portids = a[OVS_VPORT_ATTR_UPCALL_PID]; 2305 - parms.desired_ifindex = a[OVS_VPORT_ATTR_IFINDEX] 2306 - ? nla_get_s32(a[OVS_VPORT_ATTR_IFINDEX]) : 0; 2307 + parms.desired_ifindex = nla_get_s32_default(a[OVS_VPORT_ATTR_IFINDEX], 2308 + 0); 2307 2309 2308 2310 vport = new_vport(&parms); 2309 2311 err = PTR_ERR(vport);
+1 -1
net/openvswitch/flow_netlink.c
··· 1938 1938 1939 1939 u32 ovs_nla_get_ufid_flags(const struct nlattr *attr) 1940 1940 { 1941 - return attr ? nla_get_u32(attr) : 0; 1941 + return nla_get_u32_default(attr, 0); 1942 1942 } 1943 1943 1944 1944 /**
+5 -5
net/sched/act_ct.c
··· 1183 1183 range->min_addr.ip = 1184 1184 nla_get_in_addr(tb[TCA_CT_NAT_IPV4_MIN]); 1185 1185 1186 - range->max_addr.ip = max_attr ? 1187 - nla_get_in_addr(max_attr) : 1188 - range->min_addr.ip; 1186 + range->max_addr.ip = 1187 + nla_get_in_addr_default(max_attr, range->min_addr.ip); 1189 1188 } else if (tb[TCA_CT_NAT_IPV6_MIN]) { 1190 1189 struct nlattr *max_attr = tb[TCA_CT_NAT_IPV6_MAX]; 1191 1190 ··· 1313 1314 err = -EINVAL; 1314 1315 goto err; 1315 1316 } 1316 - family = tb[TCA_CT_HELPER_FAMILY] ? nla_get_u8(tb[TCA_CT_HELPER_FAMILY]) : AF_INET; 1317 - proto = tb[TCA_CT_HELPER_PROTO] ? nla_get_u8(tb[TCA_CT_HELPER_PROTO]) : IPPROTO_TCP; 1317 + family = nla_get_u8_default(tb[TCA_CT_HELPER_FAMILY], AF_INET); 1318 + proto = nla_get_u8_default(tb[TCA_CT_HELPER_PROTO], 1319 + IPPROTO_TCP); 1318 1320 err = nf_ct_add_helper(tmpl, name, family, proto, 1319 1321 p->ct_action & TCA_CT_ACT_NAT, &p->helper); 1320 1322 if (err) {
+4 -4
net/sched/act_ctinfo.c
··· 197 197 "dscp mask must be 6 contiguous bits"); 198 198 return -EINVAL; 199 199 } 200 - dscpstatemask = tb[TCA_CTINFO_PARMS_DSCP_STATEMASK] ? 201 - nla_get_u32(tb[TCA_CTINFO_PARMS_DSCP_STATEMASK]) : 0; 200 + dscpstatemask = 201 + nla_get_u32_default(tb[TCA_CTINFO_PARMS_DSCP_STATEMASK], 202 + 0); 202 203 /* mask & statemask must not overlap */ 203 204 if (dscpmask & dscpstatemask) { 204 205 NL_SET_ERR_MSG_ATTR(extack, ··· 244 243 } 245 244 246 245 cp_new->net = net; 247 - cp_new->zone = tb[TCA_CTINFO_ZONE] ? 248 - nla_get_u16(tb[TCA_CTINFO_ZONE]) : 0; 246 + cp_new->zone = nla_get_u16_default(tb[TCA_CTINFO_ZONE], 0); 249 247 if (dscpmask) { 250 248 cp_new->dscpmask = dscpmask; 251 249 cp_new->dscpmaskshift = dscpmaskshift;
+3 -8
net/sched/act_gate.c
··· 190 190 191 191 entry->interval = interval; 192 192 193 - if (tb[TCA_GATE_ENTRY_IPV]) 194 - entry->ipv = nla_get_s32(tb[TCA_GATE_ENTRY_IPV]); 195 - else 196 - entry->ipv = -1; 193 + entry->ipv = nla_get_s32_default(tb[TCA_GATE_ENTRY_IPV], -1); 197 194 198 - if (tb[TCA_GATE_ENTRY_MAX_OCTETS]) 199 - entry->maxoctets = nla_get_s32(tb[TCA_GATE_ENTRY_MAX_OCTETS]); 200 - else 201 - entry->maxoctets = -1; 195 + entry->maxoctets = nla_get_s32_default(tb[TCA_GATE_ENTRY_MAX_OCTETS], 196 + -1); 202 197 203 198 return 0; 204 199 }
+8 -10
net/sched/act_mpls.c
··· 288 288 } 289 289 290 290 p->tcfm_action = parm->m_action; 291 - p->tcfm_label = tb[TCA_MPLS_LABEL] ? nla_get_u32(tb[TCA_MPLS_LABEL]) : 292 - ACT_MPLS_LABEL_NOT_SET; 293 - p->tcfm_tc = tb[TCA_MPLS_TC] ? nla_get_u8(tb[TCA_MPLS_TC]) : 294 - ACT_MPLS_TC_NOT_SET; 295 - p->tcfm_ttl = tb[TCA_MPLS_TTL] ? nla_get_u8(tb[TCA_MPLS_TTL]) : 296 - mpls_ttl; 297 - p->tcfm_bos = tb[TCA_MPLS_BOS] ? nla_get_u8(tb[TCA_MPLS_BOS]) : 298 - ACT_MPLS_BOS_NOT_SET; 299 - p->tcfm_proto = tb[TCA_MPLS_PROTO] ? nla_get_be16(tb[TCA_MPLS_PROTO]) : 300 - htons(ETH_P_MPLS_UC); 291 + p->tcfm_label = nla_get_u32_default(tb[TCA_MPLS_LABEL], 292 + ACT_MPLS_LABEL_NOT_SET); 293 + p->tcfm_tc = nla_get_u8_default(tb[TCA_MPLS_TC], ACT_MPLS_TC_NOT_SET); 294 + p->tcfm_ttl = nla_get_u8_default(tb[TCA_MPLS_TTL], mpls_ttl); 295 + p->tcfm_bos = nla_get_u8_default(tb[TCA_MPLS_BOS], 296 + ACT_MPLS_BOS_NOT_SET); 297 + p->tcfm_proto = nla_get_be16_default(tb[TCA_MPLS_PROTO], 298 + htons(ETH_P_MPLS_UC)); 301 299 302 300 spin_lock_bh(&m->tcf_lock); 303 301 goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
+2 -4
net/sched/act_police.c
··· 167 167 } 168 168 if (R_tab) { 169 169 new->rate_present = true; 170 - rate64 = tb[TCA_POLICE_RATE64] ? 171 - nla_get_u64(tb[TCA_POLICE_RATE64]) : 0; 170 + rate64 = nla_get_u64_default(tb[TCA_POLICE_RATE64], 0); 172 171 psched_ratecfg_precompute(&new->rate, &R_tab->rate, rate64); 173 172 qdisc_put_rtab(R_tab); 174 173 } else { ··· 175 176 } 176 177 if (P_tab) { 177 178 new->peak_present = true; 178 - prate64 = tb[TCA_POLICE_PEAKRATE64] ? 179 - nla_get_u64(tb[TCA_POLICE_PEAKRATE64]) : 0; 179 + prate64 = nla_get_u64_default(tb[TCA_POLICE_PEAKRATE64], 0); 180 180 psched_ratecfg_precompute(&new->peak, &P_tab->rate, prate64); 181 181 qdisc_put_rtab(P_tab); 182 182 } else {
+4 -4
net/sched/cls_api.c
··· 2297 2297 } 2298 2298 block->classid = parent; 2299 2299 2300 - chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0; 2300 + chain_index = nla_get_u32_default(tca[TCA_CHAIN], 0); 2301 2301 if (chain_index > TC_ACT_EXT_VAL_MASK) { 2302 2302 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit"); 2303 2303 err = -EINVAL; ··· 2509 2509 goto errout; 2510 2510 } 2511 2511 2512 - chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0; 2512 + chain_index = nla_get_u32_default(tca[TCA_CHAIN], 0); 2513 2513 if (chain_index > TC_ACT_EXT_VAL_MASK) { 2514 2514 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit"); 2515 2515 err = -EINVAL; ··· 2664 2664 goto errout; 2665 2665 } 2666 2666 2667 - chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0; 2667 + chain_index = nla_get_u32_default(tca[TCA_CHAIN], 0); 2668 2668 if (chain_index > TC_ACT_EXT_VAL_MASK) { 2669 2669 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit"); 2670 2670 err = -EINVAL; ··· 3104 3104 if (IS_ERR(block)) 3105 3105 return PTR_ERR(block); 3106 3106 3107 - chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0; 3107 + chain_index = nla_get_u32_default(tca[TCA_CHAIN], 0); 3108 3108 if (chain_index > TC_ACT_EXT_VAL_MASK) { 3109 3109 NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit"); 3110 3110 err = -EINVAL;
+1 -1
net/sched/sch_choke.c
··· 356 356 tb[TCA_CHOKE_STAB] == NULL) 357 357 return -EINVAL; 358 358 359 - max_P = tb[TCA_CHOKE_MAX_P] ? nla_get_u32(tb[TCA_CHOKE_MAX_P]) : 0; 359 + max_P = nla_get_u32_default(tb[TCA_CHOKE_MAX_P], 0); 360 360 361 361 ctl = nla_data(tb[TCA_CHOKE_PARMS]); 362 362 stab = nla_data(tb[TCA_CHOKE_STAB]);
+1 -1
net/sched/sch_gred.c
··· 668 668 return -EINVAL; 669 669 } 670 670 671 - max_P = tb[TCA_GRED_MAX_P] ? nla_get_u32(tb[TCA_GRED_MAX_P]) : 0; 671 + max_P = nla_get_u32_default(tb[TCA_GRED_MAX_P], 0); 672 672 673 673 ctl = nla_data(tb[TCA_GRED_PARMS]); 674 674 stab = nla_data(tb[TCA_GRED_STAB]);
+2 -2
net/sched/sch_htb.c
··· 1810 1810 qdisc_put_rtab(qdisc_get_rtab(&hopt->ceil, tb[TCA_HTB_CTAB], 1811 1811 NULL)); 1812 1812 1813 - rate64 = tb[TCA_HTB_RATE64] ? nla_get_u64(tb[TCA_HTB_RATE64]) : 0; 1814 - ceil64 = tb[TCA_HTB_CEIL64] ? nla_get_u64(tb[TCA_HTB_CEIL64]) : 0; 1813 + rate64 = nla_get_u64_default(tb[TCA_HTB_RATE64], 0); 1814 + ceil64 = nla_get_u64_default(tb[TCA_HTB_CEIL64], 0); 1815 1815 1816 1816 if (!cl) { /* new class */ 1817 1817 struct net_device *dev = qdisc_dev(sch);
+1 -4
net/sched/sch_qfq.c
··· 421 421 if (err < 0) 422 422 return err; 423 423 424 - if (tb[TCA_QFQ_WEIGHT]) 425 - weight = nla_get_u32(tb[TCA_QFQ_WEIGHT]); 426 - else 427 - weight = 1; 424 + weight = nla_get_u32_default(tb[TCA_QFQ_WEIGHT], 1); 428 425 429 426 if (tb[TCA_QFQ_LMAX]) { 430 427 lmax = nla_get_u32(tb[TCA_QFQ_LMAX]);
+1 -1
net/sched/sch_red.c
··· 248 248 tb[TCA_RED_STAB] == NULL) 249 249 return -EINVAL; 250 250 251 - max_P = tb[TCA_RED_MAX_P] ? nla_get_u32(tb[TCA_RED_MAX_P]) : 0; 251 + max_P = nla_get_u32_default(tb[TCA_RED_MAX_P], 0); 252 252 253 253 ctl = nla_data(tb[TCA_RED_PARMS]); 254 254 stab = nla_data(tb[TCA_RED_STAB]);
+1 -1
net/sched/sch_taprio.c
··· 1828 1828 * zero; (2) the 'flags' of a "running" taprio instance cannot be 1829 1829 * changed. 1830 1830 */ 1831 - taprio_flags = tb[TCA_TAPRIO_ATTR_FLAGS] ? nla_get_u32(tb[TCA_TAPRIO_ATTR_FLAGS]) : 0; 1831 + taprio_flags = nla_get_u32_default(tb[TCA_TAPRIO_ATTR_FLAGS], 0); 1832 1832 1833 1833 /* txtime-assist and full offload are mutually exclusive */ 1834 1834 if ((taprio_flags & TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST) &&
+18 -36
net/wireless/nl80211.c
··· 1286 1286 { 1287 1287 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID]; 1288 1288 1289 - if (!linkid) 1290 - return 0; 1291 - 1292 - return nla_get_u8(linkid); 1289 + return nla_get_u8_default(linkid, 0); 1293 1290 } 1294 1291 1295 1292 static int nl80211_link_id_or_invalid(struct nlattr **attrs) ··· 3411 3414 if (attrs[NL80211_ATTR_CENTER_FREQ1]) { 3412 3415 chandef->center_freq1 = 3413 3416 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); 3414 - if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) 3415 - chandef->freq1_offset = nla_get_u32( 3416 - attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); 3417 - else 3418 - chandef->freq1_offset = 0; 3417 + chandef->freq1_offset = 3418 + nla_get_u32_default(attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET], 3419 + 0); 3419 3420 } 3420 3421 if (attrs[NL80211_ATTR_CENTER_FREQ2]) 3421 3422 chandef->center_freq2 = ··· 8260 8265 if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) 8261 8266 return -EINPROGRESS; 8262 8267 8263 - if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) 8264 - user_reg_hint_type = 8265 - nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); 8266 - else 8267 - user_reg_hint_type = NL80211_USER_REG_HINT_USER; 8268 + user_reg_hint_type = 8269 + nla_get_u32_default(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE], 8270 + NL80211_USER_REG_HINT_USER); 8268 8271 8269 8272 switch (user_reg_hint_type) { 8270 8273 case NL80211_USER_REG_HINT_USER: ··· 11080 11087 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 11081 11088 } 11082 11089 11083 - if (info->attrs[NL80211_ATTR_SAE_PWE]) 11084 - settings->sae_pwe = 11085 - nla_get_u8(info->attrs[NL80211_ATTR_SAE_PWE]); 11086 - else 11087 - settings->sae_pwe = NL80211_SAE_PWE_UNSPECIFIED; 11090 + settings->sae_pwe = 11091 + nla_get_u8_default(info->attrs[NL80211_ATTR_SAE_PWE], 11092 + NL80211_SAE_PWE_UNSPECIFIED); 11088 11093 11089 11094 return 0; 11090 11095 } ··· 12338 12347 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 12339 12348 return -EPERM; 12340 12349 12341 - if (!info->attrs[NL80211_ATTR_REASON_CODE]) 12342 - reason = WLAN_REASON_DEAUTH_LEAVING; 12343 - else 12344 - reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 12350 + reason = nla_get_u16_default(info->attrs[NL80211_ATTR_REASON_CODE], 12351 + WLAN_REASON_DEAUTH_LEAVING); 12345 12352 12346 12353 if (reason == 0) 12347 12354 return -EINVAL; ··· 13685 13696 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); 13686 13697 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), 13687 13698 ETH_ALEN); 13688 - if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) 13689 - port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); 13690 - else 13691 - port = 0; 13699 + port = nla_get_u16_default(tb[NL80211_WOWLAN_TCP_SRC_PORT], 0); 13692 13700 #ifdef CONFIG_INET 13693 13701 /* allocate a socket and port for it and use it */ 13694 13702 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, ··· 13896 13910 pat_len < wowlan->pattern_min_len) 13897 13911 goto error; 13898 13912 13899 - if (!pat_tb[NL80211_PKTPAT_OFFSET]) 13900 - pkt_offset = 0; 13901 - else 13902 - pkt_offset = nla_get_u32( 13903 - pat_tb[NL80211_PKTPAT_OFFSET]); 13913 + pkt_offset = 13914 + nla_get_u32_default(pat_tb[NL80211_PKTPAT_OFFSET], 13915 + 0); 13904 13916 if (pkt_offset > wowlan->max_pkt_offset) 13905 13917 goto error; 13906 13918 new_triggers.patterns[i].pkt_offset = pkt_offset; ··· 14142 14158 pat_len < coalesce->pattern_min_len) 14143 14159 return -EINVAL; 14144 14160 14145 - if (!pat_tb[NL80211_PKTPAT_OFFSET]) 14146 - pkt_offset = 0; 14147 - else 14148 - pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); 14161 + pkt_offset = nla_get_u32_default(pat_tb[NL80211_PKTPAT_OFFSET], 14162 + 0); 14149 14163 if (pkt_offset > coalesce->max_pkt_offset) 14150 14164 return -EINVAL; 14151 14165 new_rule->patterns[i].pkt_offset = pkt_offset;
+3 -5
net/xfrm/xfrm_user.c
··· 200 200 struct netlink_ext_ack *extack) 201 201 { 202 202 int err; 203 - u8 sa_dir = attrs[XFRMA_SA_DIR] ? nla_get_u8(attrs[XFRMA_SA_DIR]) : 0; 203 + u8 sa_dir = nla_get_u8_default(attrs[XFRMA_SA_DIR], 0); 204 204 u16 family = p->sel.family; 205 205 206 206 err = -EINVAL; ··· 767 767 { 768 768 if (attrs[XFRMA_SET_MARK]) { 769 769 m->v = nla_get_u32(attrs[XFRMA_SET_MARK]); 770 - if (attrs[XFRMA_SET_MARK_MASK]) 771 - m->m = nla_get_u32(attrs[XFRMA_SET_MARK_MASK]); 772 - else 773 - m->m = 0xffffffff; 770 + m->m = nla_get_u32_default(attrs[XFRMA_SET_MARK_MASK], 771 + 0xffffffff); 774 772 } else { 775 773 m->v = m->m = 0; 776 774 }