Commit be51da0f authored by David S. Miller's avatar David S. Miller

ieee802154: 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: default avatarDavid S. Miller <davem@davemloft.net>
parent d317e4f6
...@@ -63,15 +63,14 @@ int ieee802154_nl_assoc_indic(struct net_device *dev, ...@@ -63,15 +63,14 @@ int ieee802154_nl_assoc_indic(struct net_device *dev,
if (!msg) if (!msg)
return -ENOBUFS; return -ENOBUFS;
NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
dev->dev_addr); dev->dev_addr) ||
nla_put(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN,
NLA_PUT(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN, addr->hwaddr) ||
addr->hwaddr); nla_put_u8(msg, IEEE802154_ATTR_CAPABILITY, cap))
goto nla_put_failure;
NLA_PUT_U8(msg, IEEE802154_ATTR_CAPABILITY, cap);
return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
...@@ -92,14 +91,13 @@ int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr, ...@@ -92,14 +91,13 @@ int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr,
if (!msg) if (!msg)
return -ENOBUFS; return -ENOBUFS;
NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
dev->dev_addr); dev->dev_addr) ||
nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) ||
NLA_PUT_U16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr); nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status); goto nla_put_failure;
return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
nla_put_failure: nla_put_failure:
...@@ -119,20 +117,22 @@ int ieee802154_nl_disassoc_indic(struct net_device *dev, ...@@ -119,20 +117,22 @@ int ieee802154_nl_disassoc_indic(struct net_device *dev,
if (!msg) if (!msg)
return -ENOBUFS; return -ENOBUFS;
NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
dev->dev_addr); dev->dev_addr))
goto nla_put_failure;
if (addr->addr_type == IEEE802154_ADDR_LONG) if (addr->addr_type == IEEE802154_ADDR_LONG) {
NLA_PUT(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN, if (nla_put(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN,
addr->hwaddr); addr->hwaddr))
else goto nla_put_failure;
NLA_PUT_U16(msg, IEEE802154_ATTR_SRC_SHORT_ADDR, } else {
addr->short_addr); if (nla_put_u16(msg, IEEE802154_ATTR_SRC_SHORT_ADDR,
addr->short_addr))
NLA_PUT_U8(msg, IEEE802154_ATTR_REASON, reason); goto nla_put_failure;
}
if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason))
goto nla_put_failure;
return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
nla_put_failure: nla_put_failure:
...@@ -151,13 +151,12 @@ int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status) ...@@ -151,13 +151,12 @@ int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status)
if (!msg) if (!msg)
return -ENOBUFS; return -ENOBUFS;
NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
dev->dev_addr); dev->dev_addr) ||
nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status); goto nla_put_failure;
return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
nla_put_failure: nla_put_failure:
...@@ -177,13 +176,13 @@ int ieee802154_nl_beacon_indic(struct net_device *dev, ...@@ -177,13 +176,13 @@ int ieee802154_nl_beacon_indic(struct net_device *dev,
if (!msg) if (!msg)
return -ENOBUFS; return -ENOBUFS;
NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
dev->dev_addr); dev->dev_addr) ||
NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr); nla_put_u16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr) ||
NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid); nla_put_u16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid))
goto nla_put_failure;
return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
nla_put_failure: nla_put_failure:
...@@ -204,19 +203,17 @@ int ieee802154_nl_scan_confirm(struct net_device *dev, ...@@ -204,19 +203,17 @@ int ieee802154_nl_scan_confirm(struct net_device *dev,
if (!msg) if (!msg)
return -ENOBUFS; return -ENOBUFS;
NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
dev->dev_addr); dev->dev_addr) ||
nla_put_u8(msg, IEEE802154_ATTR_STATUS, status) ||
NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status); nla_put_u8(msg, IEEE802154_ATTR_SCAN_TYPE, scan_type) ||
NLA_PUT_U8(msg, IEEE802154_ATTR_SCAN_TYPE, scan_type); nla_put_u32(msg, IEEE802154_ATTR_CHANNELS, unscanned) ||
NLA_PUT_U32(msg, IEEE802154_ATTR_CHANNELS, unscanned); nla_put_u8(msg, IEEE802154_ATTR_PAGE, page) ||
NLA_PUT_U8(msg, IEEE802154_ATTR_PAGE, page); (edl &&
nla_put(msg, IEEE802154_ATTR_ED_LIST, 27, edl)))
if (edl) goto nla_put_failure;
NLA_PUT(msg, IEEE802154_ATTR_ED_LIST, 27, edl);
return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
nla_put_failure: nla_put_failure:
...@@ -235,13 +232,12 @@ int ieee802154_nl_start_confirm(struct net_device *dev, u8 status) ...@@ -235,13 +232,12 @@ int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)
if (!msg) if (!msg)
return -ENOBUFS; return -ENOBUFS;
NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
dev->dev_addr); dev->dev_addr) ||
nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status); goto nla_put_failure;
return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
nla_put_failure: nla_put_failure:
...@@ -266,16 +262,16 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 pid, ...@@ -266,16 +262,16 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 pid,
phy = ieee802154_mlme_ops(dev)->get_phy(dev); phy = ieee802154_mlme_ops(dev)->get_phy(dev);
BUG_ON(!phy); BUG_ON(!phy);
NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)); nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex); nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN, dev->dev_addr) ||
dev->dev_addr); nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR,
NLA_PUT_U16(msg, IEEE802154_ATTR_SHORT_ADDR, ieee802154_mlme_ops(dev)->get_short_addr(dev)) ||
ieee802154_mlme_ops(dev)->get_short_addr(dev)); nla_put_u16(msg, IEEE802154_ATTR_PAN_ID,
NLA_PUT_U16(msg, IEEE802154_ATTR_PAN_ID, ieee802154_mlme_ops(dev)->get_pan_id(dev)))
ieee802154_mlme_ops(dev)->get_pan_id(dev)); goto nla_put_failure;
wpan_phy_put(phy); wpan_phy_put(phy);
return genlmsg_end(msg, hdr); return genlmsg_end(msg, hdr);
......
...@@ -53,18 +53,18 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid, ...@@ -53,18 +53,18 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid,
goto out; goto out;
mutex_lock(&phy->pib_lock); mutex_lock(&phy->pib_lock);
NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)); if (nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
nla_put_u8(msg, IEEE802154_ATTR_PAGE, phy->current_page) ||
NLA_PUT_U8(msg, IEEE802154_ATTR_PAGE, phy->current_page); nla_put_u8(msg, IEEE802154_ATTR_CHANNEL, phy->current_channel))
NLA_PUT_U8(msg, IEEE802154_ATTR_CHANNEL, phy->current_channel); goto nla_put_failure;
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
if (phy->channels_supported[i]) if (phy->channels_supported[i])
buf[pages++] = phy->channels_supported[i] | (i << 27); buf[pages++] = phy->channels_supported[i] | (i << 27);
} }
if (pages) if (pages &&
NLA_PUT(msg, IEEE802154_ATTR_CHANNEL_PAGE_LIST, nla_put(msg, IEEE802154_ATTR_CHANNEL_PAGE_LIST,
pages * sizeof(uint32_t), buf); pages * sizeof(uint32_t), buf))
goto nla_put_failure;
mutex_unlock(&phy->pib_lock); mutex_unlock(&phy->pib_lock);
kfree(buf); kfree(buf);
return genlmsg_end(msg, hdr); return genlmsg_end(msg, hdr);
...@@ -245,9 +245,9 @@ static int ieee802154_add_iface(struct sk_buff *skb, ...@@ -245,9 +245,9 @@ static int ieee802154_add_iface(struct sk_buff *skb,
goto dev_unregister; goto dev_unregister;
} }
NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)); if (nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name); nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name))
goto nla_put_failure;
dev_put(dev); dev_put(dev);
wpan_phy_put(phy); wpan_phy_put(phy);
...@@ -333,10 +333,9 @@ static int ieee802154_del_iface(struct sk_buff *skb, ...@@ -333,10 +333,9 @@ static int ieee802154_del_iface(struct sk_buff *skb,
rtnl_unlock(); rtnl_unlock();
if (nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)); nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, name))
NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, name); goto nla_put_failure;
wpan_phy_put(phy); wpan_phy_put(phy);
return ieee802154_nl_reply(msg, info); return ieee802154_nl_reply(msg, info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment