Subject: Re: [PATCH net-next v2 04/15] idpf: add core init and interrupt request

From: Simon Horman <[email-masked]>
Date: Tue, 11 Apr 2023 11:52:25 +0200

On Mon, Apr 10, 2023 at 06:13:43PM -0700, Pavan Kumar Linga wrote:

...

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c

...

> +/**
> + * idpf_recv_get_caps_msg - Receive virtchnl get capabilities message
> + * @adapter: Driver specific private structure
> + *
> + * Receive virtchnl get capabilities message. Returns 0 on success, negative on
> + * failure.
> + */
> +static int idpf_recv_get_caps_msg(struct idpf_adapter *adapter)
> +{
> +	return idpf_recv_mb_msg(adapter, VIRTCHNL2_OP_GET_CAPS, &adapter->caps,
> +				sizeof(struct virtchnl2_get_capabilities));
> +}
> +
> +/**
> + * idpf_send_alloc_vectors_msg - Send virtchnl alloc vectors message
> + * @adapter: Driver specific private structure
> + * @num_vectors: number of vectors to be allocated
> + *
> + * Returns 0 on success, negative on failure.
> + */
> +int idpf_send_alloc_vectors_msg(struct idpf_adapter *adapter, u16 num_vectors)
> +{
> +	struct virtchnl2_alloc_vectors *alloc_vec, *rcvd_vec;
> +	struct virtchnl2_alloc_vectors ac = { };
> +	u16 num_vchunks;
> +	int size, err;
> +
> +	ac.num_vectors = cpu_to_le16(num_vectors);
> +
> +	err = idpf_send_mb_msg(adapter, VIRTCHNL2_OP_ALLOC_VECTORS,
> +			       sizeof(ac), (u8 *)&ac);
> +	if (err)
> +		return err;
> +
> +	err = idpf_wait_for_event(adapter, NULL, IDPF_VC_ALLOC_VECTORS,
> +				  IDPF_VC_ALLOC_VECTORS_ERR);
> +	if (err)
> +		return err;
> +
> +	rcvd_vec = (struct virtchnl2_alloc_vectors *)adapter->vc_msg;
> +	num_vchunks = le16_to_cpu(rcvd_vec->vchunks.num_vchunks);
> +
> +	size = struct_size(rcvd_vec, vchunks.vchunks, num_vchunks);
> +	if (size > sizeof(adapter->vc_msg)) {
> +		err = -EINVAL;
> +		goto error;
> +	}
> +
> +	kfree(adapter->req_vec_chunks);
> +	adapter->req_vec_chunks = NULL;
> +	adapter->req_vec_chunks = kzalloc(size, GFP_KERNEL);
> +	if (!adapter->req_vec_chunks) {
> +		err = -ENOMEM;
> +		goto error;
> +	}
> +	memcpy(adapter->req_vec_chunks, adapter->vc_msg, size);

Hi Pavan,

Coccinelle suggests that kmemdup might be used here.

drivers/net/ethernet/intel/idpf/idpf_virtchnl.c:2085:27-34: WARNING opportunity for kmemdup

Likewise for a similar pattern in:
* [PATCH net-next v2 14/15] idpf: add ethtool callbacks

...