Freeing network devices safely
rmmod e100 < /sys/class/net/eth0/statistics/tx_bytes
This command will keep the indicated sysfs file open past the time when the module containing the net_device structure behind that file is removed from the system. Unless special care is taken, the open file will be left pointing to structures which no longer exist, leading to all kinds of potential trouble. Most drivers do not take that care.
Until 2.6.0-test4, that is. After a series of patches by Stephen Hemminger, drivers are expected to use kmalloc() to create net_device structures dynamicly. Most drivers already worked that way; the difference now is that drivers can no longer just return those structures with kfree() when they are no longer needed. Instead, there is a new function which is used to get rid of a net_device structure:
void free_netdev (struct net_device *dev);
This function, of course, helps the networking system maintain reference
counts for net_device structures, and avoid freeing them until
they are truly unused. This whole structure is relatively simple, but it
demonstrates, again, the higher level of care required to avoid creating
race conditions in the 2.6 kernel.
