2023-03-15 10:03:07

by Miquel Raynal

[permalink] [raw]
Subject: [PATCH 0/4] nvmem: layouts: Create a macro to register drivers

Hello Srinivas,

Following your former review, here are a few changes creating and using
a macro to simplify nvmem layout driver registration.

While doing that I figured out the MODULE_ALIAS() macro in the Onie TLV
driver was useless and wrong, so there is a patch to drop it, but if you
wish you can also squash it with:
"nvmem: layouts: onie-tlv: Add new layout driver".

Thanks!
Miquèl

Miquel Raynal (4):
nvmem: Add macro to register nvmem layout drivers
nvmem: layouts: sl28vpd: Use module_nvmem_layout_driver()
nvmem: layouts: onie-tlv: Use module_nvmem_layout_driver()
nvmem: layouts: onie-tlv: Drop wrong module alias

drivers/nvmem/layouts/onie-tlv.c | 15 +--------------
drivers/nvmem/layouts/sl28vpd.c | 14 +-------------
include/linux/nvmem-provider.h | 5 +++++
3 files changed, 7 insertions(+), 27 deletions(-)

--
2.34.1



2023-03-15 10:03:23

by Miquel Raynal

[permalink] [raw]
Subject: [PATCH 1/4] nvmem: Add macro to register nvmem layout drivers

Provide a module_nvmem_layout_driver() macro at the end of the
nvmem-provider.h header to reduce the boilerplate when registering nvmem
layout drivers.

Suggested-by: Srinivas Kandagatla <[email protected]>
Signed-off-by: Miquel Raynal <[email protected]>
---
include/linux/nvmem-provider.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 0cf9f9490514..a1c668018894 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -240,4 +240,9 @@ nvmem_layout_get_match_data(struct nvmem_device *nvmem,
}

#endif /* CONFIG_NVMEM */
+
+#define module_nvmem_layout_driver(__layout_driver) \
+ module_driver(__layout_driver, nvmem_layout_register, \
+ nvmem_layout_unregister)
+
#endif /* ifndef _LINUX_NVMEM_PROVIDER_H */
--
2.34.1


2023-03-15 10:03:27

by Miquel Raynal

[permalink] [raw]
Subject: [PATCH 2/4] nvmem: layouts: sl28vpd: Use module_nvmem_layout_driver()

Stop open-coding the module init/exit functions. Use the
module_nvmem_layout_driver() instead.

Signed-off-by: Miquel Raynal <[email protected]>
---
drivers/nvmem/layouts/sl28vpd.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c
index 9370e41bad73..9cc1715c2fd5 100644
--- a/drivers/nvmem/layouts/sl28vpd.c
+++ b/drivers/nvmem/layouts/sl28vpd.c
@@ -146,19 +146,7 @@ struct nvmem_layout sl28vpd_layout = {
.of_match_table = sl28vpd_of_match_table,
.add_cells = sl28vpd_add_cells,
};
-
-static int __init sl28vpd_init(void)
-{
- return nvmem_layout_register(&sl28vpd_layout);
-}
-
-static void __exit sl28vpd_exit(void)
-{
- nvmem_layout_unregister(&sl28vpd_layout);
-}
-
-module_init(sl28vpd_init);
-module_exit(sl28vpd_exit);
+module_nvmem_layout_driver(sl28vpd_layout);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Michael Walle <[email protected]>");
--
2.34.1


2023-03-15 10:03:39

by Miquel Raynal

[permalink] [raw]
Subject: [PATCH 3/4] nvmem: layouts: onie-tlv: Use module_nvmem_layout_driver()

Stop open-coding the module init/exit functions. Use the
module_nvmem_layout_driver() instead.

Signed-off-by: Miquel Raynal <[email protected]>
---
drivers/nvmem/layouts/onie-tlv.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c
index d45b7301a69d..661093de33b4 100644
--- a/drivers/nvmem/layouts/onie-tlv.c
+++ b/drivers/nvmem/layouts/onie-tlv.c
@@ -237,19 +237,7 @@ static struct nvmem_layout onie_tlv_layout = {
.of_match_table = onie_tlv_of_match_table,
.add_cells = onie_tlv_parse_table,
};
-
-static int __init onie_tlv_init(void)
-{
- return nvmem_layout_register(&onie_tlv_layout);
-}
-
-static void __exit onie_tlv_exit(void)
-{
- nvmem_layout_unregister(&onie_tlv_layout);
-}
-
-module_init(onie_tlv_init);
-module_exit(onie_tlv_exit);
+module_nvmem_layout_driver(onie_tlv_layout);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Miquel Raynal <[email protected]>");
--
2.34.1


2023-03-15 10:03:42

by Miquel Raynal

[permalink] [raw]
Subject: [PATCH 4/4] nvmem: layouts: onie-tlv: Drop wrong module alias

The MODULE_ALIAS macro is misused here as it carries the
description. There is currently no relevant alias to provide so let's
just drop it.

Signed-off-by: Miquel Raynal <[email protected]>
---
drivers/nvmem/layouts/onie-tlv.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c
index 661093de33b4..59fc87ccfcff 100644
--- a/drivers/nvmem/layouts/onie-tlv.c
+++ b/drivers/nvmem/layouts/onie-tlv.c
@@ -242,4 +242,3 @@ module_nvmem_layout_driver(onie_tlv_layout);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Miquel Raynal <[email protected]>");
MODULE_DESCRIPTION("NVMEM layout driver for Onie TLV table parsing");
-MODULE_ALIAS("NVMEM layout driver for Onie TLV table parsing");
--
2.34.1


2023-03-16 16:39:32

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH 1/4] nvmem: Add macro to register nvmem layout drivers

Hi Rafał,

[email protected] wrote on Thu, 16 Mar 2023 17:28:04 +0100:

> On 2023-03-15 11:00, Miquel Raynal wrote:
> > Provide a module_nvmem_layout_driver() macro at the end of the
> > nvmem-provider.h header to reduce the boilerplate when registering > nvmem
> > layout drivers.
>
> I think you should take care of including <linux/device/driver.h>
> instead of depending on module_nvmem_layout_driver() *callers* to do
> that.

Right, I'll do that.

>
> That would help avoiding errors like:
>
> In file included from drivers/nvmem/layouts/fixed.c:5:
> ./include/linux/nvmem-provider.h:252:2: warning: data definition has no type or storage class
> 252 | module_driver(__layout_driver, nvmem_layout_register, \
> | ^~~~~~~~~~~~~
> ./include/linux/nvmem-provider.h:252:2: error: type defaults to 'int' in declaration of 'module_driver' [-Werror=implicit-int]
> 252 | module_driver(__layout_driver, nvmem_layout_register, \
> | ^~~~~~~~~~~~~
>
>
> > Suggested-by: Srinivas Kandagatla <[email protected]>
> > Signed-off-by: Miquel Raynal <[email protected]>
> > ---
> > include/linux/nvmem-provider.h | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/include/linux/nvmem-provider.h > b/include/linux/nvmem-provider.h
> > index 0cf9f9490514..a1c668018894 100644
> > --- a/include/linux/nvmem-provider.h
> > +++ b/include/linux/nvmem-provider.h
> > @@ -240,4 +240,9 @@ nvmem_layout_get_match_data(struct nvmem_device > *nvmem,
> > }
> >
> > #endif /* CONFIG_NVMEM */
> > +
> > +#define module_nvmem_layout_driver(__layout_driver) \
> > + module_driver(__layout_driver, nvmem_layout_register, \
> > + nvmem_layout_unregister)
> > +
> > #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */


Thanks,
Miquèl

2023-03-16 16:51:48

by Rafał Miłecki

[permalink] [raw]
Subject: Re: [PATCH 1/4] nvmem: Add macro to register nvmem layout drivers

On 2023-03-15 11:00, Miquel Raynal wrote:
> Provide a module_nvmem_layout_driver() macro at the end of the
> nvmem-provider.h header to reduce the boilerplate when registering
> nvmem
> layout drivers.

I think you should take care of including <linux/device/driver.h>
instead of depending on module_nvmem_layout_driver() *callers* to do
that.

That would help avoiding errors like:

In file included from drivers/nvmem/layouts/fixed.c:5:
./include/linux/nvmem-provider.h:252:2: warning: data definition has no
type or storage class
252 | module_driver(__layout_driver, nvmem_layout_register, \
| ^~~~~~~~~~~~~
./include/linux/nvmem-provider.h:252:2: error: type defaults to 'int' in
declaration of 'module_driver' [-Werror=implicit-int]
252 | module_driver(__layout_driver, nvmem_layout_register, \
| ^~~~~~~~~~~~~


> Suggested-by: Srinivas Kandagatla <[email protected]>
> Signed-off-by: Miquel Raynal <[email protected]>
> ---
> include/linux/nvmem-provider.h | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/include/linux/nvmem-provider.h
> b/include/linux/nvmem-provider.h
> index 0cf9f9490514..a1c668018894 100644
> --- a/include/linux/nvmem-provider.h
> +++ b/include/linux/nvmem-provider.h
> @@ -240,4 +240,9 @@ nvmem_layout_get_match_data(struct nvmem_device
> *nvmem,
> }
>
> #endif /* CONFIG_NVMEM */
> +
> +#define module_nvmem_layout_driver(__layout_driver) \
> + module_driver(__layout_driver, nvmem_layout_register, \
> + nvmem_layout_unregister)
> +
> #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */