From 29521f9a232f039318fd8525c410b3127836626f Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Mon, 6 Jun 2016 14:58:31 +0200 Subject: device: Fix device find failure in avl list due to device name change As device name is used as key in avl list a device name change will break the avl find logic. Function device_set_ifname offers api to set the device name and re-inserts the avl node in the list when the avl key value is changed. Signed-off-by: Hans Dedecker --- vlan.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'vlan.c') diff --git a/vlan.c b/vlan.c index ac434ce..7f8697b 100644 --- a/vlan.c +++ b/vlan.c @@ -63,8 +63,11 @@ static int vlan_set_device_state(struct device *dev, bool up) static void vlan_dev_set_name(struct vlan_device *vldev, struct device *dev) { + char name[IFNAMSIZ]; + vldev->dev.hidden = dev->hidden; - snprintf(vldev->dev.ifname, IFNAMSIZ, "%s.%d", dev->ifname, vldev->id); + snprintf(name, IFNAMSIZ, "%s.%d", dev->ifname, vldev->id); + device_set_ifname(&vldev->dev, name); } static void vlan_dev_cb(struct device_user *dep, enum device_event ev) @@ -81,7 +84,6 @@ static void vlan_dev_cb(struct device_user *dep, enum device_event ev) break; case DEV_EVENT_UPDATE_IFNAME: vlan_dev_set_name(vldev, dep->dev); - device_broadcast_event(&vldev->dev, ev); break; case DEV_EVENT_TOPO_CHANGE: /* Propagate topo changes */ @@ -124,9 +126,10 @@ static struct device *get_vlan_device(struct device *dev, int id, bool create) return NULL; vldev->id = id; - vlan_dev_set_name(vldev, dev); - device_init(&vldev->dev, &vlan_type, vldev->dev.ifname); + device_init(&vldev->dev, &vlan_type, NULL); + + vlan_dev_set_name(vldev, dev); vldev->dev.default_config = true; vldev->set_state = vldev->dev.set_state; -- cgit v1.2.3