[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20241227111328.540ced11@kernel.org>
Date: Fri, 27 Dec 2024 11:13:28 -0800
From: Jakub Kicinski <kuba@...nel.org>
To: Liang Jie <buaajxlj@....com>
Cc: edumazet@...gle.com, davem@...emloft.net, pabeni@...hat.com,
horms@...nel.org, anthony.l.nguyen@...el.com, andrew+netdev@...n.ch,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org, Liang Jie
<liangjie@...iang.com>
Subject: Re: [PATCH net v3] net: Refine key_len calculations in
rhashtable_params
On Fri, 20 Dec 2024 16:24:36 +0800 Liang Jie wrote:
> From: Liang Jie <liangjie@...iang.com>
>
> This patch improves the calculation of key_len in the rhashtable_params
> structures across the net driver modules by replacing hardcoded sizes
> and previous calculations with appropriate macros like sizeof_field()
> and offsetofend().
>
> Previously, key_len was set using hardcoded sizes like sizeof(u32) or
> sizeof(unsigned long), or using offsetof() calculations. This patch
> replaces these with sizeof_field() and correct use of offsetofend(),
> making the code more robust, maintainable, and improving readability.
>
> Using sizeof_field() and offsetofend() provides several advantages:
> - They explicitly specify the size of the field or the end offset of a
> member being used as a key.
> - They ensure that the key_len is accurate even if the structs change in
> the future.
> - They improve code readability by clearly indicating which fields are used
> and how their sizes are determined, making the code easier to understand
> and maintain.
>
> For example, instead of:
> .key_len = sizeof(u32),
> we now use:
> .key_len = sizeof_field(struct mae_mport_desc, mport_id),
>
> And instead of:
> .key_len = offsetof(struct efx_tc_encap_match, linkage),
> we now use:
> .key_len = offsetofend(struct efx_tc_encap_match, ip_tos_mask),
>
> These changes eliminate the risk in certain scenarios of including
> unintended padding or extra data in the key, ensuring the rhashtable
> functions correctly.
IMHO the change is not worth the churn. Does any upstream code checker
/ tool prevent from new instances of this pattern occurring?
--
pw-bot: reject
Powered by blists - more mailing lists