Skip to content

Commit

Permalink
of: module: remove strlen() call in of_modalias()
Browse files Browse the repository at this point in the history
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 <s.shtylyov@omp.ru>
Link: https://lore.kernel.org/r/471418be-5d2f-4d14-bd9e-9e8f0526241f@omp.ru
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
  • Loading branch information
Sergey Shtylyov authored and Rob Herring (Arm) committed Oct 16, 2024
1 parent 00c9a45 commit 2e03091
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions drivers/of/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
str += csize;

of_property_for_each_string(np, "compatible", p, compat) {
csize = strlen(compat) + 1;
csize = snprintf(str, len, "C%s", compat);
tsize += csize;
if (csize >= len)
continue;

csize = snprintf(str, len, "C%s", compat);
for (c = str; c; ) {
c = strchr(c, ' ');
if (c)
Expand Down

0 comments on commit 2e03091

Please sign in to comment.