c15b4b2265e73adb8313a6e2bb89329a8307f945
[openwrt/staging/stintel.git] /
1 From 6d0ca4a2a7e25f9ad07c1f335f20b4d9e048cdd5 Mon Sep 17 00:00:00 2001
2 From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
3 Date: Tue, 30 Apr 2024 09:49:11 +0100
4 Subject: [PATCH] nvmem: layouts: store owner from modules with
5 nvmem_layout_driver_register()
6
7 Modules registering driver with nvmem_layout_driver_register() might
8 forget to set .owner field. The field is used by some of other kernel
9 parts for reference counting (try_module_get()), so it is expected that
10 drivers will set it.
11
12 Solve the problem by moving this task away from the drivers to the core
13 code, just like we did for platform_driver in
14 commit 9447057eaff8 ("platform_device: use a macro instead of
15 platform_driver_register").
16
17 Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
18 Reviewed-by: Michael Walle <mwalle@kernel.org>
19 Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
20 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
21 Link: https://lore.kernel.org/r/20240430084921.33387-2-srinivas.kandagatla@linaro.org
22 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23 ---
24 drivers/nvmem/layouts.c | 6 ++++--
25 include/linux/nvmem-provider.h | 5 ++++-
26 2 files changed, 8 insertions(+), 3 deletions(-)
27
28 --- a/drivers/nvmem/layouts.c
29 +++ b/drivers/nvmem/layouts.c
30 @@ -52,13 +52,15 @@ static struct bus_type nvmem_layout_bus_
31 .remove = nvmem_layout_bus_remove,
32 };
33
34 -int nvmem_layout_driver_register(struct nvmem_layout_driver *drv)
35 +int __nvmem_layout_driver_register(struct nvmem_layout_driver *drv,
36 + struct module *owner)
37 {
38 drv->driver.bus = &nvmem_layout_bus_type;
39 + drv->driver.owner = owner;
40
41 return driver_register(&drv->driver);
42 }
43 -EXPORT_SYMBOL_GPL(nvmem_layout_driver_register);
44 +EXPORT_SYMBOL_GPL(__nvmem_layout_driver_register);
45
46 void nvmem_layout_driver_unregister(struct nvmem_layout_driver *drv)
47 {
48 --- a/include/linux/nvmem-provider.h
49 +++ b/include/linux/nvmem-provider.h
50 @@ -199,7 +199,10 @@ int nvmem_add_one_cell(struct nvmem_devi
51 int nvmem_layout_register(struct nvmem_layout *layout);
52 void nvmem_layout_unregister(struct nvmem_layout *layout);
53
54 -int nvmem_layout_driver_register(struct nvmem_layout_driver *drv);
55 +#define nvmem_layout_driver_register(drv) \
56 + __nvmem_layout_driver_register(drv, THIS_MODULE)
57 +int __nvmem_layout_driver_register(struct nvmem_layout_driver *drv,
58 + struct module *owner);
59 void nvmem_layout_driver_unregister(struct nvmem_layout_driver *drv);
60 #define module_nvmem_layout_driver(__nvmem_layout_driver) \
61 module_driver(__nvmem_layout_driver, nvmem_layout_driver_register, \