Skip to contentSkip to conversation

serial: pxa: make it explicitly non-modular

PATCH New Paul Gortmaker 1 participant 4 messages Jun 20, 2016 – Jun 21, 2016 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/3 serial: pxa: make it explicitly non-modular

The Kconfig currently controlling compilation of this code is:

drivers/tty/serial/Kconfig:config SERIAL_PXA
drivers/tty/serial/Kconfig: bool "PXA serial port support"

...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_init translates to device_initcall in the non-modular case, the init ordering remains unchanged with this commit.

Also note that MODULE_DEVICE_TABLE and MODULE_ALIAS are both a no-op for non-modular builds.

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

---
 drivers/tty/serial/pxa.c | 31 +++----------------------------
 1 file changed, 3 insertions(+), 28 deletions(-)
drivers/tty/serial/pxa.c +2 -28
index 41eab75ba2af..29c2309b4b28 100644
@@ -27,7 +27,6 @@
 #define SUPPORT_SYSRQ
 #endif
 
-#include <linux/module.h>
 #include <linux/ioport.h>
 #include <linux/init.h>
 #include <linux/console.h>
@@ -829,7 +829,6 @@ static const struct of_device_id serial_pxa_dt_ids[] = {
 	{ .compatible = "mrvl,mmp-uart", },
 	{}
 };
-MODULE_DEVICE_TABLE(of, serial_pxa_dt_ids);
 
 static int serial_pxa_probe_dt(struct platform_device *pdev,
 			       struct uart_pxa_port *sport)
@@ -914,28 +913,15 @@ static int serial_pxa_probe(struct platform_device *dev)
 	return ret;
 }
 
-static int serial_pxa_remove(struct platform_device *dev)
-{
-	struct uart_pxa_port *sport = platform_get_drvdata(dev);
-
-	uart_remove_one_port(&serial_pxa_reg, &sport->port);
-
-	clk_unprepare(sport->clk);
-	clk_put(sport->clk);
-	kfree(sport);
-
-	return 0;
-}
-
 static struct platform_driver serial_pxa_driver = {
         .probe          = serial_pxa_probe,
-        .remove         = serial_pxa_remove,
 
 	.driver		= {
 	        .name	= "pxa2xx-uart",
 #ifdef CONFIG_PM
 		.pm	= &serial_pxa_pm_ops,
 #endif
+		.suppress_bind_attrs = true,
 		.of_match_table = serial_pxa_dt_ids,
 	},
 };
@@ -954,15 +940,4 @@ static int __init serial_pxa_init(void)
 
 	return ret;
 }
-
-static void __exit serial_pxa_exit(void)
-{
-	platform_driver_unregister(&serial_pxa_driver);
-	uart_unregister_driver(&serial_pxa_reg);
-}
-
-module_init(serial_pxa_init);
-module_exit(serial_pxa_exit);
-
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:pxa2xx-uart");
+device_initcall(serial_pxa_init);
Signature · 1 line
2.8.4
#2 lore raw

PATCH 2/3 serial: vt8500_serial: make it explicitly non-modular

In reply to a message not in the archive

The Kconfig currently controlling compilation of this code is:

drivers/tty/serial/Kconfig:config SERIAL_VT8500
drivers/tty/serial/Kconfig: bool "VIA VT8500 on-chip serial port support"

...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_init translates to device_initcall in the non-modular case, the init ordering remains unchanged with this commit.

We don't replace module.h with init.h since the file already has that.

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 Tony Prisk <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Alexey Charkov <[email protected]>
---
 drivers/tty/serial/vt8500_serial.c | 30 ++----------------------------
 1 file changed, 2 insertions(+), 28 deletions(-)
drivers/tty/serial/vt8500_serial.c +2 -28
index b384060e3b1f..23cfc5e16b45 100644
@@ -21,7 +21,6 @@
 
 #include <linux/hrtimer.h>
 #include <linux/delay.h>
-#include <linux/module.h>
 #include <linux/io.h>
 #include <linux/ioport.h>
 #include <linux/irq.h>
@@ -730,22 +729,12 @@ static int vt8500_serial_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int vt8500_serial_remove(struct platform_device *pdev)
-{
-	struct vt8500_port *vt8500_port = platform_get_drvdata(pdev);
-
-	clk_disable_unprepare(vt8500_port->clk);
-	uart_remove_one_port(&vt8500_uart_driver, &vt8500_port->uart);
-
-	return 0;
-}
-
 static struct platform_driver vt8500_platform_driver = {
 	.probe  = vt8500_serial_probe,
-	.remove = vt8500_serial_remove,
 	.driver = {
 		.name = "vt8500_serial",
 		.of_match_table = wmt_dt_ids,
+		.suppress_bind_attrs = true,
 	},
 };
 
@@ -764,19 +753,4 @@ static int __init vt8500_serial_init(void)
 
 	return ret;
 }
-
-static void __exit vt8500_serial_exit(void)
-{
-#ifdef CONFIG_SERIAL_VT8500_CONSOLE
-	unregister_console(&vt8500_console);
-#endif
-	platform_driver_unregister(&vt8500_platform_driver);
-	uart_unregister_driver(&vt8500_uart_driver);
-}
-
-module_init(vt8500_serial_init);
-module_exit(vt8500_serial_exit);
-
-MODULE_AUTHOR("Alexey Charkov <[email protected]>");
-MODULE_DESCRIPTION("Driver for vt8500 serial device");
-MODULE_LICENSE("GPL v2");
+device_initcall(vt8500_serial_init);
Signature · 1 line
2.8.4
#3 lore raw

PATCH 3/3 serial: m32r_sio: make it explicitly non-modular

In reply to a message not in the archive

The Kconfig currently controlling compilation of this code is:

drivers/tty/serial/Kconfig:config SERIAL_M32R_SIO
drivers/tty/serial/Kconfig: bool "M32R SIO I/F"

...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 already contained at the top of the file in the comments.

We don't replace module.h with init.h since the file already has that.

---
 drivers/tty/serial/m32r_sio.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)
drivers/tty/serial/m32r_sio.c +1 -17
index 68765f7c2645..ea29017d320a 100644
@@ -30,7 +30,6 @@
 #define SUPPORT_SYSRQ
 #endif
 
-#include <linux/module.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
 #include <linux/ioport.h>
@@ -1060,19 +1059,4 @@ static int __init m32r_sio_init(void)
 
 	return ret;
 }
-
-static void __exit m32r_sio_exit(void)
-{
-	int i;
-
-	for (i = 0; i < UART_NR; i++)
-		uart_remove_one_port(&m32r_sio_reg, &m32r_sio_ports[i].port);
-
-	uart_unregister_driver(&m32r_sio_reg);
-}
-
-module_init(m32r_sio_init);
-module_exit(m32r_sio_exit);
-
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("Generic M32R SIO serial driver");
+device_initcall(m32r_sio_init);
Signature · 1 line
2.8.4
#4 lore raw

Re: [PATCH 0/3] serial: remove modular code from a few more non-modular drivers

In reply to a message not in the archive
Quoted 10 lines · [[PATCH 0/3] serial: remove modular code from a few more non-modular drivers]…

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.

Quoted 2 lines

We have already fixed a bunch of these in drivers/tty already, so there is really nothing new to see here (at least for the serial maintainers).

Apologies in advance to anyone who is trying to find these patches via an archive of linux-kernel or linux-serial ; it seems that we hit a window where a glitch at vger.kernel.org was rejecting incoming mails.

P.
--

Quoted 55 lines

Changes seen here cover the following categories:

-just replacement of modular macros with their non-modular
equivalents that CPP would have inserted anyway

-the removal of including module.h ; replaced with init.h
as required based on whether the file already had it.

-the removal of any/all unused/orphaned __exit functions
that would never be called/exercised.

-the removal of any ".remove" functions that were hooked into
the driver struct. This ".remove" function would of
course not be called from the __exit function since that was never run. However in theory, someone could have triggered it via sysfs unbind, even though there isn't a sensible use case for doing so. So to cover that possibility, we've also disabled sysfs unbind in the driver.

In doing so we get rid of ~70 lines of dead code across 3 drivers.

There are no initcall level changes here; everything was at the level of device_initcall and remains so, by using the builtin equivalents.

Build tested for arm(2) and m32r(1) on the linux-next tree from today to ensure no silly typos crept in.

If there is a desire for any of these to be modular, we can definitely consider that, but by default the changes here keep the code consistent with existing behaviour. Thus I do not expand functionality into the modular realm that I can't run time test, or even know if the modular instance has a sensible modular use case.

Paul.
---

Cc Alexey Charkov <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
Cc Tony Prisk <[email protected]>

Paul Gortmaker (3):
serial: pxa: make it explicitly non-modular
serial: vt8500_serial: make it explicitly non-modular
serial: m32r_sio: make it explicitly non-modular

 drivers/tty/serial/m32r_sio.c      | 18 +-----------------
 drivers/tty/serial/pxa.c           | 31 +++----------------------------
 drivers/tty/serial/vt8500_serial.c | 30 ++----------------------------
 3 files changed, 6 insertions(+), 73 deletions(-)
Signature · 1 line
2.8.4