All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] block: avoid module usage in non-modular code
@ 2015-12-13 20:04 Paul Gortmaker
  2015-12-13 20:04 ` [PATCH 1/3] block: make genhd.c slightly more explicitly non-modular Paul Gortmaker
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Paul Gortmaker @ 2015-12-13 20:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: Paul Gortmaker, Jens Axboe, Vivek Goyal

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 <axboe@kernel.dk>
Cc: Vivek Goyal <vgoyal@redhat.com>

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(-)

-- 
2.6.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] block: make genhd.c slightly more explicitly non-modular
  2015-12-13 20:04 [PATCH 0/3] block: avoid module usage in non-modular code Paul Gortmaker
@ 2015-12-13 20:04 ` Paul Gortmaker
  2015-12-13 20:04 ` [PATCH 2/3] block: make blk-throttle.c " Paul Gortmaker
  2015-12-13 20:04 ` [PATCH 3/3] block: make noop-iosched.c " Paul Gortmaker
  2 siblings, 0 replies; 5+ messages in thread
From: Paul Gortmaker @ 2015-12-13 20:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: Paul Gortmaker, Jens Axboe

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.

Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 block/genhd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/genhd.c b/block/genhd.c
index cd78712bab8e..333cd557c3a4 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -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)
-- 
2.6.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] block: make blk-throttle.c explicitly non-modular
  2015-12-13 20:04 [PATCH 0/3] block: avoid module usage in non-modular code Paul Gortmaker
  2015-12-13 20:04 ` [PATCH 1/3] block: make genhd.c slightly more explicitly non-modular Paul Gortmaker
@ 2015-12-13 20:04 ` Paul Gortmaker
  2015-12-15 13:30   ` Vivek Goyal
  2015-12-13 20:04 ` [PATCH 3/3] block: make noop-iosched.c " Paul Gortmaker
  2 siblings, 1 reply; 5+ messages in thread
From: Paul Gortmaker @ 2015-12-13 20:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: Paul Gortmaker, Vivek Goyal, Jens Axboe

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.

Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 block/blk-throttle.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 2149a1ddbacf..bec1dedf4061 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -4,7 +4,7 @@
  * Copyright (C) 2010 Vivek Goyal <vgoyal@redhat.com>
  */
 
-#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);
-- 
2.6.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] block: make noop-iosched.c explicitly non-modular
  2015-12-13 20:04 [PATCH 0/3] block: avoid module usage in non-modular code Paul Gortmaker
  2015-12-13 20:04 ` [PATCH 1/3] block: make genhd.c slightly more explicitly non-modular Paul Gortmaker
  2015-12-13 20:04 ` [PATCH 2/3] block: make blk-throttle.c " Paul Gortmaker
@ 2015-12-13 20:04 ` Paul Gortmaker
  2 siblings, 0 replies; 5+ messages in thread
From: Paul Gortmaker @ 2015-12-13 20:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: Paul Gortmaker, Jens Axboe

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.

Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 block/noop-iosched.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/block/noop-iosched.c b/block/noop-iosched.c
index a163c487cf38..09f089ee7668 100644
--- a/block/noop-iosched.c
+++ b/block/noop-iosched.c
@@ -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);
-- 
2.6.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] block: make blk-throttle.c explicitly non-modular
  2015-12-13 20:04 ` [PATCH 2/3] block: make blk-throttle.c " Paul Gortmaker
@ 2015-12-15 13:30   ` Vivek Goyal
  0 siblings, 0 replies; 5+ messages in thread
From: Vivek Goyal @ 2015-12-15 13:30 UTC (permalink / raw)
  To: Paul Gortmaker; +Cc: linux-kernel, Jens Axboe, Tejun Heo

Paul,

This looks reasonable to me. Ccing Tejun.

Thanks
Vivek

On Sun, Dec 13, 2015 at 03:04:03PM -0500, Paul Gortmaker wrote:
> 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.
> 
> Cc: Vivek Goyal <vgoyal@redhat.com>
> Cc: Jens Axboe <axboe@kernel.dk>
> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
> ---
>  block/blk-throttle.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/block/blk-throttle.c b/block/blk-throttle.c
> index 2149a1ddbacf..bec1dedf4061 100644
> --- a/block/blk-throttle.c
> +++ b/block/blk-throttle.c
> @@ -4,7 +4,7 @@
>   * Copyright (C) 2010 Vivek Goyal <vgoyal@redhat.com>
>   */
>  
> -#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);
> -- 
> 2.6.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-12-15 13:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-13 20:04 [PATCH 0/3] block: avoid module usage in non-modular code Paul Gortmaker
2015-12-13 20:04 ` [PATCH 1/3] block: make genhd.c slightly more explicitly non-modular Paul Gortmaker
2015-12-13 20:04 ` [PATCH 2/3] block: make blk-throttle.c " Paul Gortmaker
2015-12-15 13:30   ` Vivek Goyal
2015-12-13 20:04 ` [PATCH 3/3] block: make noop-iosched.c " Paul Gortmaker

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.