Re: [PATCH] mlxsw: spectrum_acl_bloom_filter: use struct_size() in kzalloc()

From: Gustavo A. R. Silva
Date: Mon Dec 24 2018 - 02:47:13 EST

On 12/24/18 1:38 AM, Ido Schimmel wrote:
On Sun, Dec 23, 2018 at 11:27:41PM -0600, Gustavo A. R. Silva wrote:
One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
int stuff;
void *entry[];

instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@xxxxxxxxxxxxxx>

Reviewed-by: Ido Schimmel <idosch@xxxxxxxxxxxx>

But net-next is closed ( and
this isn't a bug fix. Can you please re-submit when net-next opens
again? Alternatively, I can apply the patch to my mlxsw queue and submit
in your stead. Let me know what you prefer.

Oh yeah. I forgot net close net-next during the merge window. I'll
re-submit it in two weeks then. I'll add your Reviewed-by.

Happy holiday.