Thread (56 messages) 56 messages, 5 authors, 2025-02-27

Re: [PATCH v4 14/14] of: Improve __of_add_property_sysfs() readability

From: Krzysztof Kozlowski <krzk@kernel.org>
Date: 2025-01-11 09:17:28
Also in: lkml

On Sat, Jan 11, 2025 at 07:48:48AM +0800, Zijun Hu wrote:
On 2025/1/11 04:41, Rob Herring wrote:
quoted
On Thu, Jan 09, 2025 at 09:27:05PM +0800, Zijun Hu wrote:
quoted
From: Zijun Hu <redacted>

__of_add_property_sysfs() hard codes string "security-" length as 9, but
that is not obvious for readers.

Improve its readability by using strlen().
Does the compiler optimize the strlen call away? Maybe, maybe not. If 
not, that's N calls to strlen() where N is the number of properties in 
your DT. That's in the 1000s easily.

Do you really want to go test enough compiler versions we support to 
feel confident this is optimized away. I don't.
i understand your concern about performance.
perhaps, such impact about performance may be ignored for linux OS.

what about below solution ?

const char security_prefix[] = "security-";
use 'sizeof(security_prefix) - 1' for the length of string.
Code is still not equivalent - just de-assemble it and you will see
some overhead.

Maybe just introduce builtin_strlen() to string.h and use such? It would
be the pretty obvious code.


Best regards,
Krzysztof
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help