Provide a module_nd_driver() wrapper and move over the appliccable
drivers nd_pmem.ko and dax_pmem.ko.
Johannes Thumshirn (3):
libnvdimm: provide module_nd_driver wrapper
libnvdimm, pmem: use module_nd_driver
device-dax: use module_nd_driver
drivers/dax/pmem.c | 12 +-----------
drivers/nvdimm/pmem.c | 12 +-----------
include/linux/nd.h | 6 ++++++
3 files changed, 8 insertions(+), 22 deletions(-)
--
2.13.6
Use module_nd_driver() instead of having module_init() and
module_exit() callbacks which just call nd_driver_register() and
nd_driver_unregister().
Signed-off-by: Johannes Thumshirn <[email protected]>
---
drivers/nvdimm/pmem.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 06f8dcc52ca6..d8ab882be790 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -547,17 +547,7 @@ static struct nd_device_driver nd_pmem_driver = {
.type = ND_DRIVER_NAMESPACE_IO | ND_DRIVER_NAMESPACE_PMEM,
};
-static int __init pmem_init(void)
-{
- return nd_driver_register(&nd_pmem_driver);
-}
-module_init(pmem_init);
-
-static void pmem_exit(void)
-{
- driver_unregister(&nd_pmem_driver.drv);
-}
-module_exit(pmem_exit);
+module_nd_driver(nd_pmem_driver);
MODULE_AUTHOR("Ross Zwisler <[email protected]>");
MODULE_LICENSE("GPL v2");
--
2.13.6
Use module_nd_driver() instead of having module_init() and
module_exit() callbacks which just call nd_driver_register() and
nd_driver_unregister().
Signed-off-by: Johannes Thumshirn <[email protected]>
---
drivers/dax/pmem.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
index 31b6ecce4c64..d927ae82ba0d 100644
--- a/drivers/dax/pmem.c
+++ b/drivers/dax/pmem.c
@@ -150,17 +150,7 @@ static struct nd_device_driver dax_pmem_driver = {
.type = ND_DRIVER_DAX_PMEM,
};
-static int __init dax_pmem_init(void)
-{
- return nd_driver_register(&dax_pmem_driver);
-}
-module_init(dax_pmem_init);
-
-static void __exit dax_pmem_exit(void)
-{
- driver_unregister(&dax_pmem_driver.drv);
-}
-module_exit(dax_pmem_exit);
+module_nd_driver(dax_pmem_driver);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Intel Corporation");
--
2.13.6
Provide a module_nd_driver() wrapper over simple nd_driver_register()
nd_driver_unregister() combinations in module_init() and module_exit()
respectively.
Note an explicit nd_driver_unregister() had to be implemented as nd
bus drivers did call device_unregister() direcly in the module_exit()
function.
Signed-off-by: Johannes Thumshirn <[email protected]>
---
include/linux/nd.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/nd.h b/include/linux/nd.h
index 5dc6b695437d..43c181a6add5 100644
--- a/include/linux/nd.h
+++ b/include/linux/nd.h
@@ -180,6 +180,12 @@ struct nd_region;
void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event);
int __must_check __nd_driver_register(struct nd_device_driver *nd_drv,
struct module *module, const char *mod_name);
+static inline void nd_driver_unregister(struct nd_device_driver *drv)
+{
+ driver_unregister(&drv->drv);
+}
#define nd_driver_register(driver) \
__nd_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
+#define module_nd_driver(driver) \
+ module_driver(driver, nd_driver_register, nd_driver_unregister)
#endif /* __LINUX_ND_H__ */
--
2.13.6
On Wed, Mar 14, 2018 at 07:25:05PM +0100, Johannes Thumshirn wrote:
> Provide a module_nd_driver() wrapper and move over the appliccable
> drivers nd_pmem.ko and dax_pmem.ko.
What is the point? It saves a hand fulk of lines, while making
the code both harder to read and harder to extend.
On Thu, Mar 15, 2018 at 12:22:57AM -0700, Christoph Hellwig wrote:
> What is the point? It saves a hand fulk of lines, while making
> the code both harder to read and harder to extend.
In the end it's just style alignment with most of the other "busses"
in the kernel, like pci, of, acpi, platform and so on...
But yes I admit it's not a huge win. For the harder to read part, I
doubt it. A quick:
git grep -E module_.*._driver drivers/ | wc -l
has 3896 hit's, so it's not that uncommon ;-)
But anyways, it's just code churn I came up with while being
frustrated hunting down a bug in this subsystem.
Byte,
Johannes
--
Johannes Thumshirn Storage
[email protected] +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
On Thu, Mar 15, 2018 at 1:11 AM, Johannes Thumshirn <[email protected]> wrote:
> On Thu, Mar 15, 2018 at 12:22:57AM -0700, Christoph Hellwig wrote:
>> What is the point? It saves a hand fulk of lines, while making
>> the code both harder to read and harder to extend.
>
> In the end it's just style alignment with most of the other "busses"
> in the kernel, like pci, of, acpi, platform and so on...
>
> But yes I admit it's not a huge win. For the harder to read part, I
> doubt it. A quick:
> git grep -E module_.*._driver drivers/ | wc -l
> has 3896 hit's, so it's not that uncommon ;-)
>
> But anyways, it's just code churn I came up with while being
> frustrated hunting down a bug in this subsystem.
>
Works for me. Removing more lines than you add is always welcome.