diff mbox series

[1/1] ieee802154: fix error return code in ieee802154_add_iface()

Message ID 20210508062517.2574-1-thunder.leizhen@huawei.com (mailing list archive)
State Accepted
Headers show
Series [1/1] ieee802154: fix error return code in ieee802154_add_iface() | expand

Commit Message

Leizhen (ThunderTown) May 8, 2021, 6:25 a.m. UTC
Fix to return a negative error code from the error handling
case instead of 0, as done elsewhere in this function.

Fixes: be51da0f3e34 ("ieee802154: Stop using NLA_PUT*().")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 net/ieee802154/nl-phy.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Stefan Schmidt June 3, 2021, 8:53 a.m. UTC | #1
Hello.

On 08.05.21 08:25, Zhen Lei wrote:
> Fix to return a negative error code from the error handling
> case instead of 0, as done elsewhere in this function.
> 
> Fixes: be51da0f3e34 ("ieee802154: Stop using NLA_PUT*().")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>   net/ieee802154/nl-phy.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
> index 2cdc7e63fe17..88215b5c93aa 100644
> --- a/net/ieee802154/nl-phy.c
> +++ b/net/ieee802154/nl-phy.c
> @@ -241,8 +241,10 @@ int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
>   	}
>   
>   	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)) {
> +		rc = -EMSGSIZE;
>   		goto nla_put_failure;
> +	}
>   	dev_put(dev);
>   
>   	wpan_phy_put(phy);
> 

Good find. We could indeed hit a case where the IEEE802154_ATTR_HW_ADDR 
attribute is present and rc would be assigned 0 before reaching this 
goto nla_put_failure

This patch has been applied to the wpan tree and will be
part of the next pull request to net. Thanks!

regards
Stefan Schmidt
diff mbox series

Patch

diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
index 2cdc7e63fe17..88215b5c93aa 100644
--- a/net/ieee802154/nl-phy.c
+++ b/net/ieee802154/nl-phy.c
@@ -241,8 +241,10 @@  int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
 	}
 
 	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)) {
+		rc = -EMSGSIZE;
 		goto nla_put_failure;
+	}
 	dev_put(dev);
 
 	wpan_phy_put(phy);