1 From 5c3d15e127ebfc0754cd18def7124633b6d46672 Mon Sep 17 00:00:00 2001
2 From: Miquel Raynal <miquel.raynal@bootlin.com>
3 Date: Tue, 4 Apr 2023 18:21:15 +0100
4 Subject: [PATCH] of: Update of_device_get_modalias()
6 This function only needs a "struct device_node" to work, but for
7 convenience the author (and only user) of this helper did use a "struct
8 device" and put it in device.c.
10 Let's convert this helper to take a "struct device node" instead. This
11 change asks for two additional changes: renaming it "of_modalias()"
12 to fit the current naming, and moving it outside of device.c which will
13 be done in a follow-up commit.
15 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
16 Reviewed-by: Rob Herring <robh@kernel.org>
17 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
18 Link: https://lore.kernel.org/r/20230404172148.82422-8-srinivas.kandagatla@linaro.org
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21 drivers/of/device.c | 29 +++++++++++++++++------------
22 1 file changed, 17 insertions(+), 12 deletions(-)
24 --- a/drivers/of/device.c
25 +++ b/drivers/of/device.c
26 @@ -241,7 +241,7 @@ const void *of_device_get_match_data(con
28 EXPORT_SYMBOL(of_device_get_match_data);
30 -static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
31 +static ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
35 @@ -249,19 +249,16 @@ static ssize_t of_device_get_modalias(st
39 - if ((!dev) || (!dev->of_node) || dev->of_node_reused)
43 /* %p eats all alphanum characters, so %c must be used here */
44 - csize = snprintf(str, len, "of:N%pOFn%c%s", dev->of_node, 'T',
45 - of_node_get_device_type(dev->of_node));
46 + csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
47 + of_node_get_device_type(np));
53 - of_property_for_each_string(dev->of_node, "compatible", p, compat) {
54 + of_property_for_each_string(np, "compatible", p, compat) {
55 csize = strlen(compat) + 1;
58 @@ -286,7 +283,10 @@ int of_device_request_module(struct devi
62 - size = of_device_get_modalias(dev, NULL, 0);
63 + if (!dev || !dev->of_node)
66 + size = of_modalias(dev->of_node, NULL, 0);
70 @@ -297,7 +297,7 @@ int of_device_request_module(struct devi
74 - of_device_get_modalias(dev, str, size);
75 + of_modalias(dev->of_node, str, size);
77 ret = request_module(str);
79 @@ -314,7 +314,12 @@ EXPORT_SYMBOL_GPL(of_device_request_modu
81 ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len)
83 - ssize_t sl = of_device_get_modalias(dev, str, len - 2);
86 + if (!dev || !dev->of_node || dev->of_node_reused)
89 + sl = of_modalias(dev->of_node, str, len - 2);
93 @@ -379,8 +384,8 @@ int of_device_uevent_modalias(struct dev
94 if (add_uevent_var(env, "MODALIAS="))
97 - sl = of_device_get_modalias(dev, &env->buf[env->buflen-1],
98 - sizeof(env->buf) - env->buflen);
99 + sl = of_modalias(dev->of_node, &env->buf[env->buflen-1],
100 + sizeof(env->buf) - env->buflen);
103 if (sl >= (sizeof(env->buf) - env->buflen))