2021-02-13 16:49:33

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH mtd/next 0/8] 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(-)

--
2.25.0


2021-02-13 16:49:44

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH mtd/next 2/8] mtd: ftl: Use module_mtd_blktrans to register driver

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

Signed-off-by: Dejin Zheng <[email protected]>
---
drivers/mtd/ftl.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index 2578f27914ef..9b33c082179d 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -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]>");
--
2.25.0

2021-02-13 16:49:58

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH mtd/next 3/8] mtd: inftlcore: Use module_mtd_blktrans to register driver

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

Signed-off-by: Dejin Zheng <[email protected]>
---
drivers/mtd/inftlcore.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index a0d6c00e7b85..6b48397c750c 100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
@@ -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.");
--
2.25.0

2021-02-13 16:51:04

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH mtd/next 5/8] mtd: mtdblock_ro: Use module_mtd_blktrans to register driver

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

Signed-off-by: Dejin Zheng <[email protected]>
---
drivers/mtd/mtdblock_ro.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c
index 7fcf29ef2bdc..d92914f73d52 100644
--- a/drivers/mtd/mtdblock_ro.c
+++ b/drivers/mtd/mtdblock_ro.c
@@ -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]>");
--
2.25.0

2021-02-13 16:51:23

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH mtd/next 7/8] mtd: nftlcore: Use module_mtd_blktrans to register driver

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

Signed-off-by: Dejin Zheng <[email protected]>
---
drivers/mtd/nftlcore.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index d44641129cdb..bcd0094f172d 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -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.");
--
2.25.0

2021-02-13 16:53:31

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH mtd/next 8/8] mtd: rfd_ftl: Use module_mtd_blktrans to register driver

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

Signed-off-by: Dejin Zheng <[email protected]>
---
drivers/mtd/rfd_ftl.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 3d1df82fa105..cce3bf6f99b4 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -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]>");
--
2.25.0

2021-02-13 16:53:52

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH mtd/next 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.

Signed-off-by: Dejin Zheng <[email protected]>
---
include/linux/mtd/blktrans.h | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/include/linux/mtd/blktrans.h b/include/linux/mtd/blktrans.h
index 3c668cb1e344..15cc9b95e32b 100644
--- a/include/linux/mtd/blktrans.h
+++ b/include/linux/mtd/blktrans.h
@@ -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__ */
--
2.25.0

2021-03-04 06:38:41

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH mtd/next 5/8] mtd: mtdblock_ro: Use module_mtd_blktrans to register driver

On Sat, 2021-02-13 at 16:45:57 UTC, Dejin Zheng wrote:
> Removing some boilerplate by using module_mtd_blktrans instead of calling
> register and unregister in the otherwise empty init/exit functions.
>
> Signed-off-by: Dejin Zheng <[email protected]>

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

Miquel

2021-03-04 06:38:50

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH mtd/next 8/8] mtd: rfd_ftl: Use module_mtd_blktrans to register driver

On Sat, 2021-02-13 at 16:46:00 UTC, Dejin Zheng wrote:
> Removing some boilerplate by using module_mtd_blktrans instead of calling
> register and unregister in the otherwise empty init/exit functions.
>
> Signed-off-by: Dejin Zheng <[email protected]>

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

Miquel

2021-03-04 06:38:56

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH mtd/next 7/8] mtd: nftlcore: Use module_mtd_blktrans to register driver

On Sat, 2021-02-13 at 16:45:59 UTC, Dejin Zheng wrote:
> Removing some boilerplate by using module_mtd_blktrans instead of calling
> register and unregister in the otherwise empty init/exit functions.
>
> Signed-off-by: Dejin Zheng <[email protected]>

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

Miquel

2021-03-04 06:39:12

by Miquel Raynal

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

On Sat, 2021-02-13 at 16:45:53 UTC, Dejin Zheng wrote:
> 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.
>
> Signed-off-by: Dejin Zheng <[email protected]>

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

Miquel

2021-03-04 07:07:14

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH mtd/next 2/8] mtd: ftl: Use module_mtd_blktrans to register driver

On Sat, 2021-02-13 at 16:45:54 UTC, Dejin Zheng wrote:
> Removing some boilerplate by using module_mtd_blktrans instead of calling
> register and unregister in the otherwise empty init/exit functions.
>
> Signed-off-by: Dejin Zheng <[email protected]>

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

Miquel

2021-03-04 20:24:05

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH mtd/next 3/8] mtd: inftlcore: Use module_mtd_blktrans to register driver

On Sat, 2021-02-13 at 16:45:55 UTC, Dejin Zheng wrote:
> Removing some boilerplate by using module_mtd_blktrans instead of calling
> register and unregister in the otherwise empty init/exit functions.
>
> Signed-off-by: Dejin Zheng <[email protected]>

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

Miquel