Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
[firefly-linux-kernel-4.4.55.git] / net / ieee802154 / nl-phy.c
index c64a38d57aa36c4b521fd06c7a9c8c46bd0f337b..eed291626da6a2a229d00b4304b9695a1195c2ae 100644 (file)
@@ -53,18 +53,18 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid,
                goto out;
 
        mutex_lock(&phy->pib_lock);
-       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_CHANNEL, phy->current_channel);
+       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_CHANNEL, phy->current_channel))
+               goto nla_put_failure;
        for (i = 0; i < 32; i++) {
                if (phy->channels_supported[i])
                        buf[pages++] = phy->channels_supported[i] | (i << 27);
        }
-       if (pages)
-               NLA_PUT(msg, IEEE802154_ATTR_CHANNEL_PAGE_LIST,
-                               pages * sizeof(uint32_t), buf);
-
+       if (pages &&
+           nla_put(msg, IEEE802154_ATTR_CHANNEL_PAGE_LIST,
+                   pages * sizeof(uint32_t), buf))
+               goto nla_put_failure;
        mutex_unlock(&phy->pib_lock);
        kfree(buf);
        return genlmsg_end(msg, hdr);
@@ -179,6 +179,7 @@ static int ieee802154_add_iface(struct sk_buff *skb,
        const char *devname;
        int rc = -ENOBUFS;
        struct net_device *dev;
+       int type = __IEEE802154_DEV_INVALID;
 
        pr_debug("%s\n", __func__);
 
@@ -221,7 +222,13 @@ static int ieee802154_add_iface(struct sk_buff *skb,
                goto nla_put_failure;
        }
 
-       dev = phy->add_iface(phy, devname);
+       if (info->attrs[IEEE802154_ATTR_DEV_TYPE]) {
+               type = nla_get_u8(info->attrs[IEEE802154_ATTR_DEV_TYPE]);
+               if (type >= __IEEE802154_DEV_MAX)
+                       return -EINVAL;
+       }
+
+       dev = phy->add_iface(phy, devname, type);
        if (IS_ERR(dev)) {
                rc = PTR_ERR(dev);
                goto nla_put_failure;
@@ -245,9 +252,9 @@ static int ieee802154_add_iface(struct sk_buff *skb,
                        goto dev_unregister;
        }
 
-       NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy));
-       NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
-
+       if (nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
+           nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name))
+               goto nla_put_failure;
        dev_put(dev);
 
        wpan_phy_put(phy);
@@ -333,10 +340,9 @@ static int ieee802154_del_iface(struct sk_buff *skb,
 
        rtnl_unlock();
 
-
-       NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy));
-       NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, name);
-
+       if (nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
+           nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, name))
+               goto nla_put_failure;
        wpan_phy_put(phy);
 
        return ieee802154_nl_reply(msg, info);