Skip to contentSkip to conversation

bus: remove unused modular code from non-modular drivers

PATCH Applied Paul Gortmaker 4 participants 10 messages Jul 3, 2016 – Jul 14, 2016

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

v2 cover bus: remove unused modular code from non-modular drivers

The drivers/bus doesn't have a strict maintainer entry, but since all the changes here are for ARM platforms, I'm Cc'ing arm-kernel and hoping it makes sense to vector these few changes through the arm-soc tree.

My ongoing audit looking for non-modular code that needlessly uses modular macros (vs. built-in equivalents) and/or has dead code relating to module unloading that can never be executed led to the creation of these four commits.

Two are of the trivial kind, where we substitute in the non-modular versions that CPP would have put in place anyway, resulting in no actual changes, even at the binary output level.

Another is of the kind where there was a ".remove" function registered into the driver struct. Being non-modular, these functions will never be called via a normal module_exit path.

However, since it was possible (but largely pointless, and without a real use case) to unbind these drivers via sysfs, we explicitly disallow the unbind as part of the removal of the ".remove" itself.

Finally one is a conversion of a bool to a tristate; not something I'd do myself by default, but in this case we had a desire from the original author to have it that way.

For anyone new to the underlying goal of this cleanup, we are trying to not use module support for code that can never be built as a module since:

(1) it is easy to accidentally write 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, thus adding to CPP overhead.
(4) it gets copied/replicated into other code and spreads like weeds.

Build tested for arm and arm64 on linux-next to ensure no silly typos that would break compilation crept in.

---

[v2: drop arm-ccn patch; it is being made tristate elsewhere, convert
simple-pm to tristate, add new patch for new tegra-aconnect driver.]

[v1: https://lkml.kernel.org/r/1459113058-14340-1-git-send-email-paul.gortmaker at windriver.com ]

Cc Alexandre Courbot <[email protected]>
Cc Alison Chaiken <[email protected]>
Cc Brian Norris <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Gregory Fong <[email protected]>
Cc Jon Hunter <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Simon Horman <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc linux-tegra at vger.kernel.org

Paul Gortmaker (4):
bus: brcmstb_gisb: make it explicitly non-modular
bus: imx-weim: make it explicitly non-modular
bus: tegra-aconnect: make it explicitly non-modular
bus: simple-pm-bus: convert bool SIMPLE_PM_BUS to tristate

 drivers/bus/Kconfig          |  2 +-
 drivers/bus/brcmstb_gisb.c   |  4 +---
 drivers/bus/imx-weim.c       |  9 ++-------
 drivers/bus/tegra-aconnect.c | 22 +++++-----------------
 4 files changed, 9 insertions(+), 28 deletions(-)
Signature · 1 line
2.8.4
#1 lore raw

PATCH v2 1/4 bus: brcmstb_gisb: make it explicitly non-modular

The Kconfig for this driver is currently:

config BRCMSTB_GISB_ARB
bool "Broadcom STB GISB bus arbiter"

...meaning that it currently is not being built as a module by anyone. Lets remove all modular references, 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.

Cc Brian Norris <[email protected]>
Cc Gregory Fong <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/bus/brcmstb_gisb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/bus/brcmstb_gisb.c +1 -3
index 72fe0a5a8bf3..2616d8208777 100644
@@ -13,7 +13,6 @@
 
 #include <linux/init.h>
 #include <linux/types.h>
-#include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/interrupt.h>
 #include <linux/sysfs.h>
@@ -438,5 +437,4 @@ static int __init brcm_gisb_driver_init(void)
 	return platform_driver_probe(&brcmstb_gisb_arb_driver,
 				     brcmstb_gisb_arb_probe);
 }
-
-module_init(brcm_gisb_driver_init);
+device_initcall(brcm_gisb_driver_init);
Signature · 1 line
2.8.4
#3 lore raw

PATCH v2 2/4 bus: imx-weim: make it explicitly non-modular

In reply to Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

drivers/bus/Kconfig:config IMX_WEIM
drivers/bus/Kconfig: bool "Freescale EIM DRIVER

...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 Shawn Guo <[email protected]>
Cc Alison Chaiken <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/bus/imx-weim.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/bus/imx-weim.c +2 -7
index 4bd361d64270..cdc75b1b264d 100644
@@ -7,7 +7,7 @@
  * License version 2. This program is licensed "as is" without any
  * warranty of any kind, whether express or implied.
  */
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/of_device.h>
@@ -57,7 +57,6 @@ static const struct of_device_id weim_id_table[] = {
 	{ .compatible = "fsl,imx51-weim", .data = &imx51_weim_devtype, },
 	{ }
 };
-MODULE_DEVICE_TABLE(of, weim_id_table);
 
 static int __init imx_weim_gpr_setup(struct platform_device *pdev)
 {
@@ -209,8 +208,4 @@ static struct platform_driver weim_driver = {
 		.of_match_table	= weim_id_table,
 	},
 };
-module_platform_driver_probe(weim_driver, weim_probe);
-
-MODULE_AUTHOR("Freescale Semiconductor Inc.");
-MODULE_DESCRIPTION("i.MX EIM Controller Driver");
-MODULE_LICENSE("GPL");
+builtin_platform_driver_probe(weim_driver, weim_probe);
Signature · 1 line
2.8.4
#4 lore raw

PATCH v2 3/4 bus: tegra-aconnect: make it explicitly non-modular

In reply to Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

drivers/bus/Kconfig:config TEGRA_ACONNECT
drivers/bus/Kconfig: bool "Tegra ACONNECT Bus Driver"

...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 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 was (or is now) contained at the top of the file in the comments.

Cc Stephen Warren <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Jon Hunter <[email protected]>
Cc linux-tegra at vger.kernel.org
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/bus/tegra-aconnect.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)
drivers/bus/tegra-aconnect.c +5 -17
index 7e4104b74fa8..f3982946ab8a 100644
@@ -1,6 +1,8 @@
 /*
  * Tegra ACONNECT Bus Driver
  *
+ * Author: Jon Hunter <[email protected]>
+ *
  * Copyright (C) 2016, NVIDIA CORPORATION.  All rights reserved.
  *
  * This file is subject to the terms and conditions of the GNU General Public
@@ -9,7 +11,7 @@
  */
 
 #include <linux/clk.h>
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/pm_clock.h>
@@ -66,15 +68,6 @@ clk_destroy:
 	return ret;
 }
 
-static int tegra_aconnect_remove(struct platform_device *pdev)
-{
-	pm_runtime_disable(&pdev->dev);
-
-	pm_clk_destroy(&pdev->dev);
-
-	return 0;
-}
-
 static int tegra_aconnect_runtime_resume(struct device *dev)
 {
 	return pm_clk_resume(dev);
@@ -94,19 +87,14 @@ static const struct of_device_id tegra_aconnect_of_match[] = {
 	{ .compatible = "nvidia,tegra210-aconnect", },
 	{ }
 };
-MODULE_DEVICE_TABLE(of, tegra_aconnect_of_match);
 
 static struct platform_driver tegra_aconnect_driver = {
 	.probe = tegra_aconnect_probe,
-	.remove = tegra_aconnect_remove,
 	.driver = {
 		.name = "tegra-aconnect",
+		.suppress_bind_attrs = true,
 		.of_match_table = tegra_aconnect_of_match,
 		.pm = &tegra_aconnect_pm_ops,
 	},
 };
-module_platform_driver(tegra_aconnect_driver);
-
-MODULE_DESCRIPTION("NVIDIA Tegra ACONNECT Bus Driver");
-MODULE_AUTHOR("Jon Hunter <[email protected]>");
-MODULE_LICENSE("GPL v2");
+builtin_platform_driver(tegra_aconnect_driver);
Signature · 1 line
2.8.4
#8 lore raw

PATCH v2 4/4 bus: simple-pm-bus: convert bool SIMPLE_PM_BUS to tristate

In reply to Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

config SIMPLE_PM_BUS
bool "Simple Power-Managed Bus Driver"

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

In removing the orphaned modular support in a previous patch set, Geert indicated he'd rather see this code converted to tristate.

I normally don't do that because it extends functionality that I can't easily run time test or even know if the use case makes sense, but since in this case the author has nominated it as such, we do the conversion here.

Note that doesn't change the lack of run time testing ; this change is only tested for sucessful compile and modpost.

Cc Geert Uytterhoeven <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Simon Horman <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 drivers/bus/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/Kconfig +1 -1
index 3b205e212337..f4162c76a5f6 100644
@@ -109,7 +109,7 @@ config OMAP_OCP2SCP
 	  OCP2SCP.
 
 config SIMPLE_PM_BUS
-	bool "Simple Power-Managed Bus Driver"
+	tristate "Simple Power-Managed Bus Driver"
 	depends on OF && PM
 	depends on ARCH_RENESAS || COMPILE_TEST
 	help
Signature · 1 line
2.8.4
maintainer
#5 lore raw

Re: [PATCH 3/4] bus: tegra-aconnect: make it explicitly non-modular

In reply to Paul Gortmaker

Hi Paul,

Quoted 14 lines · Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

drivers/bus/Kconfig:config TEGRA_ACONNECT
drivers/bus/Kconfig: bool "Tegra ACONNECT Bus Driver"

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

Quoted 8 lines

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 was (or is now) contained at the top of the file in the comments.

In version 3 of the aconnect series [0] I had made this a tristate because we allowed it to be removed and you had submitted a patch to export the PM_CLK APIs. However, when discussing with Thierry he said that we were unable to merge with tristate because of the dependency on your patch. So he suggested we merge with bool for now and then change it back to tristate for v4.9.

I understand that we should not do this, but we do plan to make this modular in the future.

Cheers
Jon

[0] http://marc.info/?l=linux-tegra&m=146616753627760&w=2

Signature · 1 line
nvpublic
#6 lore raw

Re: [PATCH 3/4] bus: tegra-aconnect: make it explicitly non-modular

Quoted 26 lines · [Re: [PATCH 3/4] bus: tegra-aconnect: make it explicitly non-modular] On…

Hi Paul,

Quoted 14 lines · Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

drivers/bus/Kconfig:config TEGRA_ACONNECT
drivers/bus/Kconfig: bool "Tegra ACONNECT Bus Driver"

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

Quoted 8 lines

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 was (or is now) contained at the top of the file in the comments.

Quoted 6 lines

In version 3 of the aconnect series [0] I had made this a tristate because we allowed it to be removed and you had submitted a patch to export the PM_CLK APIs. However, when discussing with Thierry he said that we were unable to merge with tristate because of the dependency on your patch. So he suggested we merge with bool for now and then change it back to tristate for v4.9.

Oh I see. The exported clock syms were for the 210 DMA driver and it never crossed my mind that this driver needed the same syms in order for it to be tristate. Guess the exports proved useful afterall. :)

Quoted 3 lines

I understand that we should not do this, but we do plan to make this modular in the future.

No problem ; I will drop this patch in favor of a one line Kconfig patch in my test queue so it doesn't trip the regular audit, just like I have for the 210 below -- not yet submitted for the same dependency reason.

P.
---

From fe5bdc6348828c157deb14e8d75c732abcc2ad2b Mon Sep 17 00:00:00 2001
From: Paul Gortmaker <[email protected]>
Date: Fri, 20 May 2016 14:30:43 -0400
Subject: [PATCH] dma: tegra210-adma: convert TEGRA210_ADMA from bool to
tristate

This driver currently uses modular infrastructure but is controlled by a bool Kconfig.

There is a general consensus from the DMA reviewers and maintainers that "if it can be modular, it should be modular" in order to keep the bzImage size under control for multi platform kernels.

Build tested only. Also needs some new pm_clk symbols exported before this commit is applied to tree in order to avoid modpost errors like:

ERROR: "pm_clk_add_clk" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_create" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_destroy" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_suspend" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_resume" [drivers/dma/tegra210-adma.ko] undefined!

Cc Laxman Dewangan <[email protected]>
Cc Jon Hunter <[email protected]>
Cc Dan Williams <[email protected]>
Cc Vinod Koul <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc dmaengine at vger.kernel.org
Cc linux-tegra at vger.kernel.org
---
 drivers/dma/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/Kconfig +1 -1
index 8c98779a12b1..866068d84ca2 100644
@@ -468,7 +468,7 @@ config TEGRA20_APB_DMA
 	  or vice versa. It does not support memory to memory data transfer.
 
 config TEGRA210_ADMA
-	bool "NVIDIA Tegra210 ADMA support"
+	tristate "NVIDIA Tegra210 ADMA support"
 	depends on ARCH_TEGRA_210_SOC
 	select DMA_ENGINE
 	select DMA_VIRTUAL_CHANNELS
Signature · 1 line
2.8.0
Quoted 8 lines

Cheers
Jon

[0] http://marc.info/?l=linux-tegra&m=146616753627760&w=2

Signature · 1 line
nvpublic
maintainer Acked-by
#7 lore raw

Re: [PATCH 3/4] bus: tegra-aconnect: make it explicitly non-modular

Quoted 35 lines · Paul Gortmaker
Quoted 26 lines · [Re: [PATCH 3/4] bus: tegra-aconnect: make it explicitly non-modular] On…

Hi Paul,

Quoted 14 lines · Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

drivers/bus/Kconfig:config TEGRA_ACONNECT
drivers/bus/Kconfig: bool "Tegra ACONNECT Bus Driver"

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

Quoted 8 lines

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 was (or is now) contained at the top of the file in the comments.

Quoted 6 lines

In version 3 of the aconnect series [0] I had made this a tristate because we allowed it to be removed and you had submitted a patch to export the PM_CLK APIs. However, when discussing with Thierry he said that we were unable to merge with tristate because of the dependency on your patch. So he suggested we merge with bool for now and then change it back to tristate for v4.9.

Quoted 3 lines

Oh I see. The exported clock syms were for the 210 DMA driver and it never crossed my mind that this driver needed the same syms in order for it to be tristate. Guess the exports proved useful afterall. :)

Yes indeed and I did learn my lesson after your previous catch for the ADMA ;-)

Quoted 54 lines
Quoted 3 lines

I understand that we should not do this, but we do plan to make this modular in the future.

No problem ; I will drop this patch in favor of a one line Kconfig patch in my test queue so it doesn't trip the regular audit, just like I have for the 210 below -- not yet submitted for the same dependency reason.

P.
---

From fe5bdc6348828c157deb14e8d75c732abcc2ad2b Mon Sep 17 00:00:00 2001
From: Paul Gortmaker <[email protected]>
Date: Fri, 20 May 2016 14:30:43 -0400
Subject: [PATCH] dma: tegra210-adma: convert TEGRA210_ADMA from bool to
tristate

This driver currently uses modular infrastructure but is controlled by a bool Kconfig.

There is a general consensus from the DMA reviewers and maintainers that "if it can be modular, it should be modular" in order to keep the bzImage size under control for multi platform kernels.

Build tested only. Also needs some new pm_clk symbols exported before this commit is applied to tree in order to avoid modpost errors like:

ERROR: "pm_clk_add_clk" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_create" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_destroy" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_suspend" [drivers/dma/tegra210-adma.ko] undefined!
ERROR: "pm_clk_resume" [drivers/dma/tegra210-adma.ko] undefined!

Cc Laxman Dewangan <[email protected]>
Cc Jon Hunter <[email protected]>
Cc Dan Williams <[email protected]>
Cc Vinod Koul <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc dmaengine at vger.kernel.org
Cc linux-tegra at vger.kernel.org
---
 drivers/dma/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/Kconfig +0 -0
index 8c98779a12b1..866068d84ca2 100644

drivers/dma/Kconfig config TEGRA20_APB_DMA · line 474

Quoted 8 lines
drivers/dma/Kconfig +1 -1
@@ -468,7 +468,7 @@ config TEGRA20_APB_DMA
 	  or vice versa. It does not support memory to memory data transfer.
 
 config TEGRA210_ADMA
-	bool "NVIDIA Tegra210 ADMA support"
+	tristate "NVIDIA Tegra210 ADMA support"
 	depends on ARCH_TEGRA_210_SOC
 	select DMA_ENGINE
 	select DMA_VIRTUAL_CHANNELS

Thanks! FWIW ...

Cheers
Jon

Signature · 1 line
nvpublic
Tested-by on v2 4/4
#9 lore raw

Re: [PATCH 4/4] bus: simple-pm-bus: convert bool SIMPLE_PM_BUS to tristate

In reply to Paul Gortmaker

Hi Paul,

Quoted 10 lines · Paul Gortmaker

The Kconfig currently controlling compilation of this code is:

config SIMPLE_PM_BUS
bool "Simple Power-Managed Bus Driver"

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

In removing the orphaned modular support in a previous patch set, Geert indicated he'd rather see this code converted to tristate.

Quoted 7 lines

I normally don't do that because it extends functionality that I can't easily run time test or even know if the use case makes sense, but since in this case the author has nominated it as such, we do the conversion here.

Note that doesn't change the lack of run time testing ; this change is only tested for sucessful compile and modpost.

Thanks!

Quoted 5 lines
Cc Geert Uytterhoeven <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Simon Horman <[email protected]>
Cc linux-arm-kernel at lists.infradead.org

Ethernet is probed successfully on sh73a0/kzm9g after insmodding simple-pm-bus.ko.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#2 lore raw

Re: [PATCH 1/4] bus: brcmstb_gisb: make it explicitly non-modular

In reply to Paul Gortmaker
Quoted 12 lines · Paul Gortmaker

The Kconfig for this driver is currently:

config BRCMSTB_GISB_ARB
bool "Broadcom STB GISB bus arbiter"

...meaning that it currently is not being built as a module by anyone. Lets remove all modular references, 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.

Quoted 7 lines
Cc Brian Norris <[email protected]>
Cc Gregory Fong <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc linux-arm-kernel at lists.infradead.org

Applied to drivers/next, thanks Paul
--
Florian