06bc24ca6e37533e134d8720bd106d8dae71686c
[openwrt/staging/blocktrron.git] /
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
5
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.
9
10 The next step will be to convert users of of_device_request_module() to
11 use the new helper.
12
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>
18 ---
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(-)
23
24 --- a/drivers/of/device.c
25 +++ b/drivers/of/device.c
26 @@ -8,7 +8,6 @@
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 @@ -242,30 +241,10 @@ EXPORT_SYMBOL(of_device_get_match_data);
35
36 int of_device_request_module(struct device *dev)
37 {
38 - char *str;
39 - ssize_t size;
40 - int ret;
41 -
42 - if (!dev || !dev->of_node)
43 + if (!dev)
44 return -ENODEV;
45
46 - size = of_modalias(dev->of_node, NULL, 0);
47 - if (size < 0)
48 - return size;
49 -
50 - /* Reserve an additional byte for the trailing '\0' */
51 - size++;
52 -
53 - str = kmalloc(size, GFP_KERNEL);
54 - if (!str)
55 - return -ENOMEM;
56 -
57 - of_modalias(dev->of_node, str, size);
58 - str[size - 1] = '\0';
59 - ret = request_module(str);
60 - kfree(str);
61 -
62 - return ret;
63 + return of_request_module(dev->of_node);
64 }
65 EXPORT_SYMBOL_GPL(of_device_request_module);
66
67 --- a/drivers/of/module.c
68 +++ b/drivers/of/module.c
69 @@ -4,6 +4,7 @@
70 */
71
72 #include <linux/of.h>
73 +#include <linux/module.h>
74 #include <linux/slab.h>
75 #include <linux/string.h>
76
77 @@ -42,3 +43,32 @@ ssize_t of_modalias(const struct device_
78
79 return tsize;
80 }
81 +
82 +int of_request_module(const struct device_node *np)
83 +{
84 + char *str;
85 + ssize_t size;
86 + int ret;
87 +
88 + if (!np)
89 + return -ENODEV;
90 +
91 + size = of_modalias(np, NULL, 0);
92 + if (size < 0)
93 + return size;
94 +
95 + /* Reserve an additional byte for the trailing '\0' */
96 + size++;
97 +
98 + str = kmalloc(size, GFP_KERNEL);
99 + if (!str)
100 + return -ENOMEM;
101 +
102 + of_modalias(np, str, size);
103 + str[size - 1] = '\0';
104 + ret = request_module(str);
105 + kfree(str);
106 +
107 + return ret;
108 +}
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
113
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);
117
118 /* phandle iterator functions */
119 extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
120 @@ -893,6 +894,11 @@ static inline ssize_t of_modalias(const
121 {
122 return -ENODEV;
123 }
124 +
125 +static inline int of_request_module(const struct device_node *np)
126 +{
127 + return -ENODEV;
128 +}
129
130 static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
131 const struct device_node *np,