Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: Update of_device_get_modalias()

This function only needs a "struct device_node" to work, but for
convenience the author (and only user) of this helper did use a "struct
device" and put it in device.c.

Let's convert this helper to take a "struct device node" instead. This
change asks for two additional changes: renaming it "of_modalias()"
to fit the current naming, and moving it outside of device.c which will
be done in a follow-up commit.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230404172148.82422-8-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Miquel Raynal and committed by
Greg Kroah-Hartman
5c3d15e1 2187af84

+17 -12
+17 -12
drivers/of/device.c
··· 248 248 } 249 249 EXPORT_SYMBOL(of_device_get_match_data); 250 250 251 - static ssize_t of_device_get_modalias(const struct device *dev, char *str, ssize_t len) 251 + static ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len) 252 252 { 253 253 const char *compat; 254 254 char *c; ··· 256 256 ssize_t csize; 257 257 ssize_t tsize; 258 258 259 - if ((!dev) || (!dev->of_node) || dev->of_node_reused) 260 - return -ENODEV; 261 - 262 259 /* Name & Type */ 263 260 /* %p eats all alphanum characters, so %c must be used here */ 264 - csize = snprintf(str, len, "of:N%pOFn%c%s", dev->of_node, 'T', 265 - of_node_get_device_type(dev->of_node)); 261 + csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T', 262 + of_node_get_device_type(np)); 266 263 tsize = csize; 267 264 len -= csize; 268 265 if (str) 269 266 str += csize; 270 267 271 - of_property_for_each_string(dev->of_node, "compatible", p, compat) { 268 + of_property_for_each_string(np, "compatible", p, compat) { 272 269 csize = strlen(compat) + 1; 273 270 tsize += csize; 274 271 if (csize > len) ··· 290 293 ssize_t size; 291 294 int ret; 292 295 293 - size = of_device_get_modalias(dev, NULL, 0); 296 + if (!dev || !dev->of_node) 297 + return -ENODEV; 298 + 299 + size = of_modalias(dev->of_node, NULL, 0); 294 300 if (size < 0) 295 301 return size; 296 302 ··· 304 304 if (!str) 305 305 return -ENOMEM; 306 306 307 - of_device_get_modalias(dev, str, size); 307 + of_modalias(dev->of_node, str, size); 308 308 str[size - 1] = '\0'; 309 309 ret = request_module(str); 310 310 kfree(str); ··· 321 321 */ 322 322 ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len) 323 323 { 324 - ssize_t sl = of_device_get_modalias(dev, str, len - 2); 324 + ssize_t sl; 325 + 326 + if (!dev || !dev->of_node || dev->of_node_reused) 327 + return -ENODEV; 328 + 329 + sl = of_modalias(dev->of_node, str, len - 2); 325 330 if (sl < 0) 326 331 return sl; 327 332 if (sl > len - 2) ··· 391 386 if (add_uevent_var(env, "MODALIAS=")) 392 387 return -ENOMEM; 393 388 394 - sl = of_device_get_modalias(dev, &env->buf[env->buflen-1], 395 - sizeof(env->buf) - env->buflen); 389 + sl = of_modalias(dev->of_node, &env->buf[env->buflen-1], 390 + sizeof(env->buf) - env->buflen); 396 391 if (sl < 0) 397 392 return sl; 398 393 if (sl >= (sizeof(env->buf) - env->buflen))