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

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 <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>

authored by

Sergey Shtylyov and committed by
Rob Herring (Arm)
2e030910 00c9a452

+1 -3
+1 -3
drivers/of/module.c
··· 35 35 str += csize; 36 36 37 37 of_property_for_each_string(np, "compatible", p, compat) { 38 - csize = strlen(compat) + 1; 38 + csize = snprintf(str, len, "C%s", compat); 39 39 tsize += csize; 40 40 if (csize >= len) 41 41 continue; 42 - 43 - csize = snprintf(str, len, "C%s", compat); 44 42 for (c = str; c; ) { 45 43 c = strchr(c, ' '); 46 44 if (c)