All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Yeounsu Moon <yyyynoom@gmail.com>
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: Wed, 8 Oct 2025 10:13:46 +0100	[thread overview]
Message-ID: <20251008091346.GO3060232@horms.kernel.org> (raw)
In-Reply-To: <DDA4Y2GRUHD4.1DFHX01NOJYCB@gmail.com>

On Sun, Oct 05, 2025 at 02:22:43PM +0900, Yeounsu Moon wrote:
> 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.

Sorry for the slow response, I've been ill for the past few days.

I did also consider the option above. That is handling the
errors in the loop. And I can see some merit in that approach,
e.g. reduced scope of variables.

But I think the more idiomatic approach is to handle them 'here'.
That is, at the end of the function. So I would lean towards
that option.

  reply	other threads:[~2025-10-08  9:13 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
2025-10-08  9:13     ` Simon Horman [this message]
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=20251008091346.GO3060232@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=yyyynoom@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.