Discussion:
Fix oops in wlan_setup on 2.6.27-rc3
Richard Kennedy
2008-08-19 15:19:43 UTC
Permalink
Fix oops in wlan_setup on 2.6.27-rc3

oops caused by not setting up network device queues.

Change wlan_setup to use the kernel provided alloc_netdev() rather than
hand coding it. This should help avoid any future problems.

Also change register_wlandev to not call dev_alloc_name() as
register_netdev() will do that if the device name has been setup.

Signed-off-by: Richard Kennedy <***@rsk.demon.co.uk>
----

both of these functions have existed for many kernel versions so we
could enable this to cover them, but I haven't tested it. I haven't
checked how long alloc_netdev() has existed, but we could look it up in
git if anyone cares.

Patch is against latest git & works on 2.6.27-rc3.

Richard



diff --git a/src/p80211/p80211netdev.c b/src/p80211/p80211netdev.c
index c8d879a..14d1329 100644
--- a/src/p80211/p80211netdev.c
+++ b/src/p80211/p80211netdev.c
@@ -869,6 +869,30 @@ static int wlan_change_mtu(netdevice_t *dev, int new_mtu)
return 0;
}

+/*---------------------------------------------------------
+ * wlan_alloc_netdev
+ *
+ * create a netdev properly over different kernel versions
+ * this should work with kernels earlier than 2.6.26, and if
+ * anyone cares they can change it
+----------------------------------------------------------*/
+
+static inline netdevice_t * wlan_alloc_netdev() {
+ netdevice_t *dev;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) )
+ dev = alloc_netdev(0,"wlan%d",ether_setup);
+#else
+ dev = kmalloc(sizeof(netdevice_t), GFP_ATOMIC);
+ if ( dev ) {
+ memset( dev, 0, sizeof(netdevice_t));
+ ether_setup(dev);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) )
+ dev->nd_net = &init_net;
+#endif
+ }
+#endif
+ return dev;
+}


/*----------------------------------------------------------------
@@ -911,14 +935,12 @@ int wlan_setup(wlandevice_t *wlandev)
p80211netdev_rx_bh,
(unsigned long)wlandev);

- /* Allocate and initialize the struct device */
- dev = kmalloc(sizeof(netdevice_t), GFP_ATOMIC);
+ /* Allocate and initialize the struct net device */
+ dev = wlan_alloc_netdev();
if ( dev == NULL ) {
WLAN_LOG_ERROR("Failed to alloc netdev.\n");
result = 1;
} else {
- memset( dev, 0, sizeof(netdevice_t));
- ether_setup(dev);
wlandev->netdev = dev;
dev->priv = wlandev;
dev->hard_start_xmit = p80211knetdev_hard_start_xmit;
@@ -946,10 +968,8 @@ int wlan_setup(wlandevice_t *wlandev)
dev->wireless_handlers = &p80211wext_handler_def;
#endif
#endif
-
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) )
- dev_net_set(dev, &init_net);
-#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) )
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
dev->nd_net = &init_net;
#endif

@@ -1044,7 +1064,12 @@ int register_wlandev(wlandevice_t *wlandev)
netdevice_t *dev = wlandev->netdev;

DBFENTER;
-
+/* alloc_netdev already sets up the name */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) )
+ i = register_netdev(dev);
+ if (i)
+ return i;
+#else
i = dev_alloc_name(wlandev->netdev, "wlan%d");
if (i >= 0) {
i = register_netdev(wlandev->netdev);
@@ -1058,6 +1083,8 @@ int register_wlandev(wlandevice_t *wlandev)
#else
strcpy(wlandev->name, dev->name);
#endif
+#endif
+

#ifdef CONFIG_PROC_FS
if (proc_p80211) {
Solomon Peachy
2008-09-30 14:57:11 UTC
Permalink
Post by Richard Kennedy
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
dev->nd_net = &init_net;
#endif
Any reason you left this in, when it's either implicitly or explicitly
handled by wlan_alloc_netdev() ?

- Solomon
--
Solomon Peachy ***@linux-wlan.com
AbsoluteValue Systems http://www.linux-wlan.com
721-D North Drive +1 (321) 259-0737 (office)
Melbourne, FL 32934 +1 (321) 259-0286 (fax)
Richard Kennedy
2008-09-30 15:39:34 UTC
Permalink
Post by Solomon Peachy
Post by Richard Kennedy
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
dev->nd_net = &init_net;
#endif
Any reason you left this in, when it's either implicitly or explicitly
handled by wlan_alloc_netdev() ?
- Solomon
Sorry, I left that in by mistake.

Richard
Solomon Peachy
2008-09-30 17:16:40 UTC
Permalink
Post by Richard Kennedy
Post by Solomon Peachy
Any reason you left this in, when it's either implicitly or explicitly
handled by wlan_alloc_netdev() ?
Sorry, I left that in by mistake.
No problem; your patch (minus that chunk) was committed.

Thanks for your work, and I apologize agin for the delay in getting it
merged.

- Solomon
--
Solomon Peachy ***@linux-wlan.com
AbsoluteValue Systems http://www.linux-wlan.com
721-D North Drive +1 (321) 259-0737 (office)
Melbourne, FL 32934 +1 (321) 259-0286 (fax)
Loading...