nl802154: cleanup invalid argument handling
Subsystems (2)
Alexander Aring
maintainerPATCH 1/2 nl802154: cleanup invalid argument handling
This patch cleanups the -EINVAL cases by combining them in one condition.
Signed-off-by Alexander Aring <[email protected]>
--- net/ieee802154/nl802154.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
net/ieee802154/nl802154.c +4 -8
@@ -668,10 +668,8 @@ static int nl802154_set_pan_id(struct sk_buff *skb, struct genl_info *info)return -EBUSY ;/* don't change address fields on monitor */ -if (wpan_dev->iftype ==NL802154_IFTYPE_MONITOR ) -return -EINVAL ; - -if (!info->attrs[NL802154_ATTR_PAN_ID ]) +if (wpan_dev->iftype ==NL802154_IFTYPE_MONITOR || + !info->attrs[NL802154_ATTR_PAN_ID ])return -EINVAL ; pan_id =nla_get_le16 (info->attrs[NL802154_ATTR_PAN_ID ]);
@@ -691,10 +689,8 @@ static int nl802154_set_short_addr(struct sk_buff *skb, struct genl_info *info)return -EBUSY ;/* don't change address fields on monitor */ -if (wpan_dev->iftype ==NL802154_IFTYPE_MONITOR ) -return -EINVAL ; - -if (!info->attrs[NL802154_ATTR_SHORT_ADDR ]) +if (wpan_dev->iftype ==NL802154_IFTYPE_MONITOR || + !info->attrs[NL802154_ATTR_SHORT_ADDR ])return -EINVAL ; short_addr =nla_get_le16 (info->attrs[NL802154_ATTR_SHORT_ADDR ]);
Signature · 1 line
2.3.6
Alexander Aring
maintainerPATCH 2/2 ieee802154: move validation check out of softmac
This patch moves the value validation out of softmac layer. We need to be sure now that this value is accepted by the transceiver/mac802154 or "possible" hardmac drivers before calling rdev-ops.
Signed-off-by Alexander Aring <[email protected]>
--- net/ieee802154/nl802154.c | 28 +++++++++++++++++++++++++++- net/mac802154/cfg.c | 29 ----------------------------- 2 files changed, 27 insertions(+), 30 deletions(-)
net/ieee802154/nl802154.c +27 -1
@@ -625,7 +625,8 @@ static int nl802154_set_channel(struct sk_buff *skb, struct genl_info *info) channel =nla_get_u8 (info->attrs[NL802154_ATTR_CHANNEL ]);/* check 802.15.4 constraints */ -if (page >IEEE802154_MAX_PAGE || channel >IEEE802154_MAX_CHANNEL ) +if (page >IEEE802154_MAX_PAGE || channel >IEEE802154_MAX_CHANNEL || + !(rdev->wpan_phy.channels_supported[page] &BIT (channel)))return -EINVAL ;return rdev_set_channel (rdev, page, channel);
@@ -674,6 +675,16 @@ static int nl802154_set_pan_id(struct sk_buff *skb, struct genl_info *info) pan_id =nla_get_le16 (info->attrs[NL802154_ATTR_PAN_ID ]); +/* TODO +* I am not sure about to check here on broadcast pan_id. +* Broadcast is a valid setting, comment from 802.15.4: +* If this value is 0xffff, the device is not associated. +* +* This could useful to simple deassociate an device. +*/ +if (pan_id ==cpu_to_le16 (IEEE802154_PAN_ID_BROADCAST )) +return -EINVAL ; +return rdev_set_pan_id (rdev, wpan_dev, pan_id); }
@@ -695,6 +706,21 @@ static int nl802154_set_short_addr(struct sk_buff *skb, struct genl_info *info) short_addr =nla_get_le16 (info->attrs[NL802154_ATTR_SHORT_ADDR ]); +/* TODO +* I am not sure about to check here on broadcast short_addr. +* Broadcast is a valid setting, comment from 802.15.4: +* A value of 0xfffe indicates that the device has +* associated but has not been allocated an address. A +* value of 0xffff indicates that the device does not +* have a short address. +* +* I think we should allow to set these settings but +* don't allow to allow socket communication with it. +*/ +if (short_addr ==cpu_to_le16 (IEEE802154_ADDR_SHORT_UNSPEC ) || + short_addr ==cpu_to_le16 (IEEE802154_ADDR_SHORT_BROADCAST )) +return -EINVAL ; +return rdev_set_short_addr (rdev, wpan_dev, short_addr); }
net/mac802154/cfg.c +0 -29
@@ -73,10 +73,6 @@ ieee802154_set_channel(struct wpan_phy *wpan_phy, u8 page, u8 channel)ASSERT_RTNL (); -/* check if phy support this setting */ -if (!(wpan_phy->channels_supported[page] &BIT (channel))) -return -EINVAL ; - ret =drv_set_channel (local, page, channel);if (!ret) { wpan_phy->current_page = page;
@@ -112,16 +108,6 @@ ieee802154_set_pan_id(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, {ASSERT_RTNL (); -/* TODO -* I am not sure about to check here on broadcast pan_id. -* Broadcast is a valid setting, comment from 802.15.4: -* If this value is 0xffff, the device is not associated. -* -* This could useful to simple deassociate an device. -*/ -if (pan_id ==cpu_to_le16 (IEEE802154_PAN_ID_BROADCAST )) -return -EINVAL ; - wpan_dev->pan_id = pan_id;return 0 ; }
@@ -149,21 +135,6 @@ ieee802154_set_short_addr(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, {ASSERT_RTNL (); -/* TODO -* I am not sure about to check here on broadcast short_addr. -* Broadcast is a valid setting, comment from 802.15.4: -* A value of 0xfffe indicates that the device has -* associated but has not been allocated an address. A -* value of 0xffff indicates that the device does not -* have a short address. -* -* I think we should allow to set these settings but -* don't allow to allow socket communication with it. -*/ -if (short_addr ==cpu_to_le16 (IEEE802154_ADDR_SHORT_UNSPEC ) || - short_addr ==cpu_to_le16 (IEEE802154_ADDR_SHORT_BROADCAST )) -return -EINVAL ; - wpan_dev->short_addr = short_addr;return 0 ; }
Signature · 1 line
2.3.6
Quoted 28 lines · Alexander Aring
This patch cleanups the
-EINVALcases by combining them in one condition.Signed-off-by Alexander Aring <[email protected]>--- net/ieee802154/nl802154.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)net/ieee802154/nl802154.c +2
-4@@ -668,10 +668,8 @@ static int nl802154_set_pan_id(struct sk_buff *skb, struct genl_info *info)return -EBUSY ;/* don't change address fields on monitor */ -if (wpan_dev->iftype ==NL802154_IFTYPE_MONITOR ) -return -EINVAL ; - -if (!info->attrs[NL802154_ATTR_PAN_ID ]) +if (wpan_dev->iftype ==NL802154_IFTYPE_MONITOR || + !info->attrs[NL802154_ATTR_PAN_ID ])return -EINVAL ; pan_id =nla_get_le16 (info->attrs[NL802154_ATTR_PAN_ID ]);@@ -691,10 +689,8 @@ static int nl802154_set_short_addr(struct sk_buff *skb, struct genl_info *info)return -EBUSY ;
net/ieee802154/nl802154.c static int nl802154_set_short_addr(struct sk_buff *skb, struct genl_info *info) · line 696
Quoted 10 lines
net/ieee802154/nl802154.c +2
-4/* don't change address fields on monitor */ -if (wpan_dev->iftype ==NL802154_IFTYPE_MONITOR ) -return -EINVAL ; - -if (!info->attrs[NL802154_ATTR_SHORT_ADDR ]) +if (wpan_dev->iftype ==NL802154_IFTYPE_MONITOR || + !info->attrs[NL802154_ATTR_SHORT_ADDR ])return -EINVAL ; short_addr =nla_get_le16 (info->attrs[NL802154_ATTR_SHORT_ADDR ]);
ACK