All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Thomas Chou <thomas@wytron.com.tw>
Cc: netdev@vger.kernel.org, thierry.reding@avionic-design.de,
	Nios2 development list <nios2-dev@sopc.et.ntust.edu.tw>,
	linux-kernel@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>
Subject: [PATCH] net: Add netdev_alloc_skb_ip_align() helper
Date: Thu, 08 Oct 2009 05:11:23 +0200	[thread overview]
Message-ID: <4ACD585B.5080106@gmail.com> (raw)
In-Reply-To: <1254969161-3609-1-git-send-email-thomas@wytron.com.tw>

Thomas Chou a écrit :
> As suggested by Stephen Hemminger.
> 
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
>  drivers/net/ethoc.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
> index ecc53d9..4a1ed81 100644
> --- a/drivers/net/ethoc.c
> +++ b/drivers/net/ethoc.c
> @@ -409,7 +409,7 @@ static int ethoc_rx(struct net_device *dev, int limit)
>  			struct sk_buff *skb = netdev_alloc_skb(dev, size);
>  
>  			size -= 4; /* strip the CRC */
> -			skb_reserve(skb, 2); /* align TCP/IP header */
> +			skb_reserve(skb, NET_IP_ALIGN);
>  
>  			if (likely(skb)) {
>  				void *src = phys_to_virt(bd.addr);

Sorry to be dense here, but this code breaks if NET_IP_ALIGN > 4.
Its also suboptimal, you alloc two bytes in excess.


You should do :

size -= 4; /* strip the CRC */
skb = netdev_alloc_skb(dev, size + NET_IP_ALIGN);
if (skb) {
	skb_reserve(skb, NET_IP_ALIGN);
	...
}


Please check other implementations...

David, maybe we should add following helper :

[PATCH] net: Add netdev_alloc_skb_ip_align() helper

Instead of hardcoding NET_IP_ALIGN stuff in various network drivers, we can
add a helper around netdev_alloc_skb()

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index df7b23a..fed788e 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1489,6 +1489,16 @@ static inline struct sk_buff *netdev_alloc_skb(struct net_device *dev,
 	return __netdev_alloc_skb(dev, length, GFP_ATOMIC);
 }
 
+static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev,
+		unsigned int length)
+{
+	struct sk_buff *skb = netdev_alloc_skb(dev, length + NET_IP_ALIGN);
+
+	if (NET_IP_ALIGN && skb)
+		skb_reserve(skb, NET_IP_ALIGN);
+	return skb;
+}
+
 extern struct page *__netdev_alloc_page(struct net_device *dev, gfp_t gfp_mask);
 
 /**

  reply	other threads:[~2009-10-08  3:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-08  2:32 [PATCH] ethoc: use NET_IP_ALIGN in skb_reserve() Thomas Chou
2009-10-08  3:11 ` Eric Dumazet [this message]
2009-10-08  4:36   ` [PATCH] net: Add netdev_alloc_skb_ip_align() helper Thomas Chou
2009-10-08  5:40   ` David Miller
2009-10-09 16:31     ` Eric Dumazet
2009-10-10  3:43       ` David Miller
2009-10-13 10:45   ` David Miller
2009-10-13 15:34     ` Eric Dumazet
2009-10-13 17:30       ` Stephen Hemminger
2009-10-13 18:06         ` Eric Dumazet
2009-10-13 18:53       ` David Miller

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=4ACD585B.5080106@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nios2-dev@sopc.et.ntust.edu.tw \
    --cc=thierry.reding@avionic-design.de \
    --cc=thomas@wytron.com.tw \
    /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.