Skip to content

Commit a885a6b

Browse files
jmberg-intelkuba-moo
authored andcommitted
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 <[email protected]> Reviewed-by: Toke Høiland-Jørgensen <[email protected]> Link: https://patch.msgid.link/20241108114145.0580b8684e7f.I740beeaa2f70ebfc19bfca1045a24d6151992790@changeid Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7f4b396 commit a885a6b

40 files changed

+126
-236
lines changed

drivers/net/amt.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,15 +3206,11 @@ static int amt_newlink(struct net *net, struct net_device *dev,
32063206
goto err;
32073207
}
32083208

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));
32133211

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));
32183214

32193215
if (!amt->relay_port) {
32203216
NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_AMT_DISCOVERY_IP],

drivers/net/gtp.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,10 +1491,8 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev,
14911491
}
14921492
gtp->role = role;
14931493

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);
14981496

14991497
gtp->net = src_net;
15001498

@@ -1829,10 +1827,7 @@ static struct pdp_ctx *gtp_pdp_add(struct gtp_dev *gtp, struct sock *sk,
18291827

18301828
version = nla_get_u32(info->attrs[GTPA_VERSION]);
18311829

1832-
if (info->attrs[GTPA_FAMILY])
1833-
family = nla_get_u8(info->attrs[GTPA_FAMILY]);
1834-
else
1835-
family = AF_INET;
1830+
family = nla_get_u8_default(info->attrs[GTPA_FAMILY], AF_INET);
18361831

18371832
#if !IS_ENABLED(CONFIG_IPV6)
18381833
if (family == AF_INET6)
@@ -2069,10 +2064,7 @@ static struct pdp_ctx *gtp_find_pdp_by_link(struct net *net,
20692064
struct gtp_dev *gtp;
20702065
int family;
20712066

2072-
if (nla[GTPA_FAMILY])
2073-
family = nla_get_u8(nla[GTPA_FAMILY]);
2074-
else
2075-
family = AF_INET;
2067+
family = nla_get_u8_default(nla[GTPA_FAMILY], AF_INET);
20762068

20772069
gtp = gtp_find_dev(net, nla);
20782070
if (!gtp)

drivers/net/macsec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,9 +4299,9 @@ static int macsec_validate_attr(struct nlattr *tb[], struct nlattr *data[],
42994299
}
43004300
}
43014301

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);
43054305

43064306
if ((sci && (scb || es)) || (scb && es))
43074307
return -EINVAL;

drivers/net/vxlan/vxlan_core.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,10 +1232,7 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan,
12321232
*ifindex = 0;
12331233
}
12341234

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);
12391236

12401237
return 0;
12411238
}

net/8021q/vlan_netlink.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,8 @@ static int vlan_newlink(struct net *src_net, struct net_device *dev,
161161
return -ENODEV;
162162
}
163163

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));
168166

169167
vlan->vlan_proto = proto;
170168
vlan->vlan_id = nla_get_u16(data[IFLA_VLAN_ID]);

net/core/fib_rules.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,7 @@ static int fib_nl2rule(struct sk_buff *skb, struct nlmsghdr *nlh,
558558
nlrule->pref = fib_default_rule_pref(ops);
559559
}
560560

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);
563562

564563
if (tb[FRA_IIFNAME]) {
565564
struct net_device *dev;

net/core/rtnetlink.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,10 +2940,7 @@ static int do_setlink(const struct sk_buff *skb, struct net_device *dev,
29402940
const char *pat = ifname[0] ? ifname : NULL;
29412941
int new_ifindex;
29422942

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);
29472944

29482945
err = __dev_change_net_namespace(dev, tgt_net, pat, new_ifindex);
29492946
if (err)

net/devlink/dev.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,8 @@ int devlink_nl_reload_doit(struct sk_buff *skb, struct genl_info *info)
531531
return err;
532532
}
533533

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);
538536

539537
if (!devlink_reload_action_is_supported(devlink, action)) {
540538
NL_SET_ERR_MSG(info->extack, "Requested reload action is not supported by the driver");

net/hsr/hsr_netlink.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
8282
return -EINVAL;
8383
}
8484

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);
8986

9087
if (data[IFLA_HSR_PROTOCOL])
9188
proto = nla_get_u8(data[IFLA_HSR_PROTOCOL]);

net/ieee802154/nl-mac.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,7 @@ int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info)
202202
addr.pan_id = nla_get_shortaddr(
203203
info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
204204

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);
209206

210207
ret = ieee802154_mlme_ops(dev)->assoc_req(dev, &addr,
211208
nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]),
@@ -338,10 +335,7 @@ int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
338335
blx = nla_get_u8(info->attrs[IEEE802154_ATTR_BAT_EXT]);
339336
coord_realign = nla_get_u8(info->attrs[IEEE802154_ATTR_COORD_REALIGN]);
340337

341-
if (info->attrs[IEEE802154_ATTR_PAGE])
342-
page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
343-
else
344-
page = 0;
338+
page = nla_get_u8_default(info->attrs[IEEE802154_ATTR_PAGE], 0);
345339

346340
if (addr.short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST)) {
347341
ieee802154_nl_start_confirm(dev, IEEE802154_NO_SHORT_ADDRESS);
@@ -388,10 +382,7 @@ int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
388382
channels = nla_get_u32(info->attrs[IEEE802154_ATTR_CHANNELS]);
389383
duration = nla_get_u8(info->attrs[IEEE802154_ATTR_DURATION]);
390384

391-
if (info->attrs[IEEE802154_ATTR_PAGE])
392-
page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
393-
else
394-
page = 0;
385+
page = nla_get_u8_default(info->attrs[IEEE802154_ATTR_PAGE], 0);
395386

396387
ret = ieee802154_mlme_ops(dev)->scan_req(dev, type, channels,
397388
page, duration);

net/ieee802154/nl802154.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,22 +1438,18 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info)
14381438
}
14391439

14401440
/* 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);
14451443

14461444
/* 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]);
14511448

14521449
/* 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);
14571453

14581454
err = rdev_trigger_scan(rdev, request);
14591455
if (err) {
@@ -1598,10 +1594,8 @@ nl802154_send_beacons(struct sk_buff *skb, struct genl_info *info)
15981594
request->wpan_phy = wpan_phy;
15991595

16001596
/* Use maximum duration order by default */
1601-
if (info->attrs[NL802154_ATTR_BEACON_INTERVAL])
1602-
request->interval = nla_get_u8(info->attrs[NL802154_ATTR_BEACON_INTERVAL]);
1603-
else
1604-
request->interval = IEEE802154_MAX_SCAN_DURATION;
1597+
request->interval = nla_get_u8_default(info->attrs[NL802154_ATTR_BEACON_INTERVAL],
1598+
IEEE802154_MAX_SCAN_DURATION);
16051599

16061600
err = rdev_send_beacons(rdev, request);
16071601
if (err) {

net/ipv4/devinet.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,7 @@ static struct in_ifaddr *inet_rtm_to_ifa(struct net *net, struct nlmsghdr *nlh,
926926

927927
ifa->ifa_prefixlen = ifm->ifa_prefixlen;
928928
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);
931930
ifa->ifa_scope = ifm->ifa_scope;
932931
ifa->ifa_local = nla_get_in_addr(tb[IFA_LOCAL]);
933932
ifa->ifa_address = nla_get_in_addr(tb[IFA_ADDRESS]);

net/ipv4/ipmr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,9 +2546,9 @@ static int ipmr_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
25462546
if (err < 0)
25472547
goto errout;
25482548

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);
25522552

25532553
mrt = ipmr_get_table(net, tableid ? tableid : RT_TABLE_DEFAULT);
25542554
if (!mrt) {

net/ipv4/nexthop.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,12 +3247,8 @@ static int nh_valid_get_del_req(const struct nlmsghdr *nlh,
32473247
return -EINVAL;
32483248
}
32493249

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);
32563252

32573253
return 0;
32583254
}
@@ -3433,10 +3429,7 @@ static int nh_valid_dump_req(const struct nlmsghdr *nlh,
34333429
if (err < 0)
34343430
return err;
34353431

3436-
if (tb[NHA_OP_FLAGS])
3437-
filter->op_flags = nla_get_u32(tb[NHA_OP_FLAGS]);
3438-
else
3439-
filter->op_flags = 0;
3432+
filter->op_flags = nla_get_u32_default(tb[NHA_OP_FLAGS], 0);
34403433

34413434
return __nh_valid_dump_req(nlh, tb, filter, cb->extack);
34423435
}

net/ipv4/route.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,10 +3231,10 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
32313231
return err;
32323232

32333233
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);
32383238
if (tb[RTA_UID])
32393239
uid = make_kuid(current_user_ns(), nla_get_u32(tb[RTA_UID]));
32403240
else
@@ -3260,7 +3260,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
32603260
fl4.daddr = dst;
32613261
fl4.saddr = src;
32623262
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);
32643264
fl4.flowi4_mark = mark;
32653265
fl4.flowi4_uid = uid;
32663266
if (sport)

net/ipv6/addrconf.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4793,7 +4793,7 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh,
47934793
if (!pfx)
47944794
return -EINVAL;
47954795

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);
47974797

47984798
/* We ignore other flags so far. */
47994799
ifa_flags &= IFA_F_MANAGETEMPADDR;
@@ -5018,10 +5018,7 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
50185018
return -ENODEV;
50195019
}
50205020

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);
50255022

50265023
/* We ignore other flags so far. */
50275024
cfg.ifa_flags &= IFA_F_NODAD | IFA_F_HOMEADDRESS |

net/ipv6/ila/ila_xlat.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,11 @@ static int parse_nl_config(struct genl_info *info,
105105
xp->ip.locator_match.v64 = (__force __be64)nla_get_u64(
106106
info->attrs[ILA_ATTR_LOCATOR_MATCH]);
107107

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;
112-
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;
108+
xp->ip.csum_mode = nla_get_u8_default(info->attrs[ILA_ATTR_CSUM_MODE],
109+
ILA_CSUM_NO_ACTION);
110+
111+
xp->ip.ident_type = nla_get_u8_default(info->attrs[ILA_ATTR_IDENT_TYPE],
112+
ILA_ATYPE_USE_FORMAT);
118113

119114
if (info->attrs[ILA_ATTR_IFINDEX])
120115
xp->ifindex = nla_get_s32(info->attrs[ILA_ATTR_IFINDEX]);

net/ipv6/ioam6.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,11 @@ static int ioam6_genl_addns(struct sk_buff *skb, struct genl_info *info)
135135

136136
ns->id = id;
137137

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]);
142-
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]);
138+
data32 = nla_get_u32_default(info->attrs[IOAM6_ATTR_NS_DATA],
139+
IOAM6_U32_UNAVAILABLE);
140+
141+
data64 = nla_get_u64_default(info->attrs[IOAM6_ATTR_NS_DATA_WIDE],
142+
IOAM6_U64_UNAVAILABLE);
147143

148144
ns->data = cpu_to_be32(data32);
149145
ns->data_wide = cpu_to_be64(data64);

net/ipv6/ioam6_iptunnel.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,8 @@ static int ioam6_build_state(struct net *net, struct nlattr *nla,
142142
}
143143
}
144144

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);
149147

150148
if (tb[IOAM6_IPTUNNEL_SRC] && mode == IOAM6_IPTUNNEL_MODE_INLINE) {
151149
NL_SET_ERR_MSG(extack, "no tunnel src expected with this mode");

net/ipv6/ip6mr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,7 @@ static int ip6mr_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
25602560
src = nla_get_in6_addr(tb[RTA_SRC]);
25612561
if (tb[RTA_DST])
25622562
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);
25642564

25652565
mrt = ip6mr_get_table(net, tableid ?: RT_TABLE_DEFAULT);
25662566
if (!mrt) {

net/netfilter/ipvs/ip_vs_ctl.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,10 +3662,7 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
36623662
nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr));
36633663
udest->port = nla_get_be16(nla_port);
36643664

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);
36693666

36703667
/* If a full entry was requested, check for the additional fields */
36713668
if (full_entry) {

0 commit comments

Comments
 (0)