ieee802154: keep the original error after a netns rollback
Subsystems (3)
PATCH 1/1 ieee802154: keep the original error after a netns rollback
cfg802154_switch_netns() moves all of a phy's netdevs into a new netns. If one move fails, it jumps to the errout label and moves the already-moved netdevs back to the old netns.
That rollback loop overwrites the same 'err' variable with the result of each move-back. The move-backs succeed, so 'err' ends up 0 and the function returns 0 -- success -- even though nothing moved and the phy stayed in the old netns. nl802154_wpan_phy_netns() then tells userspace the move worked.
Keep the original error in a separate variable and return that.
---
Found during a backport review.
On debian13 6.12.88, "iwpan phy phy0 set netns name T" reported success (returned 0) while phy0 and its wpan0 interface stayed in the original namespace; internally the move had failed with -EEXIST, but the function returned 0 anyway. With the fix the same command correctly fails with "File exists".
net/ieee802154/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ieee802154/core.c +3 -1
@@ -222,6 +222,7 @@ {struct wpan_dev *wpan_dev;int err =0 ; +int ret;list_for_each_entry (wpan_dev, &rdev->wpan_dev_list, list) {if (!wpan_dev->netdev)
@@ -249,6 +250,7 @@return 0 ; errout: + ret = err;/* failed -- clean up to old netns */ net =wpan_phy_net (&rdev->wpan_phy);
@@ -264,7 +266,7 @@ wpan_dev->netdev->netns_immutable = true; } -return err; +return ret; }void cfg802154_dev_free (struct cfg802154_registered_device *rdev)
Miquel Raynal
maintainerHello Andrey,
Quoted 18 lines
+++
b/net/ieee802154/core.cnet/ieee802154/core.c +2
-0@@ -222,6 +222,7 @@ {struct wpan_dev *wpan_dev;int err =0 ; +int ret;list_for_each_entry (wpan_dev, &rdev->wpan_dev_list, list) {if (!wpan_dev->netdev)@@ -249,6 +250,7 @@return 0 ; errout: + ret = err;/* failed -- clean up to old netns */ net =wpan_phy_net (&rdev->wpan_phy);
net/ieee802154/core.c line 266
Quoted 1 line
net/ieee802154/core.c +0
-0@@ -264,7 +266,7 @@ wpan_dev->netdev->netns_immutable = true;
Shall we just shadow int err in this loop? the current implementation is correct but is a bit strange (having ret and err next to each other).
net/ieee802154/core.c line 272
Quoted 7 lines
net/ieee802154/core.c +1
-1} -return err; +return ret; }void cfg802154_dev_free (struct cfg802154_registered_device *rdev)
Thanks,
Miquèl