Skip to content

Commit

Permalink
idpf: Slightly simplify memory management in idpf_add_del_mac_filters()
Browse files Browse the repository at this point in the history
In idpf_add_del_mac_filters(), filters are chunked up into multiple
messages to avoid sending a control queue message buffer that is too large.

Each chunk has up to IDPF_NUM_FILTERS_PER_MSG entries. So except for the
last iteration which can be smaller, space for exactly
IDPF_NUM_FILTERS_PER_MSG entries is allocated.

There is no need to free and reallocate a smaller array just for the last
iteration.

This slightly simplifies the code and avoid an (unlikely) memory allocation
failure.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: NipaLocal <nipa@local>
  • Loading branch information
tititiou36 authored and NipaLocal committed Aug 25, 2024
1 parent c28c43c commit 6d6f70a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3669,12 +3669,15 @@ int idpf_add_del_mac_filters(struct idpf_vport *vport,
entries_size = sizeof(struct virtchnl2_mac_addr) * num_entries;
buf_size = struct_size(ma_list, mac_addr_list, num_entries);

if (!ma_list || num_entries != IDPF_NUM_FILTERS_PER_MSG) {
kfree(ma_list);
if (!ma_list) {
ma_list = kzalloc(buf_size, GFP_ATOMIC);
if (!ma_list)
return -ENOMEM;
} else {
/* ma_list was allocated in the first iteration
* so IDPF_NUM_FILTERS_PER_MSG entries are
* available
*/
memset(ma_list, 0, buf_size);
}

Expand Down

0 comments on commit 6d6f70a

Please sign in to comment.