Subject: [PATCH] virtio_net: memset scatterlist before using

From: Alex Williamson <[email-masked]>
Date: Fri, 24 Apr 2009 08:37:03 -0600

A powerpc gcc-4.4 build generates the following warnings:

drivers/net/virtio_net.c: In function 'virnet_vlan_rx_add_vid':
include/linux/scatterlist.h:57: warning: 'sg' is used uninitialized in this function
drivers/net/virtio_net.c:746: note: 'sg' was declared here
drivers/net/virtio_net.c: In function 'virnet_vlan_rx_kill_vid':
include/linux/scatterlist.h:57: warning: 'sg' is used uninitialized in this function
drivers/net/virtio_net.c:758: note: 'sg' was declared here

We need to clear the scatterlist before using it.  This sg entry will
get copied into another scatterlist before it's used, so memset it
rather than using sg_init_table or sg_init_one to avoid a bogus end
marker.

Signed-off-by: Alex Williamson <[email-masked]>
--

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 0718558..be1a9fe 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -745,6 +745,7 @@ static void virnet_vlan_rx_add_vid(struct net_device *dev, u16 vid)
 	struct virtnet_info *vi = netdev_priv(dev);
 	struct scatterlist sg;
 
+	memset(&sg, 0, sizeof(sg));
 	sg_set_buf(&sg, &vid, sizeof(vid));
 
 	if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,
@@ -757,6 +758,7 @@ static void virnet_vlan_rx_kill_vid(struct net_device *dev, u16 vid)
 	struct virtnet_info *vi = netdev_priv(dev);
 	struct scatterlist sg;
 
+	memset(&sg, 0, sizeof(sg));
 	sg_set_buf(&sg, &vid, sizeof(vid));
 
 	if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,