Skip to content

Commit

Permalink
virtio_net: Cleanup command queue scatterlist usage
Browse files Browse the repository at this point in the history
We were avoiding calling sg_init* on scatterlists passed
into virtnet_send_command to prevent extraneous end markers.
This caused build warnings for uninitialized variables.
Cleanup the code to create proper scatterlists.

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Alex Williamson authored and David S. Miller committed May 2, 2009
1 parent 1363d9b commit 23e258e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,11 @@ static int virtnet_open(struct net_device *dev)
static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
struct scatterlist *data, int out, int in)
{
struct scatterlist sg[VIRTNET_SEND_COMMAND_SG_MAX + 2];
struct scatterlist *s, sg[VIRTNET_SEND_COMMAND_SG_MAX + 2];
struct virtio_net_ctrl_hdr ctrl;
virtio_net_ctrl_ack status = ~0;
unsigned int tmp;
int i;

if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) {
BUG(); /* Caller should know better */
Expand All @@ -637,7 +638,8 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
sg_init_table(sg, out + in);

sg_set_buf(&sg[0], &ctrl, sizeof(ctrl));
memcpy(&sg[1], data, sizeof(struct scatterlist) * (out + in - 2));
for_each_sg(data, s, out + in - 2, i)
sg_set_buf(&sg[i + 1], sg_virt(s), s->length);
sg_set_buf(&sg[out + in - 1], &status, sizeof(status));

if (vi->cvq->vq_ops->add_buf(vi->cvq, sg, out, in, vi) != 0)
Expand Down Expand Up @@ -692,15 +694,15 @@ static void virtnet_set_rx_mode(struct net_device *dev)
promisc = ((dev->flags & IFF_PROMISC) != 0);
allmulti = ((dev->flags & IFF_ALLMULTI) != 0);

sg_set_buf(sg, &promisc, sizeof(promisc));
sg_init_one(sg, &promisc, sizeof(promisc));

if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
VIRTIO_NET_CTRL_RX_PROMISC,
sg, 1, 0))
dev_warn(&dev->dev, "Failed to %sable promisc mode.\n",
promisc ? "en" : "dis");

sg_set_buf(sg, &allmulti, sizeof(allmulti));
sg_init_one(sg, &allmulti, sizeof(allmulti));

if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
VIRTIO_NET_CTRL_RX_ALLMULTI,
Expand All @@ -716,6 +718,8 @@ static void virtnet_set_rx_mode(struct net_device *dev)
return;
}

sg_init_table(sg, 2);

/* Store the unicast list and count in the front of the buffer */
mac_data->entries = dev->uc_count;
addr = dev->uc_list;
Expand Down Expand Up @@ -749,7 +753,7 @@ static void virnet_vlan_rx_add_vid(struct net_device *dev, u16 vid)
struct virtnet_info *vi = netdev_priv(dev);
struct scatterlist sg;

sg_set_buf(&sg, &vid, sizeof(vid));
sg_init_one(&sg, &vid, sizeof(vid));

if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,
VIRTIO_NET_CTRL_VLAN_ADD, &sg, 1, 0))
Expand All @@ -761,7 +765,7 @@ static void virnet_vlan_rx_kill_vid(struct net_device *dev, u16 vid)
struct virtnet_info *vi = netdev_priv(dev);
struct scatterlist sg;

sg_set_buf(&sg, &vid, sizeof(vid));
sg_init_one(&sg, &vid, sizeof(vid));

if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,
VIRTIO_NET_CTRL_VLAN_DEL, &sg, 1, 0))
Expand Down

0 comments on commit 23e258e

Please sign in to comment.