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
));
33 csize
= len
> 0 ? len
- 1 : 0;
37 of_property_for_each_string(np
, "compatible", p
, compat
) {
38 csize
= snprintf(str
, len
, "C%s", compat
);
54 int of_request_module(const struct device_node
*np
)
63 size
= of_modalias(np
, NULL
, 0);
67 /* Reserve an additional byte for the trailing '\0' */
70 str
= kmalloc(size
, GFP_KERNEL
);
74 of_modalias(np
, str
, size
);
76 ret
= request_module(str
);
81 EXPORT_SYMBOL_GPL(of_request_module
);