Re: [PATCH net-next] net: rfkill: Replace strcpy with memcpy to improve rfkill_alloc

From: Thorsten Blum

Date: Fri Feb 20 2026 - 12:00:18 EST


On 8. Jan 2026, at 13:29, Johannes Berg wrote:
> On Mon, 2025-12-15 at 13:20 +0100, Thorsten Blum wrote:
>> strcpy() is deprecated [1] and uses an additional strlen() internally;
>> use memcpy() directly since we already know the length of 'name' and
>> that it is guaranteed to be NUL-terminated.
>>
>> Use struct_size(), which provides additional compile-time checks for
>> structures with flexible array members (e.g., __must_be_array()), to
>> determine the allocation size for a new 'struct rfkill'.
>
> TBH, I don't really see that this is a real _improvement_. I guess I'll
> take it if you sell it as "let's not use deprecated strcpy" instead,
> although even the documentation says "no new uses"...

Yes, this is primarily a refactoring to avoid deprecated strcpy(), and
to harden the code by using struct_size().

Thanks,
Thorsten