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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2025/1/11 04:41, Rob Herring wrote:
>> From: Zijun Hu <quic_zijuhu@xxxxxxxxxxx>
>>
>> __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.

what about below solution ?

 int __of_add_property_sysfs(struct device_node *np, struct property *pp)
 {
+#define SECURITY_PREFIX "security-"
        int rc;

        /* Important: Don't leak passwords */
-       bool secure = strncmp(pp->name, "security-", 9) == 0;
+       bool secure = strncmp(pp->name, SECURITY_PREFIX,
sizeof(SECURITY_PREFIX) - 1) == 0;

        if (!IS_ENABLED(CONFIG_SYSFS))
                return 0;







[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux