mtd: fix build with GCC 14
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 828-v6.4-0002-of-Update-of_device_get_modalias.patch
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()
5
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.
9
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.
14
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>
20 ---
21 drivers/of/device.c | 29 +++++++++++++++++------------
22 1 file changed, 17 insertions(+), 12 deletions(-)
23
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
27 }
28 EXPORT_SYMBOL(of_device_get_match_data);
29
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)
32 {
33 const char *compat;
34 char *c;
35 @@ -249,19 +249,16 @@ static ssize_t of_device_get_modalias(st
36 ssize_t csize;
37 ssize_t tsize;
38
39 - if ((!dev) || (!dev->of_node) || dev->of_node_reused)
40 - return -ENODEV;
41 -
42 /* Name & Type */
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));
48 tsize = csize;
49 len -= csize;
50 if (str)
51 str += csize;
52
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;
56 tsize += csize;
57 if (csize > len)
58 @@ -286,7 +283,10 @@ int of_device_request_module(struct devi
59 ssize_t size;
60 int ret;
61
62 - size = of_device_get_modalias(dev, NULL, 0);
63 + if (!dev || !dev->of_node)
64 + return -ENODEV;
65 +
66 + size = of_modalias(dev->of_node, NULL, 0);
67 if (size < 0)
68 return size;
69
70 @@ -297,7 +297,7 @@ int of_device_request_module(struct devi
71 if (!str)
72 return -ENOMEM;
73
74 - of_device_get_modalias(dev, str, size);
75 + of_modalias(dev->of_node, str, size);
76 str[size - 1] = '\0';
77 ret = request_module(str);
78 kfree(str);
79 @@ -314,7 +314,12 @@ EXPORT_SYMBOL_GPL(of_device_request_modu
80 */
81 ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len)
82 {
83 - ssize_t sl = of_device_get_modalias(dev, str, len - 2);
84 + ssize_t sl;
85 +
86 + if (!dev || !dev->of_node || dev->of_node_reused)
87 + return -ENODEV;
88 +
89 + sl = of_modalias(dev->of_node, str, len - 2);
90 if (sl < 0)
91 return sl;
92 if (sl > len - 2)
93 @@ -379,8 +384,8 @@ int of_device_uevent_modalias(struct dev
94 if (add_uevent_var(env, "MODALIAS="))
95 return -ENOMEM;
96
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);
101 if (sl < 0)
102 return sl;
103 if (sl >= (sizeof(env->buf) - env->buflen))