netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yeounsu Moon" <yyyynoom@gmail.com>
To: "Simon Horman" <horms@kernel.org>
Cc: "Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net] net: dlink: handle dma_map_single() failure properly
Date: Sun, 05 Oct 2025 14:22:43 +0900	[thread overview]
Message-ID: <DDA4Y2GRUHD4.1DFHX01NOJYCB@gmail.com> (raw)
In-Reply-To: <20251003094424.GF2878334@horms.kernel.org>

Hello Simon.

I'm currenly re-writing the code as you suggested. I think `alloc_list()` 
can easily adopt the `goto` pattern, but for others functions, it's not 
that straightforward.

My question is whether a style combining `goto`, `continue`, and `break`
would be acceptable in this context:

```c
	if (np->cur_rx - np->old_rx >= RX_RING_SIZE) {
		printk(KERN_INFO "Try to recover rx ring exhausted...\n");
		/* Re-allocate skbuffs to fill the descriptor ring */
		for (; np->cur_rx - np->old_rx > 0; np->old_rx++) {
			struct sk_buff *skb;
			dma_addr_t addr;
			entry = np->old_rx % RX_RING_SIZE;
			/* Dropped packets don't need to re-allocate */
			if (np->rx_skbuff[entry])
				goto fill_entry;

			skb = netdev_alloc_skb_ip_align(dev, np->rx_buf_sz);
			if (skb == NULL)
				goto out_clear_fraginfo;

			addr = dma_map_single(&np->pdev->dev, skb->data,
					      np->rx_buf_sz,
					      DMA_FROM_DEVICE);
			if (dma_mapping_error(&np->pdev->dev, addr))
				goto out_kfree_skb;

			np->rx_skbuff[entry] = skb;
			np->rx_ring[entry].fraginfo = cpu_to_le64(addr);
fill_entry:
			np->rx_ring[entry].fraginfo |=
			    cpu_to_le64((u64)np->rx_buf_sz << 48);
			np->rx_ring[entry].status = 0;
			continue;

out_kfree_skb:
			dev_kfree_skb_irq(skb);
out_clear_fraginfo:
			np->rx_ring[entry].fraginfo = 0;
			printk(KERN_INFO
			       "%s: Still unable to re-allocate Rx skbuff.#%d\n"
			       , dev->name, entry);
			break;
		} /* end for */
	} /* end if */
	spin_unlock_irqrestore (&np->rx_lock, flags);
	np->timer.expires = jiffies + next_tick;
	add_timer(&np->timer);
}
```

Or is there any better way to handle errors here?
I'd appreciate your guidance.

  parent reply	other threads:[~2025-10-05  5:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-02 15:26 [PATCH net] net: dlink: handle dma_map_single() failure properly Yeounsu Moon
2025-10-03  9:44 ` Simon Horman
2025-10-03 12:29   ` Yeounsu Moon
2025-10-03 15:55     ` Jakub Kicinski
2025-10-05  5:22   ` Yeounsu Moon [this message]
2025-10-08  9:13     ` Simon Horman
2025-10-09 15:56       ` Yeounsu Moon

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=DDA4Y2GRUHD4.1DFHX01NOJYCB@gmail.com \
    --to=yyyynoom@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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).