netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Tony Nguyen <anthony.l.nguyen@intel.com>
Cc: davem@davemloft.net, pabeni@redhat.com, edumazet@google.com,
	netdev@vger.kernel.org, Joshua Hay <joshua.a.hay@intel.com>,
	pavan.kumar.linga@intel.com, emil.s.tantilov@intel.com,
	jesse.brandeburg@intel.com, sridhar.samudrala@intel.com,
	shiraz.saleem@intel.com, sindhu.devale@intel.com,
	willemb@google.com, decot@google.com, andrew@lunn.ch,
	leon@kernel.org, mst@redhat.com, simon.horman@corigine.com,
	shannon.nelson@amd.com, stephen@networkplumber.org,
	Alan Brady <alan.brady@intel.com>,
	Madhu Chittim <madhu.chittim@intel.com>,
	Phani Burra <phani.r.burra@intel.com>,
	Shailendra Bhatnagar <shailendra.bhatnagar@intel.com>
Subject: Re: [PATCH net-next v2 03/15] idpf: add controlq init and reset checks
Date: Fri, 16 Jun 2023 23:42:18 -0700	[thread overview]
Message-ID: <20230616234218.58760587@kernel.org> (raw)
In-Reply-To: <20230614171428.1504179-4-anthony.l.nguyen@intel.com>

On Wed, 14 Jun 2023 10:14:16 -0700 Tony Nguyen wrote:
> +static void idpf_ctlq_init_rxq_bufs(struct idpf_ctlq_info *cq)
> +{
> +	int i = 0;
> +
> +	for (i = 0; i < cq->ring_size; i++) {

no need to init i twice

> +	if (!qinfo->len || !qinfo->buf_size ||
> +	    qinfo->len > IDPF_CTLQ_MAX_RING_SIZE ||
> +	    qinfo->buf_size > IDPF_CTLQ_MAX_BUF_LEN)
> +		return -EINVAL;

Looks like defensive programming, it's generally discouraged in 
the kernel.

> +init_free_q:
> +	kfree(cq);
> +	cq = NULL;

no need to clear local variables

> +	return err;
> +}

> +	int i = 0;
> +
> +	INIT_LIST_HEAD(&hw->cq_list_head);
> +
> +	for (i = 0; i < num_q; i++) {

init, again, please fix throughout

> +		struct idpf_ctlq_create_info *qinfo = q_info + i;
> +
> +		err = idpf_ctlq_add(hw, qinfo, &cq);
> +		if (err)
> +			goto init_destroy_qs;
> +	}
> +
> +	return err;

return 0 is more idiomatic, you can't reach it with an errno


> +void idpf_ctlq_deinit(struct idpf_hw *hw)
> +{
> +	struct idpf_ctlq_info *cq = NULL, *tmp = NULL;

You really like to init the stack :S

> +	list_for_each_entry_safe(cq, tmp, &hw->cq_list_head, cq_list)
> +		idpf_ctlq_remove(hw, cq);
> +}

> +	if (!cq || !cq->ring_size)
> +		return -ENOBUFS;

even worse defensive programming

> +	mutex_lock(&cq->cq_lock);
> +
> +	/* Ensure there are enough descriptors to send all messages */
> +	num_desc_avail = IDPF_CTLQ_DESC_UNUSED(cq);
> +	if (num_desc_avail == 0 || num_desc_avail < num_q_msg) {
> +		err = -ENOSPC;
> +		goto sq_send_command_out;

name labels after what they jump to, err_unlock

> +void *idpf_alloc_dma_mem(struct idpf_hw *hw, struct idpf_dma_mem *mem, u64 size)
> +{
> +	struct idpf_adapter *adapter = hw->back;
> +	size_t sz = ALIGN(size, 4096);
> +
> +	mem->va = dma_alloc_coherent(&adapter->pdev->dev, sz,
> +				     &mem->pa, GFP_KERNEL | __GFP_ZERO);

DMA API always zeros memory, I thought cocci warns about this
Did you run cocci checks?


  reply	other threads:[~2023-06-17  6:42 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-14 17:14 [PATCH net-next v2 00/15][pull request] Introduce Intel IDPF driver Tony Nguyen
2023-06-14 17:14 ` [PATCH net-next v2 01/15] virtchnl: add virtchnl version 2 ops Tony Nguyen
2023-06-14 17:14 ` [PATCH net-next v2 02/15] idpf: add module register and probe functionality Tony Nguyen
2023-06-14 17:14 ` [PATCH net-next v2 03/15] idpf: add controlq init and reset checks Tony Nguyen
2023-06-17  6:42   ` Jakub Kicinski [this message]
2023-06-21 19:05     ` Linga, Pavan Kumar
2023-06-21 19:14       ` Jakub Kicinski
2023-06-21 19:43         ` Simon Horman
2023-06-14 17:14 ` [PATCH net-next v2 04/15] idpf: add core init and interrupt request Tony Nguyen
2023-06-17  6:50   ` Jakub Kicinski
2023-06-21 19:07     ` Linga, Pavan Kumar
2023-06-14 17:14 ` [PATCH net-next v2 05/15] idpf: add create vport and netdev configuration Tony Nguyen
2023-06-14 18:21   ` Stephen Hemminger
2023-06-15  0:12     ` Linga, Pavan Kumar
2023-06-14 17:14 ` [PATCH net-next v2 06/15] idpf: continue expanding init task Tony Nguyen
2023-06-14 17:14 ` [PATCH net-next v2 07/15] idpf: configure resources for TX queues Tony Nguyen
2023-06-14 17:14 ` [PATCH net-next v2 08/15] idpf: configure resources for RX queues Tony Nguyen
2023-06-14 17:14 ` [PATCH net-next v2 09/15] idpf: initialize interrupts and enable vport Tony Nguyen
2023-06-14 17:14 ` [PATCH net-next v2 10/15] idpf: add splitq start_xmit Tony Nguyen
2023-06-14 17:14 ` [PATCH net-next v2 11/15] idpf: add TX splitq napi poll support Tony Nguyen
2023-06-14 17:14 ` [PATCH net-next v2 12/15] idpf: add RX " Tony Nguyen
2023-06-17  6:55   ` Jakub Kicinski
2023-06-21 19:07     ` Linga, Pavan Kumar
2023-06-17  7:01   ` Jakub Kicinski
2023-06-21 19:09     ` Linga, Pavan Kumar
2023-06-21 19:21       ` Jakub Kicinski
2023-06-14 17:14 ` [PATCH net-next v2 13/15] idpf: add singleq start_xmit and napi poll Tony Nguyen
2023-06-14 17:14 ` [PATCH net-next v2 14/15] idpf: add ethtool callbacks Tony Nguyen
2023-06-14 17:14 ` [PATCH net-next v2 15/15] idpf: configure SRIOV and add other ndo_ops Tony Nguyen
  -- strict thread matches above, loose matches on Subject: below --
2023-04-11  1:13 [PATCH net-next v2 00/15] Introduce Intel IDPF driver Pavan Kumar Linga
2023-04-11  1:13 ` [PATCH net-next v2 03/15] idpf: add controlq init and reset checks Pavan Kumar Linga
2023-04-11  9:19   ` Simon Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230616234218.58760587@kernel.org \
    --to=kuba@kernel.org \
    --cc=alan.brady@intel.com \
    --cc=andrew@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=decot@google.com \
    --cc=edumazet@google.com \
    --cc=emil.s.tantilov@intel.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=joshua.a.hay@intel.com \
    --cc=leon@kernel.org \
    --cc=madhu.chittim@intel.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pavan.kumar.linga@intel.com \
    --cc=phani.r.burra@intel.com \
    --cc=shailendra.bhatnagar@intel.com \
    --cc=shannon.nelson@amd.com \
    --cc=shiraz.saleem@intel.com \
    --cc=simon.horman@corigine.com \
    --cc=sindhu.devale@intel.com \
    --cc=sridhar.samudrala@intel.com \
    --cc=stephen@networkplumber.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).