drivers/rtc/rtc-fsl-ftm-alarm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fsl-ftm-alarm driver can be built out of tree, so change the
macro device_initcall() to module_init() for standard usage.
fsl-ftm-alarm registers a platform driver in module_init function,
however there is no module_exit function to unregister it, and it will
occur resource leak, so add ftm_alarm_exit() function for module_exit.
Signed-off-by: Zhang Jianhua <chris.zjh@huawei.com>
---
v3:
- add semicolon after module_init and module_exit to keep the format
consistent
v2:
- modify the commit message for more accurate description
---
drivers/rtc/rtc-fsl-ftm-alarm.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-fsl-ftm-alarm.c b/drivers/rtc/rtc-fsl-ftm-alarm.c
index c0df49fb978c..7fabfc098299 100644
--- a/drivers/rtc/rtc-fsl-ftm-alarm.c
+++ b/drivers/rtc/rtc-fsl-ftm-alarm.c
@@ -332,7 +332,13 @@ static int __init ftm_alarm_init(void)
return platform_driver_register(&ftm_rtc_driver);
}
-device_initcall(ftm_alarm_init);
+static void __exit ftm_alarm_exit(void)
+{
+ platform_driver_unregister(&ftm_rtc_driver);
+}
+
+module_init(ftm_alarm_init);
+module_exit(ftm_alarm_exit);
MODULE_DESCRIPTION("NXP/Freescale FlexTimer alarm driver");
MODULE_AUTHOR("Biwen Li <biwen.li@nxp.com>");
--
2.31.0
On 05/09/2022 08.26, Zhang Jianhua wrote: > fsl-ftm-alarm driver can be built out of tree, so change the > macro device_initcall() to module_init() for standard usage. "out of tree" usually refers to modules that are not part of the mainline kernel. "can be built as a module" is more accurate and less confusing. > fsl-ftm-alarm registers a platform driver in module_init function, > however there is no module_exit function to unregister it, and it will > occur resource leak, so add ftm_alarm_exit() function for module_exit. It seems that you can avoid a lot of boilerplate using the module_platform_driver macro. The single line module_platform_driver(ftm_rtc_driver); should/could replace the ftm_alarm_init/ftm_alarm_exit functions and the explicit module_init()/module_exit() lines. Rasmus
This is a good idea, thanks. 在 2022/9/5 21:17, Rasmus Villemoes 写道: > On 05/09/2022 08.26, Zhang Jianhua wrote: >> fsl-ftm-alarm driver can be built out of tree, so change the >> macro device_initcall() to module_init() for standard usage. > "out of tree" usually refers to modules that are not part of the > mainline kernel. > > "can be built as a module" is more accurate and less confusing. > >> fsl-ftm-alarm registers a platform driver in module_init function, >> however there is no module_exit function to unregister it, and it will >> occur resource leak, so add ftm_alarm_exit() function for module_exit. > It seems that you can avoid a lot of boilerplate using the > module_platform_driver macro. The single line > > module_platform_driver(ftm_rtc_driver); > > should/could replace the ftm_alarm_init/ftm_alarm_exit functions and the > explicit module_init()/module_exit() lines. > > Rasmus
© 2016 - 2026 Red Hat, Inc.