1 From e6506f06d5e82765666902ccf9e9162f3e31d518 Mon Sep 17 00:00:00 2001
2 From: Miquel Raynal <miquel.raynal@bootlin.com>
3 Date: Tue, 4 Apr 2023 18:21:18 +0100
4 Subject: [PATCH] of: Move the request module helper logic to module.c
6 Depending on device.c for pure OF handling is considered
7 backwards. Let's extract the content of of_device_request_module() to
8 have the real logic under module.c.
10 The next step will be to convert users of of_device_request_module() to
13 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
14 Reviewed-by: Rob Herring <robh@kernel.org>
15 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
16 Link: https://lore.kernel.org/r/20230404172148.82422-11-srinivas.kandagatla@linaro.org
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19 drivers/of/device.c | 25 ++-----------------------
20 drivers/of/module.c | 30 ++++++++++++++++++++++++++++++
21 include/linux/of.h | 6 ++++++
22 3 files changed, 38 insertions(+), 23 deletions(-)
24 --- a/drivers/of/device.c
25 +++ b/drivers/of/device.c
27 #include <linux/dma-direct.h> /* for bus_dma_region */
28 #include <linux/dma-map-ops.h>
29 #include <linux/init.h>
30 -#include <linux/module.h>
31 #include <linux/mod_devicetable.h>
32 #include <linux/slab.h>
33 #include <linux/platform_device.h>
34 @@ -216,30 +215,10 @@ EXPORT_SYMBOL(of_device_get_match_data);
36 int of_device_request_module(struct device *dev)
42 - if (!dev || !dev->of_node)
46 - size = of_modalias(dev->of_node, NULL, 0);
50 - /* Reserve an additional byte for the trailing '\0' */
53 - str = kmalloc(size, GFP_KERNEL);
57 - of_modalias(dev->of_node, str, size);
58 - str[size - 1] = '\0';
59 - ret = request_module(str);
63 + return of_request_module(dev->of_node);
65 EXPORT_SYMBOL_GPL(of_device_request_module);
67 --- a/drivers/of/module.c
68 +++ b/drivers/of/module.c
73 +#include <linux/module.h>
74 #include <linux/slab.h>
75 #include <linux/string.h>
77 @@ -42,3 +43,32 @@ ssize_t of_modalias(const struct device_
82 +int of_request_module(const struct device_node *np)
91 + size = of_modalias(np, NULL, 0);
95 + /* Reserve an additional byte for the trailing '\0' */
98 + str = kmalloc(size, GFP_KERNEL);
102 + of_modalias(np, str, size);
103 + str[size - 1] = '\0';
104 + ret = request_module(str);
109 +EXPORT_SYMBOL_GPL(of_request_module);
110 --- a/include/linux/of.h
111 +++ b/include/linux/of.h
112 @@ -375,6 +375,7 @@ extern int of_count_phandle_with_args(co
114 /* module functions */
115 extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len);
116 +extern int of_request_module(const struct device_node *np);
118 /* phandle iterator functions */
119 extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
120 @@ -886,6 +887,11 @@ static inline ssize_t of_modalias(const
125 +static inline int of_request_module(const struct device_node *np)
130 static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
131 const struct device_node *np,