[OpenWrt-Devel] [PATCH 4/5] netifd: Check device_claim return code in all cases

Hans Dedecker dedeckeh at gmail.com
Wed Jun 18 02:55:47 EDT 2014


Fixes observed issue a tunnel interface is reported as up although device_claim failed

Signed-off-by: Hans Dedecker <dedeckeh at gmail.com>
---
 interface.c   |   12 ++++++++----
 proto-shell.c |    4 +++-
 vlan.c        |    2 +-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/interface.c b/interface.c
index 6ca1d0d..b0fe9de 100644
--- a/interface.c
+++ b/interface.c
@@ -766,8 +766,10 @@ interface_set_l3_dev(struct interface *iface, struct device *dev)
 	device_add_user(&iface->l3_dev, dev);
 
 	if (dev) {
-		if (claimed)
-			device_claim(&iface->l3_dev);
+		if (claimed) {
+			if (device_claim(&iface->l3_dev) < 0)
+				return;
+		}
 		interface_ip_set_enabled(&iface->config_ip, enabled);
 	}
 }
@@ -787,8 +789,10 @@ interface_set_main_dev(struct interface *iface, struct device *dev)
 		return;
 	}
 
-	if (claimed)
-		device_claim(&iface->l3_dev);
+	if (claimed) {
+		if (device_claim(&iface->l3_dev) < 0)
+			return;
+	}
 
 	if (!iface->l3_dev.dev)
 		interface_set_l3_dev(iface, dev);
diff --git a/proto-shell.c b/proto-shell.c
index c4039ed..9fad3a0 100644
--- a/proto-shell.c
+++ b/proto-shell.c
@@ -463,7 +463,9 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data,
 			return UBUS_STATUS_INVALID_ARGUMENT;
 
 		interface_set_l3_dev(iface, dev);
-		device_claim(&iface->l3_dev);
+		if (device_claim(&iface->l3_dev) < 0)
+			return UBUS_STATUS_UNKNOWN_ERROR;
+
 		device_set_present(dev, true);
 
 		interface_update_start(iface);
diff --git a/vlan.c b/vlan.c
index 28e561b..28b1441 100644
--- a/vlan.c
+++ b/vlan.c
@@ -50,7 +50,7 @@ static int vlan_set_device_state(struct device *dev, bool up)
 	}
 
 	ret = device_claim(&vldev->dep);
-	if (ret)
+	if (ret < 0)
 		return ret;
 
 	system_vlan_add(vldev->dep.dev, vldev->id);
-- 
1.7.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list