linux_dsm_epyc7002/drivers/net/ethernet/intel/i40e
Gustavo A. R. Silva fae6cad17c i40e/i40e_virtchnl_pf: Use struct_size() in kzalloc()
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 virtchnl_iwarp_qvlist_info {
	...
        struct virtchnl_iwarp_qv_info qv_info[1];
};

size = sizeof(struct virtchnl_iwarp_qvlist_info) + (sizeof(struct virtchnl_iwarp_qv_info) * count;
instance = kzalloc(size, GFP_KERNEL);

and

struct virtchnl_vf_resource {
	...
        struct virtchnl_vsi_resource vsi_res[1];
};

size = sizeof(struct virtchnl_vf_resource) + sizeof(struct virtchnl_vsi_resource) * count;
instance = kzalloc(size, 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, qv_info, count), GFP_KERNEL);

and

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

Notice that, in the first case above, variable size is not necessary, hence it
is removed.

This code was detected with the help of Coccinelle.

Signed-off-by: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
2019-06-26 09:18:54 -07:00
..
i40e_adminq_cmd.h i40e: Add support for X710 B/P & SFP+ cards 2019-05-04 17:24:48 -07:00
i40e_adminq.c i40e: Improve AQ log granularity 2019-06-14 12:59:16 -07:00
i40e_adminq.h
i40e_alloc.h
i40e_client.c i40e: Use struct_size() in kzalloc() 2019-05-04 17:34:43 -07:00
i40e_client.h
i40e_common.c i40e: Fix for missing "link modes" info in ethtool 2019-06-26 09:18:54 -07:00
i40e_dcb_nl.c
i40e_dcb.c i40e: Update i40e_init_dcb to return correct error 2019-04-16 15:10:47 -07:00
i40e_dcb.h i40e: Update i40e_init_dcb to return correct error 2019-04-16 15:10:47 -07:00
i40e_ddp.c i40e: Implement DDP support in i40e driver 2019-04-16 15:10:21 -07:00
i40e_debugfs.c i40e: Fix descriptor count manipulation 2019-06-26 09:18:54 -07:00
i40e_devids.h i40e: Add support for X710 B/P & SFP+ cards 2019-05-04 17:24:48 -07:00
i40e_diag.c
i40e_diag.h
i40e_ethtool.c i40e: Fix descriptor count manipulation 2019-06-26 09:18:54 -07:00
i40e_hmc.c
i40e_hmc.h
i40e_lan_hmc.c
i40e_lan_hmc.h
i40e_main.c i40e: update copyright string 2019-06-26 09:18:54 -07:00
i40e_nvm.c i40e: Revert ShadowRAM checksum calculation change 2019-05-04 17:30:58 -07:00
i40e_osdep.h
i40e_prototype.h i40e: fix 'Unknown bps' in dmesg for 2.5Gb/5Gb speeds 2019-06-26 09:18:54 -07:00
i40e_ptp.c i40e: fix incorrect function documentation comment 2019-06-26 09:18:54 -07:00
i40e_register.h
i40e_status.h
i40e_trace.h
i40e_txrx_common.h i40e: DRY rx_ptype handling code 2018-12-12 15:46:02 -08:00
i40e_txrx.c i40e: Use signed variable 2019-06-14 12:59:16 -07:00
i40e_txrx.h
i40e_type.h i40e: Add support for X710 B/P & SFP+ cards 2019-05-04 17:24:48 -07:00
i40e_virtchnl_pf.c i40e/i40e_virtchnl_pf: Use struct_size() in kzalloc() 2019-06-26 09:18:54 -07:00
i40e_virtchnl_pf.h i40e: missing input validation on VF message handling by the PF 2019-05-04 17:28:04 -07:00
i40e_xsk.c i40e: mark expected switch fall-through 2019-06-14 13:03:45 -07:00
i40e_xsk.h net: bpf: remove XDP_QUERY_XSK_UMEM enumerator 2019-02-15 15:14:22 +01:00
i40e.h i40e: Fix descriptor count manipulation 2019-06-26 09:18:54 -07:00
Makefile i40e: Implement DDP support in i40e driver 2019-04-16 15:10:21 -07:00