netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v3 0/2] net: dlink: handle copy_thresh allocation
@ 2025-09-16 18:33 Yeounsu Moon
  2025-09-16 18:33 ` [PATCH net v3 1/2] net: dlink: fix whitespace around function call Yeounsu Moon
  2025-09-16 18:33 ` [PATCH net v3 2/2] net: dlink: handle copy_thresh allocation failure Yeounsu Moon
  0 siblings, 2 replies; 10+ messages in thread
From: Yeounsu Moon @ 2025-09-16 18:33 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev, linux-kernel, Yeounsu Moon

This series contains two patches:

1. clean up whitespace around function calls to follow coding style.
(No functional change intended.)

2. Fix the memory handling issue with copybreak in the rx path.

Both patches have been tested on hardware.

Signed-off-by: Yeounsu Moon <yyyynoom@gmail.com>
---
Changelog:
v1: https://lore.kernel.org/netdev/20250912145339.67448-2-yyyynoom@gmail.com/
v2: https://lore.kernel.org/netdev/20250914182653.3152-4-yyyynoom@gmail.com/
- split into two patches: whitespace cleanup and functional fix
v3:
- change confusing label name
---

Yeounsu Moon (2):
  net: dlink: fix whitespace around function call
  net: dlink: handle copy_thresh allocation failure

 drivers/net/ethernet/dlink/dl2k.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

-- 
2.51.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH net v3 1/2] net: dlink: fix whitespace around function call
  2025-09-16 18:33 [PATCH net v3 0/2] net: dlink: handle copy_thresh allocation Yeounsu Moon
@ 2025-09-16 18:33 ` Yeounsu Moon
  2025-09-17 23:06   ` Jakub Kicinski
  2025-09-16 18:33 ` [PATCH net v3 2/2] net: dlink: handle copy_thresh allocation failure Yeounsu Moon
  1 sibling, 1 reply; 10+ messages in thread
From: Yeounsu Moon @ 2025-09-16 18:33 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev, linux-kernel, Yeounsu Moon, Andrew Lunn

Remove unnecessary whitespace between function names and the opening
parenthesis to follow kernel coding style.

No functional change intended.

Tested-on: D-Link DGE-550T Rev-A3
Signed-off-by: Yeounsu Moon <yyyynoom@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/ethernet/dlink/dl2k.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/dlink/dl2k.c b/drivers/net/ethernet/dlink/dl2k.c
index 6bbf6e5584e5..faf8a9fc7ed1 100644
--- a/drivers/net/ethernet/dlink/dl2k.c
+++ b/drivers/net/ethernet/dlink/dl2k.c
@@ -970,17 +970,17 @@ receive_packet (struct net_device *dev)
 						 desc_to_dma(desc),
 						 np->rx_buf_sz,
 						 DMA_FROM_DEVICE);
-				skb_put (skb = np->rx_skbuff[entry], pkt_len);
+				skb_put(skb = np->rx_skbuff[entry], pkt_len);
 				np->rx_skbuff[entry] = NULL;
 			} else if ((skb = netdev_alloc_skb_ip_align(dev, pkt_len))) {
 				dma_sync_single_for_cpu(&np->pdev->dev,
 							desc_to_dma(desc),
 							np->rx_buf_sz,
 							DMA_FROM_DEVICE);
-				skb_copy_to_linear_data (skb,
+				skb_copy_to_linear_data(skb,
 						  np->rx_skbuff[entry]->data,
 						  pkt_len);
-				skb_put (skb, pkt_len);
+				skb_put(skb, pkt_len);
 				dma_sync_single_for_device(&np->pdev->dev,
 							   desc_to_dma(desc),
 							   np->rx_buf_sz,
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net v3 2/2] net: dlink: handle copy_thresh allocation failure
  2025-09-16 18:33 [PATCH net v3 0/2] net: dlink: handle copy_thresh allocation Yeounsu Moon
  2025-09-16 18:33 ` [PATCH net v3 1/2] net: dlink: fix whitespace around function call Yeounsu Moon
@ 2025-09-16 18:33 ` Yeounsu Moon
  2025-09-16 19:36   ` Andrew Lunn
  2025-09-17 23:09   ` Jakub Kicinski
  1 sibling, 2 replies; 10+ messages in thread
From: Yeounsu Moon @ 2025-09-16 18:33 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev, linux-kernel, Yeounsu Moon

The driver did not handle failure of `netdev_alloc_skb_ip_align()`.
If the allocation failed, dereferencing `skb->protocol` could lead to a
NULL pointer dereference.

This patch adds proper error handling by falling back to the `else` clause
when the allocation fails.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Tested-on: D-Link DGE-550T Rev-A3
Signed-off-by: Yeounsu Moon <yyyynoom@gmail.com>
---
 drivers/net/ethernet/dlink/dl2k.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/dlink/dl2k.c b/drivers/net/ethernet/dlink/dl2k.c
index faf8a9fc7ed1..cff90417c05c 100644
--- a/drivers/net/ethernet/dlink/dl2k.c
+++ b/drivers/net/ethernet/dlink/dl2k.c
@@ -965,14 +965,11 @@ receive_packet (struct net_device *dev)
 			struct sk_buff *skb;
 
 			/* Small skbuffs for short packets */
-			if (pkt_len > copy_thresh) {
-				dma_unmap_single(&np->pdev->dev,
-						 desc_to_dma(desc),
-						 np->rx_buf_sz,
-						 DMA_FROM_DEVICE);
-				skb_put(skb = np->rx_skbuff[entry], pkt_len);
-				np->rx_skbuff[entry] = NULL;
-			} else if ((skb = netdev_alloc_skb_ip_align(dev, pkt_len))) {
+			if (pkt_len <= copy_thresh) {
+				skb = netdev_alloc_skb_ip_align(dev, pkt_len);
+				if (!skb)
+					goto fallback_to_normal_path;
+
 				dma_sync_single_for_cpu(&np->pdev->dev,
 							desc_to_dma(desc),
 							np->rx_buf_sz,
@@ -985,6 +982,14 @@ receive_packet (struct net_device *dev)
 							   desc_to_dma(desc),
 							   np->rx_buf_sz,
 							   DMA_FROM_DEVICE);
+			} else {
+fallback_to_normal_path:
+				dma_unmap_single(&np->pdev->dev,
+						 desc_to_dma(desc),
+						 np->rx_buf_sz,
+						 DMA_FROM_DEVICE);
+				skb_put(skb = np->rx_skbuff[entry], pkt_len);
+				np->rx_skbuff[entry] = NULL;
 			}
 			skb->protocol = eth_type_trans (skb, dev);
 #if 0
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 2/2] net: dlink: handle copy_thresh allocation failure
  2025-09-16 18:33 ` [PATCH net v3 2/2] net: dlink: handle copy_thresh allocation failure Yeounsu Moon
@ 2025-09-16 19:36   ` Andrew Lunn
  2025-09-17 23:09   ` Jakub Kicinski
  1 sibling, 0 replies; 10+ messages in thread
From: Andrew Lunn @ 2025-09-16 19:36 UTC (permalink / raw)
  To: Yeounsu Moon
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel

On Wed, Sep 17, 2025 at 03:33:05AM +0900, Yeounsu Moon wrote:
> The driver did not handle failure of `netdev_alloc_skb_ip_align()`.
> If the allocation failed, dereferencing `skb->protocol` could lead to a
> NULL pointer dereference.
> 
> This patch adds proper error handling by falling back to the `else` clause
> when the allocation fails.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Tested-on: D-Link DGE-550T Rev-A3
> Signed-off-by: Yeounsu Moon <yyyynoom@gmail.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 1/2] net: dlink: fix whitespace around function call
  2025-09-16 18:33 ` [PATCH net v3 1/2] net: dlink: fix whitespace around function call Yeounsu Moon
@ 2025-09-17 23:06   ` Jakub Kicinski
  2025-09-24 16:38     ` Yeounsu Moon
  0 siblings, 1 reply; 10+ messages in thread
From: Jakub Kicinski @ 2025-09-17 23:06 UTC (permalink / raw)
  To: Yeounsu Moon
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni, netdev,
	linux-kernel, Andrew Lunn

On Wed, 17 Sep 2025 03:33:04 +0900 Yeounsu Moon wrote:
> Remove unnecessary whitespace between function names and the opening
> parenthesis to follow kernel coding style.
> 
> No functional change intended.

please dont mix whitespace changes with fixes

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 2/2] net: dlink: handle copy_thresh allocation failure
  2025-09-16 18:33 ` [PATCH net v3 2/2] net: dlink: handle copy_thresh allocation failure Yeounsu Moon
  2025-09-16 19:36   ` Andrew Lunn
@ 2025-09-17 23:09   ` Jakub Kicinski
  2025-09-24 16:36     ` Yeounsu Moon
  1 sibling, 1 reply; 10+ messages in thread
From: Jakub Kicinski @ 2025-09-17 23:09 UTC (permalink / raw)
  To: Yeounsu Moon
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni, netdev,
	linux-kernel

On Wed, 17 Sep 2025 03:33:05 +0900 Yeounsu Moon wrote:
> @@ -965,14 +965,11 @@ receive_packet (struct net_device *dev)
>  			struct sk_buff *skb;
>  
>  			/* Small skbuffs for short packets */
> -			if (pkt_len > copy_thresh) {
> -				dma_unmap_single(&np->pdev->dev,
> -						 desc_to_dma(desc),
> -						 np->rx_buf_sz,
> -						 DMA_FROM_DEVICE);
> -				skb_put(skb = np->rx_skbuff[entry], pkt_len);
> -				np->rx_skbuff[entry] = NULL;
> -			} else if ((skb = netdev_alloc_skb_ip_align(dev, pkt_len))) {
> +			if (pkt_len <= copy_thresh) {
> +				skb = netdev_alloc_skb_ip_align(dev, pkt_len);
> +				if (!skb)
> +					goto fallback_to_normal_path;

The goto looks pretty awkward.

	skb = NULL;
	if (pkt_len <= copy_thresh)
		skb = netdev_alloc_skb_ip_align(dev, pkt_len);
	if (!skb) {
		// existing non-copy path
	} else {
		// existing copybreak path
	}

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 2/2] net: dlink: handle copy_thresh allocation failure
  2025-09-17 23:09   ` Jakub Kicinski
@ 2025-09-24 16:36     ` Yeounsu Moon
  2025-09-24 23:11       ` Jakub Kicinski
  0 siblings, 1 reply; 10+ messages in thread
From: Yeounsu Moon @ 2025-09-24 16:36 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni, netdev,
	linux-kernel

On Thu Sep 18, 2025 at 8:09 AM KST, Jakub Kicinski wrote:

Thank you for reviewing! and sorry for the delayed reply.
There have been quite a lot of things on my end recently.

> On Wed, 17 Sep 2025 03:33:05 +0900 Yeounsu Moon wrote:
>> @@ -965,14 +965,11 @@ receive_packet (struct net_device *dev)
>>  			struct sk_buff *skb;
>>  
>>  			/* Small skbuffs for short packets */
>> -			if (pkt_len > copy_thresh) {
>> -				dma_unmap_single(&np->pdev->dev,
>> -						 desc_to_dma(desc),
>> -						 np->rx_buf_sz,
>> -						 DMA_FROM_DEVICE);
>> -				skb_put(skb = np->rx_skbuff[entry], pkt_len);
>> -				np->rx_skbuff[entry] = NULL;
>> -			} else if ((skb = netdev_alloc_skb_ip_align(dev, pkt_len))) {
>> +			if (pkt_len <= copy_thresh) {
>> +				skb = netdev_alloc_skb_ip_align(dev, pkt_len);
>> +				if (!skb)
>> +					goto fallback_to_normal_path;
>
> The goto looks pretty awkward.
>
> 	skb = NULL;
> 	if (pkt_len <= copy_thresh)
> 		skb = netdev_alloc_skb_ip_align(dev, pkt_len);
> 	if (!skb) {
> 		// existing non-copy path
> 	} else {
> 		// existing copybreak path
> 	}

I totally agree with your point. However, the two cases handle `skb` and
`rx_skbuff` differently depending on the `copy_thresh` condition,
regardless of whether `skb` is NULL or not.

This patch is only intended to gracefully handle the failure case when `skb`
allocation fails.

	Yeounsu Moon

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 1/2] net: dlink: fix whitespace around function call
  2025-09-17 23:06   ` Jakub Kicinski
@ 2025-09-24 16:38     ` Yeounsu Moon
  2025-09-24 23:12       ` Jakub Kicinski
  0 siblings, 1 reply; 10+ messages in thread
From: Yeounsu Moon @ 2025-09-24 16:38 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni, netdev,
	linux-kernel, Andrew Lunn

On Thu Sep 18, 2025 at 8:06 AM KST, Jakub Kicinski wrote:
> On Wed, 17 Sep 2025 03:33:04 +0900 Yeounsu Moon wrote:
>> Remove unnecessary whitespace between function names and the opening
>> parenthesis to follow kernel coding style.
>> 
>> No functional change intended.
>
> please dont mix whitespace changes with fixes

Now that some time has passed, let me recap the situation,
(I initially wanted to summerize the message, but I'm concerned that my
English might cause misunderstanding. So I'll just quote the full
message instead. Sorry about that.)

------------

> > Please don't include white space changes with other changes. It makes
> > the patch harder to review.
> >
> >     Andrew
> Thank you for reviewing!
>
> As you mentioned, it indeed becomes harder to see what the real changes
> are. I have a few questions related to that:
>
> 1. If I remove the whitespace between the funciton name and the
> parenthesis, `checkpatch.pl` will warn about it. Of course, I understand
> that we don't need to follow such rules in a mindessly robotic way.
>
> 2. However, I also read in the netdev FAQ that cleanup-only patches are
> discouraged. So I thought it would be better to include the cleanup
> together with the patch. But I see your point, and I'll be more careful
> not to send patches that cause such confusion in the future.
>
> 3. This is more of a personal curiosity: in that case, what would be the
> proper way to handle cleanup patches?

The problem with cleanup patches is that they are often done by
developers who don't have the hardware, and so don't do any
testing. White space changes like this a low risk, but other cleanup
patches are much more risky. So some cleanup patches end up breaking
stuff. We reviewers know this, and so put in more time looking at such
patches and try to make sure they are correct. But cleanup is
generally lower priority than new code. So to some extent, we prefer
the code is left 'dirty but working'.

In this case, you have the hardware. You are testing your change, so
we are much happier to accept such a cleanup patch as part of a
patchset fixing a real problem.

Please submit two patches in a patchset. The first patch fixes the
whitespace. The second fixes the memory problem with copy break. That
should be checkpatch clean. And mention in the commit message that
this has been tested on hardware.

------------

You and Andrew seems to share a similar point of view, and both are
quite reasonable. What do you think about this approach?

	Yeousu Moon

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 2/2] net: dlink: handle copy_thresh allocation failure
  2025-09-24 16:36     ` Yeounsu Moon
@ 2025-09-24 23:11       ` Jakub Kicinski
  0 siblings, 0 replies; 10+ messages in thread
From: Jakub Kicinski @ 2025-09-24 23:11 UTC (permalink / raw)
  To: Yeounsu Moon
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni, netdev,
	linux-kernel

On Thu, 25 Sep 2025 01:36:57 +0900 Yeounsu Moon wrote:
> > On Wed, 17 Sep 2025 03:33:05 +0900 Yeounsu Moon wrote:  
> >> @@ -965,14 +965,11 @@ receive_packet (struct net_device *dev)
> >>  			struct sk_buff *skb;
> >>  
> >>  			/* Small skbuffs for short packets */
> >> -			if (pkt_len > copy_thresh) {
> >> -				dma_unmap_single(&np->pdev->dev,
> >> -						 desc_to_dma(desc),
> >> -						 np->rx_buf_sz,
> >> -						 DMA_FROM_DEVICE);
> >> -				skb_put(skb = np->rx_skbuff[entry], pkt_len);
> >> -				np->rx_skbuff[entry] = NULL;
> >> -			} else if ((skb = netdev_alloc_skb_ip_align(dev, pkt_len))) {
> >> +			if (pkt_len <= copy_thresh) {
> >> +				skb = netdev_alloc_skb_ip_align(dev, pkt_len);
> >> +				if (!skb)
> >> +					goto fallback_to_normal_path;  
> >
> > The goto looks pretty awkward.
> >
> > 	skb = NULL;
> > 	if (pkt_len <= copy_thresh)
> > 		skb = netdev_alloc_skb_ip_align(dev, pkt_len);
> > 	if (!skb) {
> > 		// existing non-copy path
> > 	} else {
> > 		// existing copybreak path
> > 	}  
> 
> I totally agree with your point. However, the two cases handle `skb` and
> `rx_skbuff` differently depending on the `copy_thresh` condition,
> regardless of whether `skb` is NULL or not.

I don't understand.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 1/2] net: dlink: fix whitespace around function call
  2025-09-24 16:38     ` Yeounsu Moon
@ 2025-09-24 23:12       ` Jakub Kicinski
  0 siblings, 0 replies; 10+ messages in thread
From: Jakub Kicinski @ 2025-09-24 23:12 UTC (permalink / raw)
  To: Yeounsu Moon
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni, netdev,
	linux-kernel, Andrew Lunn

On Thu, 25 Sep 2025 01:38:34 +0900 Yeounsu Moon wrote:
> You and Andrew seems to share a similar point of view, and both are
> quite reasonable. What do you think about this approach?

Send the fix first, wait for it to reach net-next.
Then send the cleanup.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-09-24 23:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-16 18:33 [PATCH net v3 0/2] net: dlink: handle copy_thresh allocation Yeounsu Moon
2025-09-16 18:33 ` [PATCH net v3 1/2] net: dlink: fix whitespace around function call Yeounsu Moon
2025-09-17 23:06   ` Jakub Kicinski
2025-09-24 16:38     ` Yeounsu Moon
2025-09-24 23:12       ` Jakub Kicinski
2025-09-16 18:33 ` [PATCH net v3 2/2] net: dlink: handle copy_thresh allocation failure Yeounsu Moon
2025-09-16 19:36   ` Andrew Lunn
2025-09-17 23:09   ` Jakub Kicinski
2025-09-24 16:36     ` Yeounsu Moon
2025-09-24 23:11       ` Jakub Kicinski

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).