diff options
author | David S. Miller <davem@davemloft.net> | 2012-04-01 20:03:01 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-04-02 04:33:41 -0400 |
commit | 1eb4c977778b5ab8e8fba9022687f0a5941d681a (patch) | |
tree | 4b56513ec81622d7aa2ee319d0777fb441d987cb /net/dcb/dcbnl.c | |
parent | 60aed2abb3f6a713c3a9beda1436866079ee146c (diff) |
dcbnl: Stop using NLA_PUT*().
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>
Diffstat (limited to 'net/dcb/dcbnl.c')
-rw-r--r-- | 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 d86053002c16..36f37af63bf2 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, | |||
1205 | if (!app) | 1205 | if (!app) |
1206 | goto nla_put_failure; | 1206 | goto nla_put_failure; |
1207 | 1207 | ||
1208 | if (app_info_type) | 1208 | if (app_info_type && |
1209 | NLA_PUT(skb, app_info_type, sizeof(info), &info); | 1209 | nla_put(skb, app_info_type, sizeof(info), &info)) |
1210 | 1210 | goto nla_put_failure; | |
1211 | for (i = 0; i < app_count; i++) | ||
1212 | NLA_PUT(skb, app_entry_type, sizeof(struct dcb_app), | ||
1213 | &table[i]); | ||
1214 | 1211 | ||
1212 | for (i = 0; i < app_count; i++) { | ||
1213 | if (nla_put(skb, app_entry_type, sizeof(struct dcb_app), | ||
1214 | &table[i])) | ||
1215 | goto nla_put_failure; | ||
1216 | } | ||
1215 | nla_nest_end(skb, app); | 1217 | nla_nest_end(skb, app); |
1216 | } | 1218 | } |
1217 | err = 0; | 1219 | err = 0; |
@@ -1230,8 +1232,8 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) | |||
1230 | int dcbx; | 1232 | int dcbx; |
1231 | int err = -EMSGSIZE; | 1233 | int err = -EMSGSIZE; |
1232 | 1234 | ||
1233 | NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name); | 1235 | if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name)) |
1234 | 1236 | goto nla_put_failure; | |
1235 | ieee = nla_nest_start(skb, DCB_ATTR_IEEE); | 1237 | ieee = nla_nest_start(skb, DCB_ATTR_IEEE); |
1236 | if (!ieee) | 1238 | if (!ieee) |
1237 | goto nla_put_failure; | 1239 | goto nla_put_failure; |
@@ -1239,15 +1241,17 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) | |||
1239 | if (ops->ieee_getets) { | 1241 | if (ops->ieee_getets) { |
1240 | struct ieee_ets ets; | 1242 | struct ieee_ets ets; |
1241 | err = ops->ieee_getets(netdev, &ets); | 1243 | err = ops->ieee_getets(netdev, &ets); |
1242 | if (!err) | 1244 | if (!err && |
1243 | NLA_PUT(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets); | 1245 | nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets)) |
1246 | goto nla_put_failure; | ||
1244 | } | 1247 | } |
1245 | 1248 | ||
1246 | if (ops->ieee_getpfc) { | 1249 | if (ops->ieee_getpfc) { |
1247 | struct ieee_pfc pfc; | 1250 | struct ieee_pfc pfc; |
1248 | err = ops->ieee_getpfc(netdev, &pfc); | 1251 | err = ops->ieee_getpfc(netdev, &pfc); |
1249 | if (!err) | 1252 | if (!err && |
1250 | NLA_PUT(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc); | 1253 | nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc)) |
1254 | goto nla_put_failure; | ||
1251 | } | 1255 | } |
1252 | 1256 | ||
1253 | app = nla_nest_start(skb, DCB_ATTR_IEEE_APP_TABLE); | 1257 | 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) | |||
1278 | if (ops->ieee_peer_getets) { | 1282 | if (ops->ieee_peer_getets) { |
1279 | struct ieee_ets ets; | 1283 | struct ieee_ets ets; |
1280 | err = ops->ieee_peer_getets(netdev, &ets); | 1284 | err = ops->ieee_peer_getets(netdev, &ets); |
1281 | if (!err) | 1285 | if (!err && |
1282 | NLA_PUT(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets); | 1286 | nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets)) |
1287 | goto nla_put_failure; | ||
1283 | } | 1288 | } |
1284 | 1289 | ||
1285 | if (ops->ieee_peer_getpfc) { | 1290 | if (ops->ieee_peer_getpfc) { |
1286 | struct ieee_pfc pfc; | 1291 | struct ieee_pfc pfc; |
1287 | err = ops->ieee_peer_getpfc(netdev, &pfc); | 1292 | err = ops->ieee_peer_getpfc(netdev, &pfc); |
1288 | if (!err) | 1293 | if (!err && |
1289 | NLA_PUT(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc); | 1294 | nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc)) |
1295 | goto nla_put_failure; | ||
1290 | } | 1296 | } |
1291 | 1297 | ||
1292 | if (ops->peer_getappinfo && ops->peer_getapptable) { | 1298 | 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, | |||
1340 | ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0, | 1346 | ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0, |
1341 | &prio, &pgid, &tc_pct, &up_map); | 1347 | &prio, &pgid, &tc_pct, &up_map); |
1342 | 1348 | ||
1343 | NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_PGID, pgid); | 1349 | if (nla_put_u8(skb, DCB_TC_ATTR_PARAM_PGID, pgid) || |
1344 | NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map); | 1350 | nla_put_u8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map) || |
1345 | NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio); | 1351 | nla_put_u8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio) || |
1346 | NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct); | 1352 | nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct)) |
1353 | goto nla_put_failure; | ||
1347 | nla_nest_end(skb, tc_nest); | 1354 | nla_nest_end(skb, tc_nest); |
1348 | } | 1355 | } |
1349 | 1356 | ||
@@ -1356,7 +1363,8 @@ static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev, | |||
1356 | else | 1363 | else |
1357 | ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0, | 1364 | ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0, |
1358 | &tc_pct); | 1365 | &tc_pct); |
1359 | NLA_PUT_U8(skb, i, tc_pct); | 1366 | if (nla_put_u8(skb, i, tc_pct)) |
1367 | goto nla_put_failure; | ||
1360 | } | 1368 | } |
1361 | nla_nest_end(skb, pg); | 1369 | nla_nest_end(skb, pg); |
1362 | return 0; | 1370 | return 0; |
@@ -1373,8 +1381,8 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev) | |||
1373 | int dcbx, i, err = -EMSGSIZE; | 1381 | int dcbx, i, err = -EMSGSIZE; |
1374 | u8 value; | 1382 | u8 value; |
1375 | 1383 | ||
1376 | NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name); | 1384 | if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name)) |
1377 | 1385 | goto nla_put_failure; | |
1378 | cee = nla_nest_start(skb, DCB_ATTR_CEE); | 1386 | cee = nla_nest_start(skb, DCB_ATTR_CEE); |
1379 | if (!cee) | 1387 | if (!cee) |
1380 | goto nla_put_failure; | 1388 | goto nla_put_failure; |
@@ -1401,7 +1409,8 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev) | |||
1401 | 1409 | ||
1402 | for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) { | 1410 | for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) { |
1403 | ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value); | 1411 | ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value); |
1404 | NLA_PUT_U8(skb, i, value); | 1412 | if (nla_put_u8(skb, i, value)) |
1413 | goto nla_put_failure; | ||
1405 | } | 1414 | } |
1406 | nla_nest_end(skb, pfc_nest); | 1415 | nla_nest_end(skb, pfc_nest); |
1407 | } | 1416 | } |
@@ -1454,8 +1463,9 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev) | |||
1454 | 1463 | ||
1455 | for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX; | 1464 | for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX; |
1456 | i++) | 1465 | i++) |
1457 | if (!ops->getfeatcfg(netdev, i, &value)) | 1466 | if (!ops->getfeatcfg(netdev, i, &value) && |
1458 | NLA_PUT_U8(skb, i, value); | 1467 | nla_put_u8(skb, i, value)) |
1468 | goto nla_put_failure; | ||
1459 | 1469 | ||
1460 | nla_nest_end(skb, feat); | 1470 | nla_nest_end(skb, feat); |
1461 | } | 1471 | } |
@@ -1464,15 +1474,17 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev) | |||
1464 | if (ops->cee_peer_getpg) { | 1474 | if (ops->cee_peer_getpg) { |
1465 | struct cee_pg pg; | 1475 | struct cee_pg pg; |
1466 | err = ops->cee_peer_getpg(netdev, &pg); | 1476 | err = ops->cee_peer_getpg(netdev, &pg); |
1467 | if (!err) | 1477 | if (!err && |
1468 | NLA_PUT(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg); | 1478 | nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg)) |
1479 | goto nla_put_failure; | ||
1469 | } | 1480 | } |
1470 | 1481 | ||
1471 | if (ops->cee_peer_getpfc) { | 1482 | if (ops->cee_peer_getpfc) { |
1472 | struct cee_pfc pfc; | 1483 | struct cee_pfc pfc; |
1473 | err = ops->cee_peer_getpfc(netdev, &pfc); | 1484 | err = ops->cee_peer_getpfc(netdev, &pfc); |
1474 | if (!err) | 1485 | if (!err && |
1475 | NLA_PUT(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc); | 1486 | nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc)) |
1487 | goto nla_put_failure; | ||
1476 | } | 1488 | } |
1477 | 1489 | ||
1478 | if (ops->peer_getappinfo && ops->peer_getapptable) { | 1490 | if (ops->peer_getappinfo && ops->peer_getapptable) { |