From: Joe Perches <joe@perches.com>
To: David Miller <davem@davemloft.net>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH] net: af_packet: Don't initialize vnet_hdr
Date: Thu, 12 May 2011 14:55:48 -0700 [thread overview]
Message-ID: <1305237348.6124.72.camel@Joe-Laptop> (raw)
In-Reply-To: <20110512.173608.1652572492952866283.davem@davemloft.net>
Save an initialization because when this structure
is used it's completely filled by memcpy_fromiovec.
Add a new variable used for the 0 sized allocation
when this structure is not used.
Signed-off-by: Joe Perches <joe@perches.com>
---
On Thu, 2011-05-12 at 17:36 -0400, David Miller wrote:
> I would rather see the code rearranged such that this sort of
> hackish scheme isn't necessary.
net/packet/af_packet.c | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 549527b..cc1e83d 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1123,9 +1123,10 @@ static int packet_snd(struct socket *sock,
__be16 proto;
unsigned char *addr;
int ifindex, err, reserve = 0;
- struct virtio_net_hdr vnet_hdr = { 0 };
+ struct virtio_net_hdr vnet_hdr;
int offset = 0;
int vnet_hdr_len;
+ size_t alloc_vnet_hdr_len;
struct packet_sock *po = pkt_sk(sk);
unsigned short gso_type = 0;
@@ -1206,7 +1207,10 @@ static int packet_snd(struct socket *sock,
goto out_unlock;
}
- }
+ alloc_vnet_hdr_len = vnet_hdr.hdr_len;
+ } else
+ alloc_vnet_hdr_len = 0;
+
err = -EMSGSIZE;
if (!gso_type && (len > dev->mtu + reserve + VLAN_HLEN))
@@ -1214,7 +1218,7 @@ static int packet_snd(struct socket *sock,
err = -ENOBUFS;
skb = packet_alloc_skb(sk, LL_ALLOCATED_SPACE(dev),
- LL_RESERVED_SPACE(dev), len, vnet_hdr.hdr_len,
+ LL_RESERVED_SPACE(dev), len, alloc_vnet_hdr_len,
msg->msg_flags & MSG_DONTWAIT, &err);
if (skb == NULL)
goto out_unlock;
next prev parent reply other threads:[~2011-05-12 21:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-12 20:36 [PATCH] net: af_packet: Don't initialize vnet_hdr Joe Perches
2011-05-12 21:26 ` David Miller
2011-05-12 21:33 ` Joe Perches
2011-05-12 21:36 ` David Miller
2011-05-12 21:55 ` Joe Perches [this message]
2011-05-12 21:59 ` David Miller
2011-05-12 23:25 ` [PATCH net-next V3] net: af_packet: Untangle packet_snd by adding vpacket_snd Joe Perches
2011-05-13 5:11 ` Eric Dumazet
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=1305237348.6124.72.camel@Joe-Laptop \
--to=joe@perches.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox