Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc3ed28c authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller
Browse files

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: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1f9d11c7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -162,9 +162,9 @@ static inline int genlmsg_end(struct sk_buff *skb, void *hdr)
 * @skb: socket buffer the message is stored in
 * @hdr: generic netlink message header
 */
static inline int genlmsg_cancel(struct sk_buff *skb, void *hdr)
static inline void genlmsg_cancel(struct sk_buff *skb, void *hdr)
{
	return nlmsg_cancel(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN);
	nlmsg_cancel(skb, hdr - GENL_HDRLEN - NLMSG_HDRLEN);
}

/**
+9 −11
Original line number Diff line number Diff line
@@ -556,14 +556,12 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
 * @skb: socket buffer the message is stored in
 * @mark: mark to trim to
 *
 * Trims the message to the provided mark. Returns -1.
 * Trims the message to the provided mark.
 */
static inline int nlmsg_trim(struct sk_buff *skb, const void *mark)
static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
{
	if (mark)
		skb_trim(skb, (unsigned char *) mark - skb->data);

	return -1;
}

/**
@@ -572,11 +570,11 @@ static inline int nlmsg_trim(struct sk_buff *skb, const void *mark)
 * @nlh: netlink message header
 *
 * Removes the complete netlink message including all
 * attributes from the socket buffer again. Returns -1.
 * attributes from the socket buffer again.
 */
static inline int nlmsg_cancel(struct sk_buff *skb, struct nlmsghdr *nlh)
static inline void nlmsg_cancel(struct sk_buff *skb, struct nlmsghdr *nlh)
{
	return nlmsg_trim(skb, nlh);
	nlmsg_trim(skb, nlh);
}

/**
@@ -775,7 +773,7 @@ static inline int __nla_parse_nested_compat(struct nlattr *tb[], int maxtype,
	int nested_len = nla_len(nla) - NLA_ALIGN(len);

	if (nested_len < 0)
		return -1;
		return -EINVAL;
	if (nested_len >= nla_attr_size(0))
		return nla_parse(tb, maxtype, nla_data(nla) + NLA_ALIGN(len),
				 nested_len, policy);
@@ -1080,11 +1078,11 @@ static inline int nla_nest_compat_end(struct sk_buff *skb, struct nlattr *start)
 * @start: container attribute
 *
 * Removes the container attribute and including all nested
 * attributes. Returns -1.
 * attributes. Returns -EMSGSIZE
 */
static inline int nla_nest_cancel(struct sk_buff *skb, struct nlattr *start)
static inline void nla_nest_cancel(struct sk_buff *skb, struct nlattr *start)
{
	return nlmsg_trim(skb, start);
	nlmsg_trim(skb, start);
}

/**
+2 −1
Original line number Diff line number Diff line
@@ -1714,7 +1714,8 @@ static int neightbl_fill_parms(struct sk_buff *skb, struct neigh_parms *parms)
	return nla_nest_end(skb, nest);

nla_put_failure:
	return nla_nest_cancel(skb, nest);
	nla_nest_cancel(skb, nest);
	return -EMSGSIZE;
}

static int neightbl_fill_info(struct sk_buff *skb, struct neigh_table *tbl,
+2 −1
Original line number Diff line number Diff line
@@ -498,7 +498,8 @@ int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics)
	return nla_nest_end(skb, mx);

nla_put_failure:
	return nla_nest_cancel(skb, mx);
	nla_nest_cancel(skb, mx);
	return -EMSGSIZE;
}

int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id,
+6 −6
Original line number Diff line number Diff line
@@ -400,13 +400,13 @@ void __nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data)
 * @attrlen: length of attribute payload
 * @data: head of attribute payload
 *
 * Returns -1 if the tailroom of the skb is insufficient to store
 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
 * the attribute header and payload.
 */
int nla_put(struct sk_buff *skb, int attrtype, int attrlen, const void *data)
{
	if (unlikely(skb_tailroom(skb) < nla_total_size(attrlen)))
		return -1;
		return -EMSGSIZE;

	__nla_put(skb, attrtype, attrlen, data);
	return 0;
@@ -418,13 +418,13 @@ int nla_put(struct sk_buff *skb, int attrtype, int attrlen, const void *data)
 * @attrlen: length of attribute payload
 * @data: head of attribute payload
 *
 * Returns -1 if the tailroom of the skb is insufficient to store
 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
 * the attribute payload.
 */
int nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data)
{
	if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen)))
		return -1;
		return -EMSGSIZE;

	__nla_put_nohdr(skb, attrlen, data);
	return 0;
@@ -436,13 +436,13 @@ int nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data)
 * @attrlen: length of attribute payload
 * @data: head of attribute payload
 *
 * Returns -1 if the tailroom of the skb is insufficient to store
 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
 * the attribute payload.
 */
int nla_append(struct sk_buff *skb, int attrlen, const void *data)
{
	if (unlikely(skb_tailroom(skb) < NLA_ALIGN(attrlen)))
		return -1;
		return -EMSGSIZE;

	memcpy(skb_put(skb, attrlen), data, attrlen);
	return 0;
Loading