Skip to contentSkip to conversation

block: avoid module usage in non-modular code

PATCH In review Paul Gortmaker 2 participants 5 messages Dec 13, 2015 – Dec 15, 2015

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

cover block: avoid module usage in non-modular code

This series of commits is a part of a larger project to ensure people don't reference modular support functions in non-modular code. Overall there was roughly 5k lines of dead code in the kernel due to this. So far we've fixed several areas, like tty, x86, net, ... and we continue to work on other areas.

There are several reasons to not use module support for code that can never be built as a module, but the big ones are:

(1) it is easy to accidentally code up unused module_exit and remove code
(2) it can be misleading when reading the source, thinking it can be modular when the Makefile and/or Kconfig prohibit it
(3) it requires the include of the module.h header file which in turn includes nearly everything else.

The block layer is an easy one as far as this cleanup goes. Only three files touched, and two of the three don't even change the compiled objects -- only the noop-iosched had an unused exit function removed.

Cc Jens Axboe <[email protected]>
Cc Vivek Goyal <[email protected]>

Paul Gortmaker (3):
block: make genhd.c slightly more explicitly non-modular
block: make blk-throttle.c explicitly non-modular
block: make noop-iosched.c explicitly non-modular

 block/blk-throttle.c |  5 ++---
 block/genhd.c        |  2 +-
 block/noop-iosched.c | 19 ++++---------------
 3 files changed, 7 insertions(+), 19 deletions(-)
Signature · 1 line
2.6.1
#1 lore raw

PATCH 1/3 block: make genhd.c slightly more explicitly non-modular

The Makefile currently controlling compilation of this code is:

obj-$(CONFIG_BLOCK) := bio.o elevator.o blk-core.o blk-tag.o blk-sysfs.o \
                        [...]
                        genhd.o scsi_ioctl.o partition-generic.o ioprio.o \

...and the Kconfig is:

menuconfig BLOCK
bool "Enable the block layer" if EXPERT
default y

...meaning that it currently is not being built as a module by anyone.

While the code uses moduleparam and other modular infrastructure that prevents removal of module.h itself, we can at least ensure the way it is loaded sends a clear message that it is built-in or absent.

Since module_init translates to device_initcall in the non-modular case, the init ordering remains unchanged with this commit. We do that because the file already has subsys_initcall() usage within, and I don't want to risk breaking ordering within the file itself.

---
 block/genhd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/genhd.c +1 -1
index cd78712bab8e..333cd557c3a4 100644
@@ -1214,7 +1214,7 @@ static int __init proc_genhd_init(void)
 	proc_create("partitions", 0, NULL, &proc_partitions_operations);
 	return 0;
 }
-module_init(proc_genhd_init);
+device_initcall(proc_genhd_init);
 #endif /* CONFIG_PROC_FS */
 
 dev_t blk_lookup_devt(const char *name, int partno)
Signature · 1 line
2.6.1
#2 lore raw

PATCH 2/3 block: make blk-throttle.c explicitly non-modular

In reply to Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

config BLK_DEV_THROTTLING
bool "Block layer bio throttling support"

...meaning that it currently is not being built as a module by anyone.

Lets remove the couple traces of modularity so that when reading the code there is no doubt it is builtin-only.

Since module_init translates to device_initcall in the non-modular case, the init ordering remains unchanged with this commit.

---
 block/blk-throttle.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
block/blk-throttle.c +2 -3
index 2149a1ddbacf..bec1dedf4061 100644
@@ -4,7 +4,7 @@
  * Copyright (C) 2010 Vivek Goyal <[email protected]>
  */
 
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/blkdev.h>
 #include <linux/bio.h>
@@ -1590,5 +1590,4 @@ static int __init throtl_init(void)
 
 	return blkcg_policy_register(&blkcg_policy_throtl);
 }
-
-module_init(throtl_init);
+device_initcall(throtl_init);
Signature · 1 line
2.6.1
#3 lore raw

Re: [PATCH 2/3] block: make blk-throttle.c explicitly non-modular

Paul,

This looks reasonable to me. Ccing Tejun.

Thanks
Vivek

Quoted 42 lines · Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

config BLK_DEV_THROTTLING
bool "Block layer bio throttling support"

...meaning that it currently is not being built as a module by anyone.

Lets remove the couple traces of modularity so that when reading the code there is no doubt it is builtin-only.

Since module_init translates to device_initcall in the non-modular case, the init ordering remains unchanged with this commit.

---
 block/blk-throttle.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
block/blk-throttle.c +2 -3
index 2149a1ddbacf..bec1dedf4061 100644
@@ -4,7 +4,7 @@
  * Copyright (C) 2010 Vivek Goyal <[email protected]>
  */
 
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/blkdev.h>
 #include <linux/bio.h>
@@ -1590,5 +1590,4 @@ static int __init throtl_init(void)
 
 	return blkcg_policy_register(&blkcg_policy_throtl);
 }
-
-module_init(throtl_init);
+device_initcall(throtl_init);
Signature · 1 line
2.6.1
#4 lore raw

PATCH 3/3 block: make noop-iosched.c explicitly non-modular

In reply to Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

config IOSCHED_NOOP
bool
default y

...meaning that it currently is not being built as a module by anyone.

Lets remove the modular code that is essentially orphaned, so that when reading the driver there is no doubt it is builtin-only.

Since module_init translates to device_initcall in the non-modular case, the init ordering remains unchanged with this commit.

We also delete the MODULE_LICENSE tag etc. since all that information is now contained at the top of the file in the comments.

---
 block/noop-iosched.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)
block/noop-iosched.c +4 -15
index a163c487cf38..09f089ee7668 100644
@@ -1,10 +1,11 @@
 /*
- * elevator noop
+ * elevator noop: No-op IO scheduler
+ * Author: Jens Axboe
+ * License: GPL
  */
 #include <linux/blkdev.h>
 #include <linux/elevator.h>
 #include <linux/bio.h>
-#include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/init.h>
 
@@ -109,16 +110,4 @@ static int __init noop_init(void)
 {
 	return elv_register(&elevator_noop);
 }
-
-static void __exit noop_exit(void)
-{
-	elv_unregister(&elevator_noop);
-}
-
-module_init(noop_init);
-module_exit(noop_exit);
-
-
-MODULE_AUTHOR("Jens Axboe");
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("No-op IO scheduler");
+device_initcall(noop_init);
Signature · 1 line
2.6.1