public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH net-next] lib8390: Use eth_skb_pad()
@ 2020-11-12 16:31 Armin Wolf
  2020-11-14 20:56 ` Jakub Kicinski
  2020-11-14 21:03 ` Florian Fainelli
  0 siblings, 2 replies; 3+ messages in thread
From: Armin Wolf @ 2020-11-12 16:31 UTC (permalink / raw)
  To: davem; +Cc: netdev, joe

Use eth_skb_pad() instead of a custom padding solution
and replace associated variables with skb->* expressions.

Signed-off-by: Armin Wolf <W_Armin@gmx•de>
---
 drivers/net/ethernet/8390/lib8390.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/8390/lib8390.c b/drivers/net/ethernet/8390/lib8390.c
index e84021282edf..47e2962eff56 100644
--- a/drivers/net/ethernet/8390/lib8390.c
+++ b/drivers/net/ethernet/8390/lib8390.c
@@ -305,16 +305,13 @@ static netdev_tx_t __ei_start_xmit(struct sk_buff *skb,
 {
 	unsigned long e8390_base = dev->base_addr;
 	struct ei_device *ei_local = netdev_priv(dev);
-	int send_length = skb->len, output_page;
+	int output_page;
 	unsigned long flags;
-	char buf[ETH_ZLEN];
-	char *data = skb->data;
-
-	if (skb->len < ETH_ZLEN) {
-		memset(buf, 0, ETH_ZLEN);	/* more efficient than doing just the needed bits */
-		memcpy(buf, data, skb->len);
-		send_length = ETH_ZLEN;
-		data = buf;
+
+	/* The Hardware does not pad undersized frames */
+	if (eth_skb_pad(skb)) {
+		dev->stats.tx_dropped++;
+		return NETDEV_TX_OK;
 	}

 	/* Mask interrupts from the ethercard.
@@ -347,7 +344,7 @@ static netdev_tx_t __ei_start_xmit(struct sk_buff *skb,

 	if (ei_local->tx1 == 0) {
 		output_page = ei_local->tx_start_page;
-		ei_local->tx1 = send_length;
+		ei_local->tx1 = skb->len;
 		if ((netif_msg_tx_queued(ei_local)) &&
 		    ei_local->tx2 > 0)
 			netdev_dbg(dev,
@@ -355,7 +352,7 @@ static netdev_tx_t __ei_start_xmit(struct sk_buff *skb,
 				   ei_local->tx2, ei_local->lasttx, ei_local->txing);
 	} else if (ei_local->tx2 == 0) {
 		output_page = ei_local->tx_start_page + TX_PAGES/2;
-		ei_local->tx2 = send_length;
+		ei_local->tx2 = skb->len;
 		if ((netif_msg_tx_queued(ei_local)) &&
 		    ei_local->tx1 > 0)
 			netdev_dbg(dev,
@@ -380,11 +377,11 @@ static netdev_tx_t __ei_start_xmit(struct sk_buff *skb,
 	 * trigger the send later, upon receiving a Tx done interrupt.
 	 */

-	ei_block_output(dev, send_length, data, output_page);
+	ei_block_output(dev, skb->len, skb->data, output_page);

 	if (!ei_local->txing) {
 		ei_local->txing = 1;
-		NS8390_trigger_send(dev, send_length, output_page);
+		NS8390_trigger_send(dev, skb->len, output_page);
 		if (output_page == ei_local->tx_start_page) {
 			ei_local->tx1 = -1;
 			ei_local->lasttx = -1;
@@ -407,8 +404,8 @@ static netdev_tx_t __ei_start_xmit(struct sk_buff *skb,
 	spin_unlock(&ei_local->page_lock);
 	enable_irq_lockdep_irqrestore(dev->irq, &flags);
 	skb_tx_timestamp(skb);
+	dev->stats.tx_bytes += skb->len;
 	dev_consume_skb_any(skb);
-	dev->stats.tx_bytes += send_length;

 	return NETDEV_TX_OK;
 }
--
2.20.1


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

* Re: [PATCH net-next] lib8390: Use eth_skb_pad()
  2020-11-12 16:31 [PATCH net-next] lib8390: Use eth_skb_pad() Armin Wolf
@ 2020-11-14 20:56 ` Jakub Kicinski
  2020-11-14 21:03 ` Florian Fainelli
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2020-11-14 20:56 UTC (permalink / raw)
  To: Armin Wolf; +Cc: davem, netdev, joe

On Thu, 12 Nov 2020 17:31:34 +0100 Armin Wolf wrote:
> Use eth_skb_pad() instead of a custom padding solution
> and replace associated variables with skb->* expressions.

These are two separate changes, please split them out to two patches.

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

* Re: [PATCH net-next] lib8390: Use eth_skb_pad()
  2020-11-12 16:31 [PATCH net-next] lib8390: Use eth_skb_pad() Armin Wolf
  2020-11-14 20:56 ` Jakub Kicinski
@ 2020-11-14 21:03 ` Florian Fainelli
  1 sibling, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2020-11-14 21:03 UTC (permalink / raw)
  To: Armin Wolf, davem; +Cc: netdev, joe



On 11/12/2020 8:31 AM, Armin Wolf wrote:
> Use eth_skb_pad() instead of a custom padding solution
> and replace associated variables with skb->* expressions.
> 
> Signed-off-by: Armin Wolf <W_Armin@gmx•de>
> ---

[snip]

> @@ -407,8 +404,8 @@ static netdev_tx_t __ei_start_xmit(struct sk_buff *skb,
>  	spin_unlock(&ei_local->page_lock);
>  	enable_irq_lockdep_irqrestore(dev->irq, &flags);
>  	skb_tx_timestamp(skb);
> +	dev->stats.tx_bytes += skb->len;
>  	dev_consume_skb_any(skb);
> -	dev->stats.tx_bytes += send_length;

There is nothing wrong here with the existing code and you could avoid
an use-after-free if not careful, I would personally keep the existing
code which appears to be just fine.
-- 
Florian

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

end of thread, other threads:[~2020-11-14 21:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-12 16:31 [PATCH net-next] lib8390: Use eth_skb_pad() Armin Wolf
2020-11-14 20:56 ` Jakub Kicinski
2020-11-14 21:03 ` Florian Fainelli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox