Skip to contentSkip to conversation

Module rewrite 3/20: init_module() changeover

PATCH New Rusty Russell 1 participant 1 message Sep 25, 2002

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Module rewrite 3/20: init_module() changeover

Name: init_module removal
Author: Rusty Russell
Status: Trivial

D: Modules in 2.4 can simply name functions init_module() and
D: cleanup_module(), and they will be called at module load and
D: unload. The preferred way is to use module_init(funcname) and
D: module_exit(funcname), and this is the only way once the
D: in-kernel-module loader is included.
D:
D: This is not all of them, just some examples (the ones I needed to
D: successfully compile).

drivers/net/ethertap.c +6 -2
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.35/drivers/net/ethertap.c working-2.5.35-modbase-try-i386/drivers/net/ethertap.c
@@ -346,7 +346,7 @@ static struct net_device dev_ethertap =
 	0, 0, 0, NULL, ethertap_probe
 };
 
-int init_module(void)
+static int init(void)
 {
 	dev_ethertap.base_addr=unit+NETLINK_TAPBASE;
 	sprintf(dev_ethertap.name,"tap%d",unit);
@@ -360,7 +360,7 @@ int init_module(void)
 	return 0;
 }
 
-void cleanup_module(void)
+static void cleanup(void)
 {
 	tap_map[dev_ethertap.base_addr]=NULL;
 	unregister_netdev(&dev_ethertap);
@@ -372,6 +372,10 @@ void cleanup_module(void)
 	kfree(dev_ethertap.priv);
 	dev_ethertap.priv = NULL;	/* gets re-allocated by ethertap_probe */
 }
+
+/* FIXME: Remove Space.c hardcoded crap --RR */
+module_init(init);
+module_exit(cleanup);
 
 #endif /* MODULE */
 MODULE_LICENSE("GPL");
drivers/net/slhc.c +5 -2
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.35/drivers/net/slhc.c working-2.5.35-modbase-try-i386/drivers/net/slhc.c
@@ -735,17 +735,20 @@ EXPORT_SYMBOL(slhc_toss);
 
 #ifdef MODULE
 
-int init_module(void)
+static int init(void)
 {
 	printk(KERN_INFO "CSLIP: code copyright 1989 Regents of the University of California\n");
 	return 0;
 }
 
-void cleanup_module(void)
+static void fini(void)
 {
 	return;
 }
 
+/* FIXME: Remove hard-coded initializers for builtin case */
+module_init(init);
+module_exit(fini);
 #endif /* MODULE */
 #else /* CONFIG_INET */
 
drivers/parport/init.c +5 -2
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.35/drivers/parport/init.c working-2.5.35-modbase-try-i386/drivers/parport/init.c
@@ -120,7 +120,7 @@ __setup ("parport=", parport_setup);
 #endif
 
 #ifdef MODULE
-int init_module(void)
+static int init(void)
 {
 #ifdef CONFIG_SYSCTL
 	parport_default_proc_register ();
@@ -128,12 +128,15 @@ int init_module(void)
 	return 0;
 }
 
-void cleanup_module(void)
+static void fini(void)
 {
 #ifdef CONFIG_SYSCTL
 	parport_default_proc_unregister ();
 #endif
 }
+
+module_init(init);
+module_exit(fini);
 
 #else
 
drivers/parport/parport_pc.c +6 -2
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.35/drivers/parport/parport_pc.c working-2.5.35-modbase-try-i386/drivers/parport/parport_pc.c
@@ -3069,7 +3069,7 @@ MODULE_PARM_DESC(verbose_probing, "Log c
 MODULE_PARM(verbose_probing, "i");
 #endif
 
-int init_module(void)
+static int init(void)
 {	
 	/* Work out how many ports we have, then get parport_share to parse
 	   the irq values. */
@@ -3118,7 +3118,7 @@ int init_module(void)
 	return ret;
 }
 
-void cleanup_module(void)
+static void fini(void)
 {
 	/* We ought to keep track of which ports are actually ours. */
 	struct parport *p = parport_enumerate(), *tmp;
@@ -3134,4 +3134,8 @@ void cleanup_module(void)
 		p = tmp;
 	}
 }
+
+/* FIXME: Merge builtin and modular initializers --RR */
+module_init(init);
+module_exit(fini);
 #endif
net/netlink/netlink_dev.c +6 -2
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.35/net/netlink/netlink_dev.c working-2.5.35-modbase-try-i386/net/netlink/netlink_dev.c
@@ -208,16 +208,20 @@ int __init init_netlink(void)
 
 MODULE_LICENSE("GPL");
 
-int init_module(void)
+static int init(void)
 {
 	printk(KERN_INFO "Network Kernel/User communications module 0.04\n");
 	return init_netlink();
 }
 
-void cleanup_module(void)
+static void fini(void)
 {
 	devfs_unregister (devfs_handle);
 	unregister_chrdev(NETLINK_MAJOR, "netlink");
 }
+
+/* FIXME: Remove harded init call in socket.c */
+module_init(init);
+module_exit(fini);
 
 #endif
drivers/char/ftape/zftape/zftape-init.c +8 -0
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .18828-linux-2.5.35/drivers/char/ftape/zftape/zftape-init.c .18828-linux-2.5.35.updated/drivers/char/ftape/zftape/zftape-init.c
@@ -393,20 +393,26 @@ KERN_INFO
 
 
 #ifdef MODULE
+
+#if 0 /* FIXME --RR */
 /* Called by modules package before trying to unload the module
  */
 static int can_unload(void)
 {
 	return (GET_USE_COUNT(THIS_MODULE)||zft_dirty()||test_bit(0,&busy_flag))?-EBUSY:0;
 }
+#endif
+
 /* Called by modules package when installing the driver
  */
 int init_module(void)
 {
+#if 0 /*FIXME --RR*/
 	if (!mod_member_present(&__this_module, can_unload)) {
 		return -EBUSY;
 	}
 	__this_module.can_unload = can_unload;
+#endif
 	return zft_init();
 }
 
@@ -444,3 +450,5 @@ void cleanup_module(void)
 }
 
 #endif /* MODULE */
+
+module_init(init_module);

--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.