[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210216010806.31948-6-TheSven73@gmail.com>
Date: Mon, 15 Feb 2021 20:08:06 -0500
From: Sven Van Asbroeck <thesven73@...il.com>
To: Bryan Whitehead <bryan.whitehead@...rochip.com>,
UNGLinuxDriver@...rochip.com, David S Miller <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>
Cc: Sven Van Asbroeck <thesven73@...il.com>,
Andrew Lunn <andrew@...n.ch>,
Alexey Denisov <rtgbnm@...il.com>,
Sergej Bauer <sbauer@...ckbox.su>,
Tim Harvey <tharvey@...eworks.com>,
Anders Rønningen <anders@...ningen.priv.no>,
Hillf Danton <hdanton@...a.com>,
Christoph Hellwig <hch@....de>,
Willem de Bruijn <willemdebruijn.kernel@...il.com>,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH net-next v3 5/5] TEST ONLY: lan743x: skb_trim failure test
From: Sven Van Asbroeck <thesven73@...il.com>
Simulate low-memory in lan743x_rx_trim_skb(): fail one allocation
in every 100.
Signed-off-by: Sven Van Asbroeck <thesven73@...il.com>
---
To: Bryan Whitehead <bryan.whitehead@...rochip.com>
To: UNGLinuxDriver@...rochip.com
To: "David S. Miller" <davem@...emloft.net>
To: Jakub Kicinski <kuba@...nel.org>
Cc: Andrew Lunn <andrew@...n.ch>
Cc: Alexey Denisov <rtgbnm@...il.com>
Cc: Sergej Bauer <sbauer@...ckbox.su>
Cc: Tim Harvey <tharvey@...eworks.com>
Cc: Anders Rønningen <anders@...ningen.priv.no>
Cc: Hillf Danton <hdanton@...a.com>
Cc: Christoph Hellwig <hch@....de>
Cc: Willem de Bruijn <willemdebruijn.kernel@...il.com>
Cc: netdev@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
drivers/net/ethernet/microchip/lan743x_main.c | 28 ++++++++-----------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index 6e1b3c996bd7..4751626f4c0f 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -1963,20 +1963,7 @@ static void lan743x_rx_update_tail(struct lan743x_rx *rx, int index)
index);
}
-static struct sk_buff *
-lan743x_alloc_skb(struct net_device *netdev, int length, bool can_fail)
-{
- static int rx_alloc;
- int counter = rx_alloc++ % 100;
-
- if (can_fail && counter >= 20 && counter < 30)
- return NULL;
-
- return __netdev_alloc_skb(netdev, length, GFP_ATOMIC | GFP_DMA);
-}
-
-static int
-lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index, bool can_fail)
+static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index)
{
struct net_device *netdev = rx->adapter->netdev;
struct device *dev = &rx->adapter->pdev->dev;
@@ -1990,7 +1977,7 @@ lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index, bool can_fail)
descriptor = &rx->ring_cpu_ptr[index];
buffer_info = &rx->buffer_info[index];
- skb = lan743x_alloc_skb(netdev, buffer_length, can_fail);
+ skb = __netdev_alloc_skb(netdev, buffer_length, GFP_ATOMIC | GFP_DMA);
if (!skb)
return -ENOMEM;
dma_ptr = dma_map_single(dev, skb->data, buffer_length, DMA_FROM_DEVICE);
@@ -2078,6 +2065,13 @@ static void lan743x_rx_release_ring_element(struct lan743x_rx *rx, int index)
static struct sk_buff *
lan743x_rx_trim_skb(struct sk_buff *skb, int frame_length)
{
+ static int trim_cnt;
+
+ if ((trim_cnt++ % 100) == 77) {
+ dev_kfree_skb_irq(skb);
+ return NULL;
+ }
+
if (skb_linearize(skb)) {
dev_kfree_skb_irq(skb);
return NULL;
@@ -2152,7 +2146,7 @@ static int lan743x_rx_process_buffer(struct lan743x_rx *rx)
/* save existing skb, allocate new skb and map to dma */
skb = buffer_info->skb;
- if (lan743x_rx_init_ring_element(rx, rx->last_head, true)) {
+ if (lan743x_rx_init_ring_element(rx, rx->last_head)) {
/* failed to allocate next skb.
* Memory is very low.
* Drop this packet and reuse buffer.
@@ -2357,7 +2351,7 @@ static int lan743x_rx_ring_init(struct lan743x_rx *rx)
rx->last_head = 0;
for (index = 0; index < rx->ring_size; index++) {
- ret = lan743x_rx_init_ring_element(rx, index, false);
+ ret = lan743x_rx_init_ring_element(rx, index);
if (ret)
goto cleanup;
}
--
2.17.1
Powered by blists - more mailing lists