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

netlink: Improve returned error codes

Make nlmsg_trim(), nlmsg_cancel(), genlmsg_cancel(), and
nla_nest_cancel() void functions.

Return -EMSGSIZE instead of -1 if the provided message buffer is not
big enough.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Thomas Graf and committed by
David S. Miller
bc3ed28c 1f9d11c7

+42 -32
+2 -2
include/net/genetlink.h
··· 162 162 * @skb: socket buffer the message is stored in 163 163 * @hdr: generic netlink message header 164 164 */ 165 - static inline int genlmsg_cancel(struct sk_buff *skb, void *hdr) 165 + static inline void genlmsg_cancel(struct sk_buff *skb, void *hdr) 166 166 { 167 - return nlmsg_cancel(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN); 167 + nlmsg_cancel(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN); 168 168 } 169 169 170 170 /**
+9 -11
include/net/netlink.h
··· 556 556 * @skb: socket buffer the message is stored in 557 557 * @mark: mark to trim to 558 558 * 559 - * Trims the message to the provided mark. Returns -1. 559 + * Trims the message to the provided mark. 560 560 */ 561 - static inline int nlmsg_trim(struct sk_buff *skb, const void *mark) 561 + static inline void nlmsg_trim(struct sk_buff *skb, const void *mark) 562 562 { 563 563 if (mark) 564 564 skb_trim(skb, (unsigned char *) mark - skb->data); 565 - 566 - return -1; 567 565 } 568 566 569 567 /** ··· 570 572 * @nlh: netlink message header 571 573 * 572 574 * Removes the complete netlink message including all 573 - * attributes from the socket buffer again. Returns -1. 575 + * attributes from the socket buffer again. 574 576 */ 575 - static inline int nlmsg_cancel(struct sk_buff *skb, struct nlmsghdr *nlh) 577 + static inline void nlmsg_cancel(struct sk_buff *skb, struct nlmsghdr *nlh) 576 578 { 577 - return nlmsg_trim(skb, nlh); 579 + nlmsg_trim(skb, nlh); 578 580 } 579 581 580 582 /** ··· 773 775 int nested_len = nla_len(nla) - NLA_ALIGN(len); 774 776 775 777 if (nested_len < 0) 776 - return -1; 778 + return -EINVAL; 777 779 if (nested_len >= nla_attr_size(0)) 778 780 return nla_parse(tb, maxtype, nla_data(nla) + NLA_ALIGN(len), 779 781 nested_len, policy); ··· 1078 1080 * @start: container attribute 1079 1081 * 1080 1082 * Removes the container attribute and including all nested 1081 - * attributes. Returns -1. 1083 + * attributes. Returns -EMSGSIZE 1082 1084 */ 1083 - static inline int nla_nest_cancel(struct sk_buff *skb, struct nlattr *start) 1085 + static inline void nla_nest_cancel(struct sk_buff *skb, struct nlattr *start) 1084 1086 { 1085 - return nlmsg_trim(skb, start); 1087 + nlmsg_trim(skb, start); 1086 1088 } 1087 1089 1088 1090 /**
+2 -1
net/core/neighbour.c
··· 1714 1714 return nla_nest_end(skb, nest); 1715 1715 1716 1716 nla_put_failure: 1717 - return nla_nest_cancel(skb, nest); 1717 + nla_nest_cancel(skb, nest); 1718 + return -EMSGSIZE; 1718 1719 } 1719 1720 1720 1721 static int neightbl_fill_info(struct sk_buff *skb, struct neigh_table *tbl,
+2 -1
net/core/rtnetlink.c
··· 498 498 return nla_nest_end(skb, mx); 499 499 500 500 nla_put_failure: 501 - return nla_nest_cancel(skb, mx); 501 + nla_nest_cancel(skb, mx); 502 + return -EMSGSIZE; 502 503 } 503 504 504 505 int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id,
+6 -6
net/netlink/attr.c
··· 400 400 * @attrlen: length of attribute payload 401 401 * @data: head of attribute payload 402 402 * 403 - * Returns -1 if the tailroom of the skb is insufficient to store 403 + * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store 404 404 * the attribute header and payload. 405 405 */ 406 406 int nla_put(struct sk_buff *skb, int attrtype, int attrlen, const void *data) 407 407 { 408 408 if (unlikely(skb_tailroom(skb) < nla_total_size(attrlen))) 409 - return -1; 409 + return -EMSGSIZE; 410 410 411 411 __nla_put(skb, attrtype, attrlen, data); 412 412 return 0; ··· 418 418 * @attrlen: length of attribute payload 419 419 * @data: head of attribute payload 420 420 * 421 - * Returns -1 if the tailroom of the skb is insufficient to store 421 + * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store 422 422 * the attribute payload. 423 423 */ 424 424 int nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data) 425 425 { 426 426 if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen))) 427 - return -1; 427 + return -EMSGSIZE; 428 428 429 429 __nla_put_nohdr(skb, attrlen, data); 430 430 return 0; ··· 436 436 * @attrlen: length of attribute payload 437 437 * @data: head of attribute payload 438 438 * 439 - * Returns -1 if the tailroom of the skb is insufficient to store 439 + * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store 440 440 * the attribute payload. 441 441 */ 442 442 int nla_append(struct sk_buff *skb, int attrlen, const void *data) 443 443 { 444 444 if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen))) 445 - return -1; 445 + return -EMSGSIZE; 446 446 447 447 memcpy(skb_put(skb, attrlen), data, attrlen); 448 448 return 0;
+4 -2
net/netlink/genetlink.c
··· 554 554 return genlmsg_end(skb, hdr); 555 555 556 556 nla_put_failure: 557 - return genlmsg_cancel(skb, hdr); 557 + genlmsg_cancel(skb, hdr); 558 + return -EMSGSIZE; 558 559 } 559 560 560 561 static int ctrl_fill_mcgrp_info(struct genl_multicast_group *grp, u32 pid, ··· 591 590 return genlmsg_end(skb, hdr); 592 591 593 592 nla_put_failure: 594 - return genlmsg_cancel(skb, hdr); 593 + genlmsg_cancel(skb, hdr); 594 + return -EMSGSIZE; 595 595 } 596 596 597 597 static int ctrl_dumpfamily(struct sk_buff *skb, struct netlink_callback *cb)
+4 -2
net/sched/sch_dsmark.c
··· 444 444 return nla_nest_end(skb, opts); 445 445 446 446 nla_put_failure: 447 - return nla_nest_cancel(skb, opts); 447 + nla_nest_cancel(skb, opts); 448 + return -EMSGSIZE; 448 449 } 449 450 450 451 static int dsmark_dump(struct Qdisc *sch, struct sk_buff *skb) ··· 467 466 return nla_nest_end(skb, opts); 468 467 469 468 nla_put_failure: 470 - return nla_nest_cancel(skb, opts); 469 + nla_nest_cancel(skb, opts); 470 + return -EMSGSIZE; 471 471 } 472 472 473 473 static const struct Qdisc_class_ops dsmark_class_ops = {
+2 -1
net/sched/sch_gred.c
··· 582 582 return nla_nest_end(skb, opts); 583 583 584 584 nla_put_failure: 585 - return nla_nest_cancel(skb, opts); 585 + nla_nest_cancel(skb, opts); 586 + return -EMSGSIZE; 586 587 } 587 588 588 589 static void gred_destroy(struct Qdisc *sch)
+1 -1
net/sched/sch_hfsc.c
··· 1360 1360 1361 1361 nla_put_failure: 1362 1362 nla_nest_cancel(skb, nest); 1363 - return -1; 1363 + return -EMSGSIZE; 1364 1364 } 1365 1365 1366 1366 static int
+2 -1
net/sched/sch_red.c
··· 281 281 return nla_nest_end(skb, opts); 282 282 283 283 nla_put_failure: 284 - return nla_nest_cancel(skb, opts); 284 + nla_nest_cancel(skb, opts); 285 + return -EMSGSIZE; 285 286 } 286 287 287 288 static int red_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
+8 -4
net/wireless/nl80211.c
··· 187 187 return genlmsg_end(msg, hdr); 188 188 189 189 nla_put_failure: 190 - return genlmsg_cancel(msg, hdr); 190 + genlmsg_cancel(msg, hdr); 191 + return -EMSGSIZE; 191 192 } 192 193 193 194 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) ··· 274 273 return genlmsg_end(msg, hdr); 275 274 276 275 nla_put_failure: 277 - return genlmsg_cancel(msg, hdr); 276 + genlmsg_cancel(msg, hdr); 277 + return -EMSGSIZE; 278 278 } 279 279 280 280 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) ··· 930 928 return genlmsg_end(msg, hdr); 931 929 932 930 nla_put_failure: 933 - return genlmsg_cancel(msg, hdr); 931 + genlmsg_cancel(msg, hdr); 932 + return -EMSGSIZE; 934 933 } 935 934 936 935 static int nl80211_dump_station(struct sk_buff *skb, ··· 1270 1267 return genlmsg_end(msg, hdr); 1271 1268 1272 1269 nla_put_failure: 1273 - return genlmsg_cancel(msg, hdr); 1270 + genlmsg_cancel(msg, hdr); 1271 + return -EMSGSIZE; 1274 1272 } 1275 1273 1276 1274 static int nl80211_dump_mpath(struct sk_buff *skb,