Skip to contentSkip to conversation

Introduces the module_mtd_blktrans macro

PATCH Applied Dejin Zheng 2 participants 17 messages Feb 13, 2021 – Mar 2, 2021 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

cover Introduces the module_mtd_blktrans macro

This patchset introduces the module_mtd_blktrans macro which is a convenience macro for mtd blktrans modules similar to module_platform_driver. It is intended to be used by drivers which init/exit section does nothing but register/unregister the mtd blktrans driver. By using this macro it is possible to eliminate a few lines of boilerplate code per mtd blktrans driver.

Dejin Zheng (8):
mtd: Add helper macro for register_mtd_blktrans boilerplate
mtd: ftl: Use module_mtd_blktrans to register driver
mtd: inftlcore: Use module_mtd_blktrans to register driver
mtd: mtdblock: Use module_mtd_blktrans to register driver
mtd: mtdblock_ro: Use module_mtd_blktrans to register driver
mtd: mtdswap: Use module_mtd_blktrans to register driver
mtd: nftlcore: Use module_mtd_blktrans to register driver
mtd: rfd_ftl: Use module_mtd_blktrans to register driver

 drivers/mtd/ftl.c            | 14 +-------------
 drivers/mtd/inftlcore.c      | 13 +------------
 drivers/mtd/mtdblock.c       | 14 +-------------
 drivers/mtd/mtdblock_ro.c    | 13 +------------
 drivers/mtd/mtdswap.c        | 14 +-------------
 drivers/mtd/nftlcore.c       | 13 +------------
 drivers/mtd/rfd_ftl.c        | 13 +------------
 include/linux/mtd/blktrans.h | 11 +++++++++++
 8 files changed, 18 insertions(+), 87 deletions(-)
Signature · 1 line
2.25.0
#1 lore raw

PATCH 1/8 mtd: Add helper macro for register_mtd_blktrans boilerplate

This patch introduces the module_mtd_blktrans macro which is a convenience macro for mtd blktrans modules similar to module_platform_driver. It is intended to be used by drivers which init/exit section does nothing but register/unregister the mtd blktrans driver. By using this macro it is possible to eliminate a few lines of boilerplate code per mtd blktrans driver.

---
 include/linux/mtd/blktrans.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/mtd/blktrans.h +11 -0
index 3c668cb1e344..15cc9b95e32b 100644
@@ -77,5 +77,16 @@ extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
 extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
 extern int mtd_blktrans_cease_background(struct mtd_blktrans_dev *dev);
 
+/**
+ * module_mtd_blktrans() - Helper macro for registering a mtd blktrans driver
+ * @__mtd_blktrans: mtd_blktrans_ops struct
+ *
+ * Helper macro for mtd blktrans drivers which do not do anything special in
+ * module init/exit. This eliminates a lot of boilerplate. Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */
+#define module_mtd_blktrans(__mtd_blktrans) \
+	module_driver(__mtd_blktrans, register_mtd_blktrans, \
+					deregister_mtd_blktrans)
 
 #endif /* __MTD_TRANS_H__ */
Signature · 1 line
2.25.0
maintainer Applied
#2 lore raw

Re: [PATCH mtd/next 1/8] mtd: Add helper macro for register_mtd_blktrans boilerplate

Quoted 8 lines · Dejin Zheng

This patch introduces the module_mtd_blktrans macro which is a convenience macro for mtd blktrans modules similar to module_platform_driver. It is intended to be used by drivers which init/exit section does nothing but register/unregister the mtd blktrans driver. By using this macro it is possible to eliminate a few lines of boilerplate code per mtd blktrans driver.

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

#3 lore raw

PATCH 2/8 mtd: ftl: Use module_mtd_blktrans to register driver

In reply to Dejin Zheng

Removing some boilerplate by using module_mtd_blktrans instead of calling register and unregister in the otherwise empty init/exit functions.

---
 drivers/mtd/ftl.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/mtd/ftl.c +1 -13
index 2578f27914ef..9b33c082179d 100644
@@ -1056,19 +1056,7 @@ static struct mtd_blktrans_ops ftl_tr = {
 	.owner		= THIS_MODULE,
 };
 
-static int __init init_ftl(void)
-{
-	return register_mtd_blktrans(&ftl_tr);
-}
-
-static void __exit cleanup_ftl(void)
-{
-	deregister_mtd_blktrans(&ftl_tr);
-}
-
-module_init(init_ftl);
-module_exit(cleanup_ftl);
-
+module_mtd_blktrans(ftl_tr);
 
 MODULE_LICENSE("Dual MPL/GPL");
 MODULE_AUTHOR("David Hinds <[email protected]>");
Signature · 1 line
2.25.0
#5 lore raw

PATCH 3/8 mtd: inftlcore: Use module_mtd_blktrans to register driver

In reply to Dejin Zheng

Removing some boilerplate by using module_mtd_blktrans instead of calling register and unregister in the otherwise empty init/exit functions.

---
 drivers/mtd/inftlcore.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/mtd/inftlcore.c +1 -12
index a0d6c00e7b85..6b48397c750c 100644
@@ -937,18 +937,7 @@ static struct mtd_blktrans_ops inftl_tr = {
 	.owner		= THIS_MODULE,
 };
 
-static int __init init_inftl(void)
-{
-	return register_mtd_blktrans(&inftl_tr);
-}
-
-static void __exit cleanup_inftl(void)
-{
-	deregister_mtd_blktrans(&inftl_tr);
-}
-
-module_init(init_inftl);
-module_exit(cleanup_inftl);
+module_mtd_blktrans(inftl_tr);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Greg Ungerer <[email protected]>, David Woodhouse <[email protected]>, Fabrice Bellard <[email protected]> et al.");
Signature · 6 lines
2.25.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#7 lore raw

PATCH 4/8 mtd: mtdblock: Use module_mtd_blktrans to register driver

In reply to Dejin Zheng

Removing some boilerplate by using module_mtd_blktrans instead of calling register and unregister in the otherwise empty init/exit functions.

---
 drivers/mtd/mtdblock.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/mtd/mtdblock.c +1 -13
index 32e52d83b961..a80809543793 100644
@@ -346,19 +346,7 @@ static struct mtd_blktrans_ops mtdblock_tr = {
 	.owner		= THIS_MODULE,
 };
 
-static int __init init_mtdblock(void)
-{
-	return register_mtd_blktrans(&mtdblock_tr);
-}
-
-static void __exit cleanup_mtdblock(void)
-{
-	deregister_mtd_blktrans(&mtdblock_tr);
-}
-
-module_init(init_mtdblock);
-module_exit(cleanup_mtdblock);
-
+module_mtd_blktrans(mtdblock_tr);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Nicolas Pitre <[email protected]> et al.");
Signature · 6 lines
2.25.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#9 lore raw

PATCH 5/8 mtd: mtdblock_ro: Use module_mtd_blktrans to register driver

In reply to Dejin Zheng

Removing some boilerplate by using module_mtd_blktrans instead of calling register and unregister in the otherwise empty init/exit functions.

---
 drivers/mtd/mtdblock_ro.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/mtd/mtdblock_ro.c +1 -12
index 7fcf29ef2bdc..d92914f73d52 100644
@@ -67,18 +67,7 @@ static struct mtd_blktrans_ops mtdblock_tr = {
 	.owner		= THIS_MODULE,
 };
 
-static int __init mtdblock_init(void)
-{
-	return register_mtd_blktrans(&mtdblock_tr);
-}
-
-static void __exit mtdblock_exit(void)
-{
-	deregister_mtd_blktrans(&mtdblock_tr);
-}
-
-module_init(mtdblock_init);
-module_exit(mtdblock_exit);
+module_mtd_blktrans(mtdblock_tr);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("David Woodhouse <[email protected]>");
Signature · 6 lines
2.25.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#11 lore raw

PATCH 6/8 mtd: mtdswap: Use module_mtd_blktrans to register driver

In reply to Dejin Zheng

Removing some boilerplate by using module_mtd_blktrans instead of calling register and unregister in the otherwise empty init/exit functions.

---
 drivers/mtd/mtdswap.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/mtd/mtdswap.c +1 -13
index 795dec4483c2..7e309270ddd4 100644
@@ -1484,19 +1484,7 @@ static struct mtd_blktrans_ops mtdswap_ops = {
 	.owner		= THIS_MODULE,
 };
 
-static int __init mtdswap_modinit(void)
-{
-	return register_mtd_blktrans(&mtdswap_ops);
-}
-
-static void __exit mtdswap_modexit(void)
-{
-	deregister_mtd_blktrans(&mtdswap_ops);
-}
-
-module_init(mtdswap_modinit);
-module_exit(mtdswap_modexit);
-
+module_mtd_blktrans(mtdswap_ops);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Jarkko Lavinen <[email protected]>");
Signature · 6 lines
2.25.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#13 lore raw

PATCH 7/8 mtd: nftlcore: Use module_mtd_blktrans to register driver

In reply to Dejin Zheng

Removing some boilerplate by using module_mtd_blktrans instead of calling register and unregister in the otherwise empty init/exit functions.

---
 drivers/mtd/nftlcore.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/mtd/nftlcore.c +1 -12
index d44641129cdb..bcd0094f172d 100644
@@ -797,18 +797,7 @@ static struct mtd_blktrans_ops nftl_tr = {
 	.owner		= THIS_MODULE,
 };
 
-static int __init init_nftl(void)
-{
-	return register_mtd_blktrans(&nftl_tr);
-}
-
-static void __exit cleanup_nftl(void)
-{
-	deregister_mtd_blktrans(&nftl_tr);
-}
-
-module_init(init_nftl);
-module_exit(cleanup_nftl);
+module_mtd_blktrans(nftl_tr);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("David Woodhouse <[email protected]>, Fabrice Bellard <[email protected]> et al.");
Signature · 6 lines
2.25.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#15 lore raw

PATCH 8/8 mtd: rfd_ftl: Use module_mtd_blktrans to register driver

In reply to Dejin Zheng

Removing some boilerplate by using module_mtd_blktrans instead of calling register and unregister in the otherwise empty init/exit functions.

---
 drivers/mtd/rfd_ftl.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/mtd/rfd_ftl.c +1 -12
index 3d1df82fa105..cce3bf6f99b4 100644
@@ -794,18 +794,7 @@ static struct mtd_blktrans_ops rfd_ftl_tr = {
 	.owner		= THIS_MODULE,
 };
 
-static int __init init_rfd_ftl(void)
-{
-	return register_mtd_blktrans(&rfd_ftl_tr);
-}
-
-static void __exit cleanup_rfd_ftl(void)
-{
-	deregister_mtd_blktrans(&rfd_ftl_tr);
-}
-
-module_init(init_rfd_ftl);
-module_exit(cleanup_rfd_ftl);
+module_mtd_blktrans(rfd_ftl_tr);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Sean Young <[email protected]>");
Signature · 6 lines
2.25.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/