As an alternative to sprinkling MOD_DEC_USE_COUNT throughout the failure paths of each net driver init sequence, maybe we should get the module use counters out of the drivers entirely. The driver source(s) look cleaner and the driver author(s) need not worry about the handling of the count. I've included one possible way of doing it below, including wd.c as an example showing the minimal driver change required. If people agree that this is the way to go then we can unleash sed on the other drivers. An added plus of this patch is that it is backward compatible with existing or 3rd party drivers that continue to handle the module count themselves. Paul. --- include/linux/netdevice.h~ Mon Sep 11 03:55:45 2000 +++ include/linux/netdevice.h Tue Oct 17 10:30:10 2000 @@ -25,6 +25,8 @@ #ifndef _LINUX_NETDEVICE_H #define _LINUX_NETDEVICE_H +#include <linux/module.h> + #include <linux/if.h> #include <linux/if_ether.h> #include <linux/if_packet.h> @@ -282,6 +284,8 @@ struct net_device *master; /* Pointer to master device of a group, * which this device is member of. */ + + struct module *module; /* Module associated with this dev */ /* Interface address info. */ unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */ --- drivers/net/wd.c~ Wed Jun 28 11:38:32 2000 +++ drivers/net/wd.c Tue Oct 17 10:59:49 2000 @@ -323,7 +323,6 @@ outb(ei_status.reg0, ioaddr); /* WD_CMDREG */ ei_open(dev); - MOD_INC_USE_COUNT; return 0; } @@ -430,8 +429,6 @@ /* And disable the shared memory. */ outb(ei_status.reg0 & ~WD_MEMENB, wd_cmdreg); - MOD_DEC_USE_COUNT; - return 0; } @@ -469,6 +466,7 @@ for (this_dev = 0; this_dev < MAX_WD_CARDS; this_dev++) { struct net_device *dev = &dev_wd[this_dev]; + dev->module = THIS_MODULE; dev->irq = irq[this_dev]; dev->base_addr = io[this_dev]; dev->mem_start = mem[this_dev]; --- net/core/dev.c~ Wed Oct 4 00:30:55 2000 +++ net/core/dev.c Wed Oct 18 00:02:24 2000 @@ -59,6 +59,7 @@ * Paul Rusty Russell : SIOCSIFNAME * Pekka Riikonen : Netdev boot-time settings code * Andrew Morton : Make unregister_netdevice wait indefinitely on dev->refcnt + * Paul Gortmaker : Put module use counts here instead of in each driver. */ #include <asm/uaccess.h> @@ -644,6 +645,14 @@ return -ENODEV; /* + * Make sure module is marked in + * use in case dev->open sleeps. + */ + + if (dev->module) + __MOD_INC_USE_COUNT(dev->module); + + /* * Call device private open method */ @@ -677,6 +686,9 @@ * ... and announce new interface. */ notifier_call_chain(&netdev_chain, NETDEV_UP, dev); + } else { /* ret!=0, dev->open caught fire... */ + if (dev->module) + __MOD_DEC_USE_COUNT(dev->module); } return(ret); } @@ -763,6 +775,9 @@ * Tell people we are down */ notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev); + + if (dev->module) + __MOD_DEC_USE_COUNT(dev->module); return(0); } _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com - : send the line "unsubscribe linux-net" in the body of a message to majordomo@vger.kernel.org