1 // SPDX-License-Identifier: GPL-2.0
3 * Linux kernel module helpers.
7 #include <linux/module.h>
8 #include <linux/slab.h>
9 #include <linux/string.h>
11 ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
20 * Prevent a kernel oops in vsnprintf() -- it only allows passing a
21 * NULL ptr when the length is also 0. Also filter out the negative
24 if ((len > 0 && !str) || len < 0)
28 /* %p eats all alphanum characters, so %c must be used here */
29 csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
30 of_node_get_device_type(np));
36 of_property_for_each_string(np, "compatible", p, compat) {
37 csize = strlen(compat) + 1;
42 csize = snprintf(str, len, "C%s", compat);
55 int of_request_module(const struct device_node *np)
64 size = of_modalias(np, NULL, 0);
68 /* Reserve an additional byte for the trailing '\0' */
71 str = kmalloc(size, GFP_KERNEL);
75 of_modalias(np, str, size);
77 ret = request_module(str);
82 EXPORT_SYMBOL_GPL(of_request_module);