[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHTyZGwAit_FSHJDSPn4QpCfim321aB478YDuC=uUhvBgPfKGA@mail.gmail.com>
Date: Tue, 17 Dec 2024 08:33:57 +0100
From: ericnetdev dumazet <erdnetdev@...il.com>
To: Liang Jie <buaajxlj@....com>
Cc: kuba@...nel.org, davem@...emloft.net, pabeni@...hat.com, horms@...nel.org,
anthony.l.nguyen@...el.com, andrew+netdev@...n.ch, edumazet@...gle.com,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
Liang Jie <liangjie@...iang.com>
Subject: Re: [PATCH] net: Refine key_len calculations in rhashtable_params
Le mar. 17 déc. 2024 à 08:16, Liang Jie <buaajxlj@....com> a écrit :
>
> 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 of including unintended padding or extra
> data in the key, ensuring the rhashtable functions correctly.
I do not see how this patch can eliminate padding.
If keys include holes or padding, something still needs to clear the
holes/padding in objects and lookup keys.
struct key {
u8 first_component;
u32 second_component;
};
Powered by blists - more mailing lists