Skip to content

Commit 2e03091

Browse files
Sergey Shtylyovrobherring
authored andcommitted
of: module: remove strlen() call in of_modalias()
In of_modalias(), there's no dire need to call strlen() (and then add 1 to its result to account for the 'C' char preceding the compat string). Replace that strlen() with snprintf() (currently below it) -- this way, we always try to print the compat string but then only advance the str and len parameters iff the compat string fit into the remaining buffer space... Signed-off-by: Sergey Shtylyov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring (Arm) <[email protected]>
1 parent 00c9a45 commit 2e03091

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

drivers/of/module.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
3535
str += csize;
3636

3737
of_property_for_each_string(np, "compatible", p, compat) {
38-
csize = strlen(compat) + 1;
38+
csize = snprintf(str, len, "C%s", compat);
3939
tsize += csize;
4040
if (csize >= len)
4141
continue;
42-
43-
csize = snprintf(str, len, "C%s", compat);
4442
for (c = str; c; ) {
4543
c = strchr(c, ' ');
4644
if (c)

0 commit comments

Comments
 (0)