[OpenWrt-Devel] [RFC netifd] Out-of-sync reference counter causes seg. fault

Kristian Evensen kristian.evensen at gmail.com
Wed Jun 18 12:12:59 EDT 2014

From: Kristian Evensen <kristian.evensen at gmail.com>


I have written a small tool which automatically adds/removes a usb LAN dongle
from uci. When the USB device is inserted, I add entries to UCI (using libuci)
and do network reload (using libubus). When the device is removed, I remove the
UCI-entries and do reload again.

This all works fine. However, when I connect the device a second time, netifd
crashes with a seg. fault. The problem seems to be that the reference counter is
not reduced properly when device remove, and device is not properly removed from
internal data structures.

The missing reference counter update seems to be in device_release(). After
adding a call to device_remove_user() here, the reference counter is correct,
device is correctly removed and netifd is stable. I have also tested by
adding/removing other types of network devices, and netifd seems to work fine.

However, I am not familiar enough with the internal architecture of netifd to
know if this is a correct fix or just a dirty hack. If this is a hack, does
anyone have any feedback or hints to how I can properly solve this issue?

 device.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/device.c b/device.c
index 7d606c6..f44a891 100644
--- a/device.c
+++ b/device.c
@@ -250,6 +250,8 @@ void device_release(struct device_user *dep)
 	D(DEVICE, "Release %s %s, new active count: %d\n", dev->type->name, dev->ifname, dev->active);
 	assert(dev->active >= 0);
+	device_remove_user(dep);
 	if (dev->active)
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list