patch-2.4.0-test12 linux/drivers/net/shaper.c
Next file: linux/drivers/net/sis900.c
Previous file: linux/drivers/net/setup.c
Back to the patch index
Back to the overall index
- Lines: 198
- Date:
Sun Dec 3 17:45:22 2000
- Orig file:
v2.4.0-test11/linux/drivers/net/shaper.c
- Orig date:
Thu Jun 29 10:09:01 2000
diff -u --recursive --new-file v2.4.0-test11/linux/drivers/net/shaper.c linux/drivers/net/shaper.c
@@ -406,7 +406,6 @@
return -ENODEV;
if(shaper->bitspersec==0)
return -EINVAL;
- MOD_INC_USE_COUNT;
return 0;
}
@@ -419,7 +418,6 @@
struct shaper *shaper=dev->priv;
shaper_flush(shaper);
del_timer_sync(&shaper->timer);
- MOD_DEC_USE_COUNT;
return 0;
}
@@ -618,34 +616,31 @@
}
}
-static struct shaper *shaper_alloc(struct net_device *dev)
+static void shaper_init_priv(struct net_device *dev)
{
- struct shaper *sh=kmalloc(sizeof(struct shaper), GFP_KERNEL);
- if(sh==NULL)
- return NULL;
- memset(sh,0,sizeof(*sh));
+ struct shaper *sh = dev->priv;
+
skb_queue_head_init(&sh->sendq);
init_timer(&sh->timer);
sh->timer.function=shaper_timer;
sh->timer.data=(unsigned long)sh;
init_waitqueue_head(&sh->wait_queue);
- return sh;
}
/*
* Add a shaper device to the system
*/
-int __init shaper_probe(struct net_device *dev)
+static int __init shaper_probe(struct net_device *dev)
{
/*
* Set up the shaper.
*/
-
- dev->priv = shaper_alloc(dev);
- if(dev->priv==NULL)
- return -ENOMEM;
-
+
+ SET_MODULE_OWNER(dev);
+
+ shaper_init_priv(dev);
+
dev->open = shaper_open;
dev->stop = shaper_close;
dev->hard_start_xmit = shaper_start_xmit;
@@ -685,89 +680,68 @@
return 0;
}
+static int shapers = 1;
#ifdef MODULE
-static struct net_device dev_shape =
-{
- "",
- 0, 0, 0, 0,
- 0, 0,
- 0, 0, 0, NULL, shaper_probe
-};
-
-int init_module(void)
-{
- int err=dev_alloc_name(&dev_shape,"shaper%d");
- if(err<0)
- return err;
- printk(SHAPER_BANNER);
- if (register_netdev(&dev_shape) != 0)
- return -EIO;
- printk("Traffic shaper initialised.\n");
- return 0;
-}
+MODULE_PARM(shapers, "i");
-void cleanup_module(void)
-{
- struct shaper *sh=dev_shape.priv;
-
- /*
- * No need to check MOD_IN_USE, as sys_delete_module() checks.
- * To be unloadable we must be closed and detached so we don't
- * need to flush things.
- */
-
- unregister_netdev(&dev_shape);
+#else /* MODULE */
- /*
- * Free up the private structure, or leak memory :-)
- */
- kfree(sh);
- dev_shape.priv = NULL;
+static int __init set_num_shapers(char *str)
+{
+ shapers = simple_strtol(str, NULL, 0);
+ return 1;
}
-#else
+__setup("shapers=", set_num_shapers);
-static struct net_device dev_sh0 =
-{
- "shaper0",
- 0, 0, 0, 0,
- 0, 0,
- 0, 0, 0, NULL, shaper_probe
-};
+#endif /* MODULE */
+static struct net_device *devs;
-static struct net_device dev_sh1 =
+static int __init shaper_init(void)
{
- "shaper1",
- 0, 0, 0, 0,
- 0, 0,
- 0, 0, 0, NULL, shaper_probe
-};
+ int i, err;
+ size_t alloc_size;
+ struct shaper *sp;
+ unsigned int shapers_registered = 0;
+
+ if (shapers < 1)
+ return -ENODEV;
+
+ alloc_size = (sizeof(*devs) * shapers) +
+ (sizeof(struct shaper) * shapers);
+ devs = kmalloc(alloc_size, GFP_KERNEL);
+ if (!devs)
+ return -ENOMEM;
+ memset(devs, 0, alloc_size);
+ sp = (struct shaper *) &devs[shapers];
+ for (i = 0; i < shapers; i++) {
+ err = dev_alloc_name(&devs[i], "shaper%d");
+ if (err < 0)
+ break;
+ devs[i].init = shaper_probe;
+ devs[i].priv = &sp[i];
+ if (register_netdev(&devs[i]))
+ break;
+ shapers_registered++;
+ }
-static struct net_device dev_sh2 =
-{
- "shaper2",
- 0, 0, 0, 0,
- 0, 0,
- 0, 0, 0, NULL, shaper_probe
-};
+ if (!shapers_registered) {
+ kfree(devs);
+ devs = NULL;
+ }
-static struct net_device dev_sh3 =
-{
- "shaper3",
- 0, 0, 0, 0,
- 0, 0,
- 0, 0, 0, NULL, shaper_probe
-};
+ return (shapers_registered ? 0 : -ENODEV);
+}
-void shaper_init(void)
+static void __exit shaper_exit (void)
{
- register_netdev(&dev_sh0);
- register_netdev(&dev_sh1);
- register_netdev(&dev_sh2);
- register_netdev(&dev_sh3);
+ kfree(devs);
+ devs = NULL;
}
-#endif /* MODULE */
+module_init(shaper_init);
+module_exit(shaper_exit);
+
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)