Skip to contentSkip to conversation

soc: avoid module usage in non-modular code

PATCH Applied Paul Gortmaker 4 participants 7 messages Nov 13, 2016 – Apr 4, 2017

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

cover soc: 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, gpio ... 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.

Two of the changes are essentially source only -- the resuting module will be binary equivalent. Only the FSL driver has unused code in addition to the use of modular macros that get converted.

Note the FSL SOC driver just appeared in linux-next and so this series won't apply on Linus' master branch. These commits were applied to linux-next and build tested there.

Paul.
---

Cc Alexandre Courbot <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Scott Wood <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Yangbo Lu <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc linuxppc-dev at lists.ozlabs.org
Cc linux-tegra at vger.kernel.org

Paul Gortmaker (3):
soc: sunxi: make sunxi_sram explicitly non-modular
soc: tegra: make fuse-tegra explicitly non-modular
soc: fsl: make guts driver explicitly non-modular

 drivers/soc/fsl/guts.c              | 17 ++---------------
 drivers/soc/sunxi/sunxi_sram.c      |  9 ++-------
 drivers/soc/tegra/fuse/fuse-tegra.c |  4 ++--
 3 files changed, 6 insertions(+), 24 deletions(-)
Signature · 1 line
2.10.1
#1 lore raw

PATCH 1/3 soc: sunxi: make sunxi_sram explicitly non-modular

The Kconfig currently controlling compilation of this code is:

drivers/soc/sunxi/Kconfig:config SUNXI_SRAM
drivers/soc/sunxi/Kconfig: bool

...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_platform_driver() uses the same init level priority as builtin_platform_driver() the init ordering remains unchanged with this commit.

Also note that MODULE_DEVICE_TABLE is a no-op for non-modular code.

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

Cc Maxime Ripard <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/soc/sunxi/sunxi_sram.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/soc/sunxi/sunxi_sram.c +2 -7
index 99e354c8f53f..5e10408a2aef 100644
@@ -12,7 +12,7 @@
 
 #include <linux/debugfs.h>
 #include <linux/io.h>
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/of_device.h>
@@ -269,7 +269,6 @@ static const struct of_device_id sunxi_sram_dt_match[] = {
 	{ .compatible = "allwinner,sun4i-a10-sram-controller" },
 	{ },
 };
-MODULE_DEVICE_TABLE(of, sunxi_sram_dt_match);
 
 static struct platform_driver sunxi_sram_driver = {
 	.driver = {
@@ -278,8 +277,4 @@ static struct platform_driver sunxi_sram_driver = {
 	},
 	.probe	= sunxi_sram_probe,
 };
-module_platform_driver(sunxi_sram_driver);
-
-MODULE_AUTHOR("Maxime Ripard <[email protected]>");
-MODULE_DESCRIPTION("Allwinner sunXi SRAM Controller Driver");
-MODULE_LICENSE("GPL");
+builtin_platform_driver(sunxi_sram_driver);
Signature · 1 line
2.10.1
#3 lore raw

PATCH 2/3 soc: tegra: make fuse-tegra explicitly non-modular

In reply to Paul Gortmaker

The Makefiles currently controlling compilation of this code is:

drivers/soc/tegra/Makefile:obj-y += fuse/ drivers/soc/tegra/fuse/Makefile:obj-y += fuse-tegra.o

...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 driver there is no doubt it is builtin-only.

Since module_platform_driver() uses the same init level priority as builtin_platform_driver() the init ordering remains unchanged with this commit.

Cc Stephen Warren <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Alexandre Courbot <[email protected]>
---
 drivers/soc/tegra/fuse/fuse-tegra.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/tegra/fuse/fuse-tegra.c +2 -2
index de2c1bfe28b5..7413f60fa855 100644
@@ -18,7 +18,7 @@
 #include <linux/clk.h>
 #include <linux/device.h>
 #include <linux/kobject.h>
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
@@ -168,7 +168,7 @@ static struct platform_driver tegra_fuse_driver = {
 	},
 	.probe = tegra_fuse_probe,
 };
-module_platform_driver(tegra_fuse_driver);
+builtin_platform_driver(tegra_fuse_driver);
 
 bool __init tegra_fuse_read_spare(unsigned int spare)
 {
Signature · 1 line
2.10.1
#5 lore raw

PATCH 3/3 soc: fsl: make guts driver explicitly non-modular

In reply to Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

drivers/soc/fsl/Kconfig:config FSL_GUTS
drivers/soc/fsl/Kconfig: bool

...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.

We explicitly disallow a driver unbind, since that doesn't have a sensible use case anyway, and it allows us to drop the ".remove" code for non-modular drivers.

Since the code was already not using module_init, the init ordering remains unchanged with this commit.

Also note that MODULE_DEVICE_TABLE is a no-op for non-modular code.

Cc Scott Wood <[email protected]>
Cc Yangbo Lu <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc linuxppc-dev at lists.ozlabs.org
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/soc/fsl/guts.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/soc/fsl/guts.c +2 -15
index 0ac88263c2d7..b4d2fd9263b2 100644
@@ -11,7 +11,7 @@
 
 #include <linux/io.h>
 #include <linux/slab.h>
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/of_fdt.h>
 #include <linux/sys_soc.h>
 #include <linux/of_address.h>
@@ -180,12 +180,6 @@ static int fsl_guts_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int fsl_guts_remove(struct platform_device *dev)
-{
-	soc_device_unregister(soc_dev);
-	return 0;
-}
-
 /*
  * Table for matching compatible strings, for device tree
  * guts node, for Freescale QorIQ SOCs.
@@ -212,15 +206,14 @@ static const struct of_device_id fsl_guts_of_match[] = {
 	{ .compatible = "fsl,ls2080a-dcfg", },
 	{}
 };
-MODULE_DEVICE_TABLE(of, fsl_guts_of_match);
 
 static struct platform_driver fsl_guts_driver = {
 	.driver = {
 		.name = "fsl-guts",
+		.suppress_bind_attrs = true,
 		.of_match_table = fsl_guts_of_match,
 	},
 	.probe = fsl_guts_probe,
-	.remove = fsl_guts_remove,
 };
 
 static int __init fsl_guts_init(void)
@@ -228,9 +221,3 @@ static int __init fsl_guts_init(void)
 	return platform_driver_register(&fsl_guts_driver);
 }
 core_initcall(fsl_guts_init);
-
-static void __exit fsl_guts_exit(void)
-{
-	platform_driver_unregister(&fsl_guts_driver);
-}
-module_exit(fsl_guts_exit);
Signature · 1 line
2.10.1
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] soc: sunxi: make sunxi_sram explicitly non-modular

In reply to Paul Gortmaker
Quoted 14 lines · Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

drivers/soc/sunxi/Kconfig:config SUNXI_SRAM
drivers/soc/sunxi/Kconfig: bool

...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_platform_driver() uses the same init level priority as builtin_platform_driver() the init ordering remains unchanged with this commit.

Quoted 8 lines

Also note that MODULE_DEVICE_TABLE is a no-op for non-modular code.

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

Cc Maxime Ripard <[email protected]>
Cc linux-arm-kernel at lists.infradead.org

Thanks!
Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20161114/be8785c8/attachment.sig>
Acked-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] soc: fsl: make guts driver explicitly non-modular

In reply to Paul Gortmaker
Quoted 19 lines · Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

drivers/soc/fsl/Kconfig:config FSL_GUTS
drivers/soc/fsl/Kconfig:????????bool

...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.

We explicitly disallow a driver unbind, since that doesn't have a sensible use case anyway, and it allows us to drop the ".remove" code for non-modular drivers.

Since the code was already not using module_init, the init ordering remains unchanged with this commit.

Also note that MODULE_DEVICE_TABLE is a no-op for non-modular code.

Quoted 7 lines
Cc Scott Wood <[email protected]>
Cc Yangbo Lu <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc linuxppc-dev at lists.ozlabs.org
Cc linux-arm-kernel at lists.infradead.org

-Scott

#4 lore raw

Re: [PATCH 2/3] soc: tegra: make fuse-tegra explicitly non-modular

In reply to Paul Gortmaker
Quoted 14 lines · Paul Gortmaker

The Makefiles currently controlling compilation of this code is:

drivers/soc/tegra/Makefile:obj-y += fuse/ drivers/soc/tegra/fuse/Makefile:obj-y += fuse-tegra.o

...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 driver there is no doubt it is builtin-only.

Since module_platform_driver() uses the same init level priority as builtin_platform_driver() the init ordering remains unchanged with this commit.

Quoted 8 lines
Cc Stephen Warren <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Alexandre Courbot <[email protected]>
---
 drivers/soc/tegra/fuse/fuse-tegra.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to for-4.12/soc, thanks.

Thierry