Skip to contentSkip to conversation

bug in /net/core/dev.c

DISCUSSION [email protected] 2 participants 2 messages Jun 13, 2001

lore
Share & tools
lore
#0 lore raw

Hi,

Here is the patch again for the benefit of those who are allergic to opening enclosures.
I believe it will only take about 30 seconds of "real thinking" for those familiar with dev.c to make
an evaluation of the patch.

Those already familiar with the bug can skip this paragraph, The bug fixes a problem that occurs if register_netdev gets called before net_dev_init the dev->refcnt gets incremented to 2 after net_dev_init is called
& unregister_netdev will loop forever.

The following additional lines at the top of register_netdev will call net_dev_init
if it hasn't already been called & by doing this I'm able to remove about 20 lines of special
case code in this function.
+ if (dev_boot_phase)
+ net_dev_init();

The following additional lines in net_dev_init will do a quick exit if this routine
as already been called ( as may be done from register_netdev ).
+ if(!dev_boot_phase)
+ return 0;

core/dev.c Tue Jun 12 15:37:58 2001 renamed from core/dev.old.c Wed May 30 14:24:47 2001 +1 -0
@@ -20,6 +20,10 @@
  *              Pekka Riikonen <[email protected]>
  *
  *  Changes:
+ *              D.J. Barrow     :       Fixed bug where dev->refcnt gets

set to 2
+ * if register_netdev gets called
before
+ * net_dev_init & also removed a few
lines
+ * of code in the process.

  *       Alan Cox  :    device private ioctl copies fields back.
  *       Alan Cox  :    Transmit queue code does relevant stunts to
  *                      keep the queue safe.

@@ -2382,6 +2386,7 @@
* will not get the same name.
*/

+int net_dev_init(void);
int register_netdevice(struct net_device *dev)

 {
     struct net_device *d, **dp;
@@ -2396,48 +2401,8 @@
     dev->fastpath_lock=RW_LOCK_UNLOCKED;

#endif

- if (dev_boot_phase) {
-#ifdef CONFIG_NET_DIVERT
- ret = alloc_divert_blk(dev);
- if (ret)
- return ret;
-#endif /* CONFIG_NET_DIVERT */
-
- /* This is NOT bug, but I am not sure, that all the
- devices, initialized before netdev module is started
- are sane.
-

-            Now they are chained to device boot list
-            and probed later. If a module is initialized
-            before netdev, but assumes that dev->init
-            is really called by register_netdev(), it will fail.

-
- So that this message should be printed for a while.
- */
- printk(KERN_INFO "early initialization of device %s is
deferred\n", dev->name);
-
- /* Check for existence, and append to tail of chain */
- for (dp=&dev_base; (d=*dp) != NULL; dp=&d->next) {
- if (d == dev || strcmp(d->name, dev->name) == 0) {
- return -EEXIST;
- }

-         }
-         dev->next = NULL;
-         write_lock_bh(&dev_base_lock);
-         *dp = dev;
-         dev_hold(dev);
-         write_unlock_bh(&dev_base_lock);
-
-         /*
-          *   Default initial state at registry is that the
-          *   device is present.
-          */

-
- set_bit(__LINK_STATE_PRESENT, &dev->state);
-
- return 0;
- }
-
+ if (dev_boot_phase)
+ net_dev_init();

 #ifdef CONFIG_NET_DIVERT
     ret = alloc_divert_blk(dev);
     if (ret)
@@ -2679,7 +2644,9 @@
 {
     struct net_device *dev, **dp;
     int i;

-
+
+ if(!dev_boot_phase)
+ return 0;

 #ifdef CONFIG_NET_SCHED
     pktsched_init();

#endif

D.J. Barrow Gnu/Linux for S/390 kernel developer
eMail: [email protected],[email protected]
Phone: +49-(0)7031-16-2583
IBM Germany Lab, Schönaicherstr. 220, 71032 Böblingen

#1 lore raw
Quoted 2 lines · [email protected] writes:

Here is the patch again for the benefit of those who are allergic to opening enclosures.

Yes, this one is for those who are not allergic to line-breaks messing up the patch, it seems :-)

The only reservation I had was wrt. procfs, but it dawned on me that we init procfs explicitly in init/main.c before initcalls are made.

So I've fixed up the line breaks and coding style issues, and applied your patch. Thanks.

Later,
David S. Miller
[email protected]