* [PATCH net v2 0/2] net: dlink: handle copy_thresh allocation
@ 2025-09-14 18:26 Yeounsu Moon
2025-09-14 18:26 ` [PATCH net v2 1/2] net: dlink: fix whitespace around function call Yeounsu Moon
2025-09-14 18:26 ` [PATCH net v2 2/2] net: dlink: handle copy_thresh allocation failure Yeounsu Moon
0 siblings, 2 replies; 5+ messages in thread
From: Yeounsu Moon @ 2025-09-14 18:26 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:
- split into two patches: whitespace cleanup and functional fix
---
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] 5+ messages in thread
* [PATCH net v2 1/2] net: dlink: fix whitespace around function call
2025-09-14 18:26 [PATCH net v2 0/2] net: dlink: handle copy_thresh allocation Yeounsu Moon
@ 2025-09-14 18:26 ` Yeounsu Moon
2025-09-14 18:55 ` Andrew Lunn
2025-09-14 18:26 ` [PATCH net v2 2/2] net: dlink: handle copy_thresh allocation failure Yeounsu Moon
1 sibling, 1 reply; 5+ messages in thread
From: Yeounsu Moon @ 2025-09-14 18:26 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: netdev, linux-kernel, Yeounsu Moon
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>
---
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] 5+ messages in thread
* [PATCH net v2 2/2] net: dlink: handle copy_thresh allocation failure
2025-09-14 18:26 [PATCH net v2 0/2] net: dlink: handle copy_thresh allocation Yeounsu Moon
2025-09-14 18:26 ` [PATCH net v2 1/2] net: dlink: fix whitespace around function call Yeounsu Moon
@ 2025-09-14 18:26 ` Yeounsu Moon
2025-09-14 18:53 ` Andrew Lunn
1 sibling, 1 reply; 5+ messages in thread
From: Yeounsu Moon @ 2025-09-14 18:26 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..a82e1fd01b92 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 reuse_skbuff;
+
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 {
+reuse_skbuff:
+ 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] 5+ messages in thread
* Re: [PATCH net v2 2/2] net: dlink: handle copy_thresh allocation failure
2025-09-14 18:26 ` [PATCH net v2 2/2] net: dlink: handle copy_thresh allocation failure Yeounsu Moon
@ 2025-09-14 18:53 ` Andrew Lunn
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2025-09-14 18:53 UTC (permalink / raw)
To: Yeounsu Moon
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
> This patch adds proper error handling by falling back to the `else` clause
> when the allocation fails.
> + if (pkt_len <= copy_thresh) {
> + skb = netdev_alloc_skb_ip_align(dev, pkt_len);
> + if (!skb)
> + goto reuse_skbuff;
> +
> 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 {
> +reuse_skbuff:
To me, the name is confusing. What Ethernet drivers usually mean with
reuse of an skbuf, is that they will give it straight back to the
hardware for use. If you can successfully do copy break, this makes
sense, the frame is no longer in the skbuf, it is in a new skbuf, so
the old skbuf can be recycled.
But that is not what is going on here. Copy break fails, and you fall
back to the normal path. The data is still in the skbuf, so you cannot
reuse it.
Andrew
---
pw-bot: cr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v2 1/2] net: dlink: fix whitespace around function call
2025-09-14 18:26 ` [PATCH net v2 1/2] net: dlink: fix whitespace around function call Yeounsu Moon
@ 2025-09-14 18:55 ` Andrew Lunn
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2025-09-14 18:55 UTC (permalink / raw)
To: Yeounsu Moon
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
On Mon, Sep 15, 2025 at 03:26:53AM +0900, Yeounsu Moon wrote:
> 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>
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-09-14 18:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-14 18:26 [PATCH net v2 0/2] net: dlink: handle copy_thresh allocation Yeounsu Moon
2025-09-14 18:26 ` [PATCH net v2 1/2] net: dlink: fix whitespace around function call Yeounsu Moon
2025-09-14 18:55 ` Andrew Lunn
2025-09-14 18:26 ` [PATCH net v2 2/2] net: dlink: handle copy_thresh allocation failure Yeounsu Moon
2025-09-14 18:53 ` Andrew Lunn
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).