diff options
author | Johannes Berg <johannes.berg@intel.com> | 2015-01-16 16:09:00 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-01-18 01:03:45 -0500 |
commit | 053c095a82cf773075e83d7233b5cc19a1f73ece (patch) | |
tree | c787028efa9a73a182a0f338f87b6294cef4b8b9 /net/xfrm | |
parent | ede58ef28e105de94475b2b69fa069c9a2ce6933 (diff) |
netlink: make nlmsg_end() and genlmsg_end() void
Contrary to common expectations for an "int" return, these functions
return only a positive value -- if used correctly they cannot even
return 0 because the message header will necessarily be in the skb.
This makes the very common pattern of
if (genlmsg_end(...) < 0) { ... }
be a whole bunch of dead code. Many places also simply do
return nlmsg_end(...);
and the caller is expected to deal with it.
This also commonly (at least for me) causes errors, because it is very
common to write
if (my_function(...))
/* error condition */
and if my_function() does "return nlmsg_end()" this is of course wrong.
Additionally, there's not a single place in the kernel that actually
needs the message length returned, and if anyone needs it later then
it'll be very easy to just use skb->len there.
Remove this, and make the functions void. This removes a bunch of dead
code as described above. The patch adds lines because I did
- return nlmsg_end(...);
+ nlmsg_end(...);
+ return 0;
I could have preserved all the function's return values by returning
skb->len, but instead I've audited all the places calling the affected
functions and found that none cared. A few places actually compared
the return value with <= 0 in dump functionality, but that could just
be changed to < 0 with no change in behaviour, so I opted for the more
efficient version.
One instance of the error I've made numerous times now is also present
in net/phonet/pn_netlink.c in the route_dumpit() function - it didn't
check for <0 or <=0 and thus broke out of the loop every single time.
I've preserved this since it will (I think) have caused the messages to
userspace to be formatted differently with just a single message for
every SKB returned to userspace. It's possible that this isn't needed
for the tools that actually use this, but I don't even know what they
are so couldn't test that changing this behaviour would be acceptable.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/xfrm')
-rw-r--r-- | net/xfrm/xfrm_user.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 8128594ab379..7de2ed9ec46d 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c | |||
@@ -1019,7 +1019,8 @@ static int build_spdinfo(struct sk_buff *skb, struct net *net, | |||
1019 | return err; | 1019 | return err; |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | return nlmsg_end(skb, nlh); | 1022 | nlmsg_end(skb, nlh); |
1023 | return 0; | ||
1023 | } | 1024 | } |
1024 | 1025 | ||
1025 | static int xfrm_set_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh, | 1026 | static int xfrm_set_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh, |
@@ -1121,7 +1122,8 @@ static int build_sadinfo(struct sk_buff *skb, struct net *net, | |||
1121 | return err; | 1122 | return err; |
1122 | } | 1123 | } |
1123 | 1124 | ||
1124 | return nlmsg_end(skb, nlh); | 1125 | nlmsg_end(skb, nlh); |
1126 | return 0; | ||
1125 | } | 1127 | } |
1126 | 1128 | ||
1127 | static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh, | 1129 | static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh, |
@@ -1842,7 +1844,8 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, const struct | |||
1842 | if (err) | 1844 | if (err) |
1843 | goto out_cancel; | 1845 | goto out_cancel; |
1844 | 1846 | ||
1845 | return nlmsg_end(skb, nlh); | 1847 | nlmsg_end(skb, nlh); |
1848 | return 0; | ||
1846 | 1849 | ||
1847 | out_cancel: | 1850 | out_cancel: |
1848 | nlmsg_cancel(skb, nlh); | 1851 | nlmsg_cancel(skb, nlh); |
@@ -2282,7 +2285,8 @@ static int build_migrate(struct sk_buff *skb, const struct xfrm_migrate *m, | |||
2282 | goto out_cancel; | 2285 | goto out_cancel; |
2283 | } | 2286 | } |
2284 | 2287 | ||
2285 | return nlmsg_end(skb, nlh); | 2288 | nlmsg_end(skb, nlh); |
2289 | return 0; | ||
2286 | 2290 | ||
2287 | out_cancel: | 2291 | out_cancel: |
2288 | nlmsg_cancel(skb, nlh); | 2292 | nlmsg_cancel(skb, nlh); |
@@ -2490,7 +2494,8 @@ static int build_expire(struct sk_buff *skb, struct xfrm_state *x, const struct | |||
2490 | if (err) | 2494 | if (err) |
2491 | return err; | 2495 | return err; |
2492 | 2496 | ||
2493 | return nlmsg_end(skb, nlh); | 2497 | nlmsg_end(skb, nlh); |
2498 | return 0; | ||
2494 | } | 2499 | } |
2495 | 2500 | ||
2496 | static int xfrm_exp_state_notify(struct xfrm_state *x, const struct km_event *c) | 2501 | static int xfrm_exp_state_notify(struct xfrm_state *x, const struct km_event *c) |
@@ -2712,7 +2717,8 @@ static int build_acquire(struct sk_buff *skb, struct xfrm_state *x, | |||
2712 | return err; | 2717 | return err; |
2713 | } | 2718 | } |
2714 | 2719 | ||
2715 | return nlmsg_end(skb, nlh); | 2720 | nlmsg_end(skb, nlh); |
2721 | return 0; | ||
2716 | } | 2722 | } |
2717 | 2723 | ||
2718 | static int xfrm_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *xt, | 2724 | static int xfrm_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *xt, |
@@ -2827,7 +2833,8 @@ static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp, | |||
2827 | } | 2833 | } |
2828 | upe->hard = !!hard; | 2834 | upe->hard = !!hard; |
2829 | 2835 | ||
2830 | return nlmsg_end(skb, nlh); | 2836 | nlmsg_end(skb, nlh); |
2837 | return 0; | ||
2831 | } | 2838 | } |
2832 | 2839 | ||
2833 | static int xfrm_exp_policy_notify(struct xfrm_policy *xp, int dir, const struct km_event *c) | 2840 | static int xfrm_exp_policy_notify(struct xfrm_policy *xp, int dir, const struct km_event *c) |
@@ -2986,7 +2993,8 @@ static int build_report(struct sk_buff *skb, u8 proto, | |||
2986 | return err; | 2993 | return err; |
2987 | } | 2994 | } |
2988 | } | 2995 | } |
2989 | return nlmsg_end(skb, nlh); | 2996 | nlmsg_end(skb, nlh); |
2997 | return 0; | ||
2990 | } | 2998 | } |
2991 | 2999 | ||
2992 | static int xfrm_send_report(struct net *net, u8 proto, | 3000 | static int xfrm_send_report(struct net *net, u8 proto, |
@@ -3031,7 +3039,8 @@ static int build_mapping(struct sk_buff *skb, struct xfrm_state *x, | |||
3031 | um->old_sport = x->encap->encap_sport; | 3039 | um->old_sport = x->encap->encap_sport; |
3032 | um->reqid = x->props.reqid; | 3040 | um->reqid = x->props.reqid; |
3033 | 3041 | ||
3034 | return nlmsg_end(skb, nlh); | 3042 | nlmsg_end(skb, nlh); |
3043 | return 0; | ||
3035 | } | 3044 | } |
3036 | 3045 | ||
3037 | static int xfrm_send_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, | 3046 | static int xfrm_send_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, |