netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "David S. Miller" <davem@davemloft.net>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>
Subject: [PATCH 25/51] dcbnl: Stop using NLA_PUT*().
Date: Sun,  1 Apr 2012 22:58:15 -0400	[thread overview]
Message-ID: <1333335521-1348-26-git-send-email-davem@davemloft.net> (raw)
In-Reply-To: <1333335521-1348-1-git-send-email-davem@davemloft.net>

From: "David S. Miller" <davem@davemloft.net>

These macros contain a hidden goto, and are thus extremely error
prone and make code hard to audit.

Signed-off-by: David S. Miller <davem@davemloft.net>
---
 net/dcb/dcbnl.c |   72 ++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 42 insertions(+), 30 deletions(-)

diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index d860530..36f37af 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -1205,13 +1205,15 @@ static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
 		if (!app)
 			goto nla_put_failure;
 
-		if (app_info_type)
-			NLA_PUT(skb, app_info_type, sizeof(info), &info);
-
-		for (i = 0; i < app_count; i++)
-			NLA_PUT(skb, app_entry_type, sizeof(struct dcb_app),
-				&table[i]);
+		if (app_info_type &&
+		    nla_put(skb, app_info_type, sizeof(info), &info))
+			goto nla_put_failure;
 
+		for (i = 0; i < app_count; i++) {
+			if (nla_put(skb, app_entry_type, sizeof(struct dcb_app),
+				    &table[i]))
+				goto nla_put_failure;
+		}
 		nla_nest_end(skb, app);
 	}
 	err = 0;
@@ -1230,8 +1232,8 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
 	int dcbx;
 	int err = -EMSGSIZE;
 
-	NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name);
-
+	if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
+		goto nla_put_failure;
 	ieee = nla_nest_start(skb, DCB_ATTR_IEEE);
 	if (!ieee)
 		goto nla_put_failure;
@@ -1239,15 +1241,17 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
 	if (ops->ieee_getets) {
 		struct ieee_ets ets;
 		err = ops->ieee_getets(netdev, &ets);
-		if (!err)
-			NLA_PUT(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets);
+		if (!err &&
+		    nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets))
+			goto nla_put_failure;
 	}
 
 	if (ops->ieee_getpfc) {
 		struct ieee_pfc pfc;
 		err = ops->ieee_getpfc(netdev, &pfc);
-		if (!err)
-			NLA_PUT(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc);
+		if (!err &&
+		    nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc))
+			goto nla_put_failure;
 	}
 
 	app = nla_nest_start(skb, DCB_ATTR_IEEE_APP_TABLE);
@@ -1278,15 +1282,17 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
 	if (ops->ieee_peer_getets) {
 		struct ieee_ets ets;
 		err = ops->ieee_peer_getets(netdev, &ets);
-		if (!err)
-			NLA_PUT(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets);
+		if (!err &&
+		    nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets))
+			goto nla_put_failure;
 	}
 
 	if (ops->ieee_peer_getpfc) {
 		struct ieee_pfc pfc;
 		err = ops->ieee_peer_getpfc(netdev, &pfc);
-		if (!err)
-			NLA_PUT(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc);
+		if (!err &&
+		    nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc))
+			goto nla_put_failure;
 	}
 
 	if (ops->peer_getappinfo && ops->peer_getapptable) {
@@ -1340,10 +1346,11 @@ static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev,
 			ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0,
 					  &prio, &pgid, &tc_pct, &up_map);
 
-		NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_PGID, pgid);
-		NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
-		NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
-		NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct);
+		if (nla_put_u8(skb, DCB_TC_ATTR_PARAM_PGID, pgid) ||
+		    nla_put_u8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map) ||
+		    nla_put_u8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio) ||
+		    nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct))
+			goto nla_put_failure;
 		nla_nest_end(skb, tc_nest);
 	}
 
@@ -1356,7 +1363,8 @@ static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev,
 		else
 			ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0,
 					   &tc_pct);
-		NLA_PUT_U8(skb, i, tc_pct);
+		if (nla_put_u8(skb, i, tc_pct))
+			goto nla_put_failure;
 	}
 	nla_nest_end(skb, pg);
 	return 0;
@@ -1373,8 +1381,8 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
 	int dcbx, i, err = -EMSGSIZE;
 	u8 value;
 
-	NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name);
-
+	if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
+		goto nla_put_failure;
 	cee = nla_nest_start(skb, DCB_ATTR_CEE);
 	if (!cee)
 		goto nla_put_failure;
@@ -1401,7 +1409,8 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
 
 		for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
 			ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value);
-			NLA_PUT_U8(skb, i, value);
+			if (nla_put_u8(skb, i, value))
+				goto nla_put_failure;
 		}
 		nla_nest_end(skb, pfc_nest);
 	}
@@ -1454,8 +1463,9 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
 
 		for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX;
 		     i++)
-			if (!ops->getfeatcfg(netdev, i, &value))
-				NLA_PUT_U8(skb, i, value);
+			if (!ops->getfeatcfg(netdev, i, &value) &&
+			    nla_put_u8(skb, i, value))
+				goto nla_put_failure;
 
 		nla_nest_end(skb, feat);
 	}
@@ -1464,15 +1474,17 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
 	if (ops->cee_peer_getpg) {
 		struct cee_pg pg;
 		err = ops->cee_peer_getpg(netdev, &pg);
-		if (!err)
-			NLA_PUT(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg);
+		if (!err &&
+		    nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg))
+			goto nla_put_failure;
 	}
 
 	if (ops->cee_peer_getpfc) {
 		struct cee_pfc pfc;
 		err = ops->cee_peer_getpfc(netdev, &pfc);
-		if (!err)
-			NLA_PUT(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc);
+		if (!err &&
+		    nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc))
+			goto nla_put_failure;
 	}
 
 	if (ops->peer_getappinfo && ops->peer_getapptable) {
-- 
1.7.7.6

  parent reply	other threads:[~2012-04-02  2:59 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-02  2:57 [PATCH 00/51] Get rid of NLA_PUT*() David S. Miller
2012-04-02  2:57 ` [PATCH 01/51] xfrm_user: Stop using NLA_PUT*() David S. Miller
2012-04-02  2:57 ` [PATCH 02/51] wireless: " David S. Miller
2012-04-02  2:57 ` [PATCH 03/51] pkt_sched: " David S. Miller
2012-04-02  2:57 ` [PATCH 04/51] phonet: " David S. Miller
2012-04-02  2:57 ` [PATCH 05/51] netlink: Add nla_put_be{16,32,64}() helpers David S. Miller
2012-04-02  2:57 ` [PATCH 06/51] openvswitch: Stop using NLA_PUT*() David S. Miller
2012-04-02  2:57 ` [PATCH 07/51] nfc: " David S. Miller
2012-04-02  2:57 ` [PATCH 08/51] genetlink: " David S. Miller
2012-04-02  2:57 ` [PATCH 09/51] nfnetlink_queue: " David S. Miller
2012-04-02  2:58 ` [PATCH 10/51] nfnetlink_log: " David S. Miller
2012-04-02  2:58 ` [PATCH 11/51] nfnetlink_cttimeout: " David S. Miller
2012-04-02  2:58 ` [PATCH 12/51] nfnetlink_acct: " David S. Miller
2012-04-02  2:58 ` [PATCH 13/51] nf_conntrack_proto_udp{,lite}: " David S. Miller
2012-04-02  2:58 ` [PATCH 14/51] nf_conntrack_proto_tcp: " David S. Miller
2012-04-02  2:58 ` [PATCH 15/51] nf_conntrack_proto_sctp: " David S. Miller
2012-04-02  2:58 ` [PATCH 16/51] nf_conntrack_proto_gre: " David S. Miller
2012-04-02  2:58 ` [PATCH 17/51] nf_conntrack_proto_generic: " David S. Miller
2012-04-02  2:58 ` [PATCH 18/51] nf_conntrack_proto_dccp: " David S. Miller
2012-04-02  2:58 ` [PATCH 19/51] nf_conntrack_netlink: " David S. Miller
2012-04-02  2:58 ` [PATCH 20/51] nf_conntrack_core: " David S. Miller
2012-04-02  2:58 ` [PATCH 21/51] ipvs: " David S. Miller
2012-04-02  5:01   ` Simon Horman
2012-04-02  5:03     ` David Miller
2012-04-02  6:22       ` Simon Horman
2012-04-02  2:58 ` [PATCH 22/51] netlink: Add nla_put_net{16,32,64}() helpers David S. Miller
2012-04-02  2:58 ` [PATCH 23/51] ipset: Stop using NLA_PUT*() David S. Miller
2012-04-02  2:58 ` [PATCH 24/51] l2tp: " David S. Miller
2012-04-02  2:58 ` David S. Miller [this message]
2012-04-02  2:58 ` [PATCH 26/51] neighbour: " David S. Miller
2012-04-02  2:58 ` [PATCH 27/51] rtnetlink: " David S. Miller
2012-04-02  2:58 ` [PATCH 28/51] netlink: Add nla_put_le{16,32,64}() helpers David S. Miller
2012-04-02  2:58 ` [PATCH 29/51] decnet: Stop using NLA_PUT*() David S. Miller
2012-04-02  2:58 ` [PATCH 30/51] crypto: " David S. Miller
2012-04-02  2:58 ` [PATCH 31/51] infiniband: " David S. Miller
2012-04-02  2:58 ` [PATCH 32/51] can: " David S. Miller
2012-04-02  2:58 ` [PATCH 33/51] enic: " David S. Miller
2012-04-02  2:58 ` [PATCH 34/51] macvlan: " David S. Miller
2012-04-02  2:58 ` [PATCH 35/51] team: " David S. Miller
2012-04-02  2:58 ` [PATCH 36/51] ipv6: " David S. Miller
2012-04-02  2:58 ` [PATCH 37/51] netfilter: " David S. Miller
2012-04-02  2:58 ` [PATCH 38/51] ipv4: " David S. Miller
2012-04-02  2:58 ` [PATCH 39/51] netfilter: " David S. Miller
2012-04-02  2:58 ` [PATCH 40/51] ieee802154: " David S. Miller
2012-04-02  2:58 ` [PATCH 41/51] fib_rules: " David S. Miller
2012-04-02  2:58 ` [PATCH 42/51] gen_stats: " David S. Miller
2012-04-02  2:58 ` [PATCH 43/51] caif: " David S. Miller
2012-04-02  2:58 ` [PATCH 44/51] bridge: " David S. Miller
2012-04-02  2:58 ` [PATCH 45/51] vlan: " David S. Miller
2012-04-02  2:58 ` [PATCH 46/51] ath6kl: " David S. Miller
2012-04-02  2:58 ` [PATCH 47/51] iwlwifi: " David S. Miller
2012-04-02  2:58 ` [PATCH 48/51] mac80211_hwsim: " David S. Miller
2012-04-02  2:58 ` [PATCH 49/51] wl12xx: " David S. Miller
2012-04-02  2:58 ` [PATCH 50/51] xfrm: " David S. Miller
2012-04-02  2:58 ` [PATCH 51/51] netlink: Delete all NLA_PUT*() macros David S. Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1333335521-1348-26-git-send-email-davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).