Skip to contentSkip to conversation

lib: make sg_pool explicitly non-modular

PATCH In review Paul Gortmaker 2 participants 4 messages Apr 20, 2016 – Apr 21, 2016 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: make sg_pool explicitly non-modular

The recently added Kconfig controlling compilation of this code is:

lib/Kconfig:config SG_POOL
lib/Kconfig: def_bool n

...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. However one might want to consider moving it to subsys_initcall if it is to be ready ahead of SCSI drivers wanting this and using device_initcall.

Cc Christoph Hellwig <[email protected]>
Cc Ming Lin <[email protected]>
Cc Sagi Grimberg <[email protected]>
Cc Martin K. Petersen <[email protected]>
---
 lib/sg_pool.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
lib/sg_pool.c +2 -15
index 6dd30615a201..e2cf548b9610 100644
@@ -1,4 +1,4 @@
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/scatterlist.h>
 #include <linux/mempool.h>
 #include <linux/slab.h>
@@ -156,17 +156,4 @@ cleanup_sdb:
 
 	return -ENOMEM;
 }
-
-static __exit void sg_pool_exit(void)
-{
-	int i;
-
-	for (i = 0; i < SG_MEMPOOL_NR; i++) {
-		struct sg_pool *sgp = sg_pools + i;
-		mempool_destroy(sgp->pool);
-		kmem_cache_destroy(sgp->slab);
-	}
-}
-
-module_init(sg_pool_init);
-module_exit(sg_pool_exit);
+device_initcall(sg_pool_init);
Signature · 1 line
2.8.0
#1 lore raw
Quoted 43 lines · Paul Gortmaker

The recently added Kconfig controlling compilation of this code is:

lib/Kconfig:config SG_POOL
lib/Kconfig: def_bool n

...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. However one might want to consider moving it to subsys_initcall if it is to be ready ahead of SCSI drivers wanting this and using device_initcall.

Cc Christoph Hellwig <[email protected]>
Cc Ming Lin <[email protected]>
Cc Sagi Grimberg <[email protected]>
Cc Martin K. Petersen <[email protected]>
---
 lib/sg_pool.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
lib/sg_pool.c +1 -6
index 6dd30615a201..e2cf548b9610 100644
@@ -1,4 +1,4 @@
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/scatterlist.h>
 #include <linux/mempool.h>
 #include <linux/slab.h>
@@ -156,17 +156,4 @@ cleanup_sdb:
 
 	return -ENOMEM;
 }
-
-static __exit void sg_pool_exit(void)
-{
-	int i;
-

lib/sg_pool.c cleanup_sdb: · line 159

Quoted 10 lines
lib/sg_pool.c +1 -9
-	for (i = 0; i < SG_MEMPOOL_NR; i++) {
-		struct sg_pool *sgp = sg_pools + i;
-		mempool_destroy(sgp->pool);
-		kmem_cache_destroy(sgp->slab);
-	}
-}
-
-module_init(sg_pool_init);
-module_exit(sg_pool_exit);
+device_initcall(sg_pool_init);

For SCSI it's OK because always CONFIG_SCSI=y

But we may have a kernel .config with !CONFIG_SCSI and other non-block-device driver may use this sg_pool.

So the .config will have CONFIG_SG_POOL=m

#2 lore raw
Quoted 57 lines · [Re: [PATCH] lib: make sg_pool explicitly non-modular] On 20/04/2016 (Wed…
Quoted 43 lines · Paul Gortmaker

The recently added Kconfig controlling compilation of this code is:

lib/Kconfig:config SG_POOL
lib/Kconfig: def_bool n

...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. However one might want to consider moving it to subsys_initcall if it is to be ready ahead of SCSI drivers wanting this and using device_initcall.

Cc Christoph Hellwig <[email protected]>
Cc Ming Lin <[email protected]>
Cc Sagi Grimberg <[email protected]>
Cc Martin K. Petersen <[email protected]>
---
 lib/sg_pool.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
lib/sg_pool.c +1 -6
index 6dd30615a201..e2cf548b9610 100644
@@ -1,4 +1,4 @@
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/scatterlist.h>
 #include <linux/mempool.h>
 #include <linux/slab.h>
@@ -156,17 +156,4 @@ cleanup_sdb:
 
 	return -ENOMEM;
 }
-
-static __exit void sg_pool_exit(void)
-{
-	int i;
-

lib/sg_pool.c cleanup_sdb: · line 159

Quoted 10 lines
lib/sg_pool.c +1 -9
-	for (i = 0; i < SG_MEMPOOL_NR; i++) {
-		struct sg_pool *sgp = sg_pools + i;
-		mempool_destroy(sgp->pool);
-		kmem_cache_destroy(sgp->slab);
-	}
-}
-
-module_init(sg_pool_init);
-module_exit(sg_pool_exit);
+device_initcall(sg_pool_init);

For SCSI it's OK because always CONFIG_SCSI=y

Quoted 4 lines

But we may have a kernel .config with !CONFIG_SCSI and other non-block-device driver may use this sg_pool.

So the .config will have CONFIG_SG_POOL=m

That is impossible currently, since as per above, the variable is bool and not tristate. Did you mean to make it tristate?

Paul.
--

Quoted 4 lines
#3 lore raw
Quoted 7 lines · Paul Gortmaker

Quoted 2 lines

So the .config will have CONFIG_SG_POOL=m

That is impossible currently, since as per above, the variable is bool
and not tristate.  Did you mean to make it tristate?

I didn't notice that.

Yes, it should be tristate.