Patchwork [1/8] virtio-net: replace redundant config_size field with config_len

login
register
mail settings
Submitter Jesse Larrew
Date Feb. 18, 2013, 10:22 p.m.
Message ID <1361226165-19030-2-git-send-email-jlarrew@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/221559/
State New
Headers show

Comments

Jesse Larrew - Feb. 18, 2013, 10:22 p.m.
Commit 14f9b664b34bbd37a488cb5c762aa278c60e1fb6 added a config_size field
to struct VirtIONet. However, struct VirtIONet has an embedded struct
VirtIODevice that already contains a config_len field for this purpose, so
config_size is unnecessary. This patch simply replaces it with
vdev->config_len instead.

Signed-off-by: Jesse Larrew <jlarrew@linux.vnet.ibm.com>
---
 hw/virtio-net.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Anthony Liguori - Feb. 19, 2013, 8:36 p.m.
Jesse Larrew <jlarrew@linux.vnet.ibm.com> writes:

> Commit 14f9b664b34bbd37a488cb5c762aa278c60e1fb6 added a config_size field
> to struct VirtIONet. However, struct VirtIONet has an embedded struct
> VirtIODevice that already contains a config_len field for this purpose, so
> config_size is unnecessary. This patch simply replaces it with
> vdev->config_len instead.
>
> Signed-off-by: Jesse Larrew <jlarrew@linux.vnet.ibm.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>  hw/virtio-net.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/hw/virtio-net.c b/hw/virtio-net.c
> index 573c669..bdbfc18 100644
> --- a/hw/virtio-net.c
> +++ b/hw/virtio-net.c
> @@ -73,7 +73,6 @@ typedef struct VirtIONet
>      int multiqueue;
>      uint16_t max_queues;
>      uint16_t curr_queues;
> -    size_t config_size;
>  } VirtIONet;
>  
>  /*
> @@ -127,7 +126,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
>      stw_p(&netcfg.status, n->status);
>      stw_p(&netcfg.max_virtqueue_pairs, n->max_queues);
>      memcpy(netcfg.mac, n->mac, ETH_ALEN);
> -    memcpy(config, &netcfg, n->config_size);
> +    memcpy(config, &netcfg, vdev->config_len);
>  }
>  
>  static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
> @@ -135,7 +134,7 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
>      VirtIONet *n = to_virtio_net(vdev);
>      struct virtio_net_config netcfg = {};
>  
> -    memcpy(&netcfg, config, n->config_size);
> +    memcpy(&netcfg, config, vdev->config_len);
>  
>      if (!(n->vdev.guest_features >> VIRTIO_NET_F_CTRL_MAC_ADDR & 1) &&
>          memcmp(netcfg.mac, n->mac, ETH_ALEN)) {
> @@ -1316,7 +1315,6 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
>      n = (VirtIONet *)virtio_common_init("virtio-net", VIRTIO_ID_NET,
>                                          config_size, sizeof(VirtIONet));
>  
> -    n->config_size = config_size;
>      n->vdev.get_config = virtio_net_get_config;
>      n->vdev.set_config = virtio_net_set_config;
>      n->vdev.get_features = virtio_net_get_features;
> -- 
> 1.7.11.7

Patch

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 573c669..bdbfc18 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -73,7 +73,6 @@  typedef struct VirtIONet
     int multiqueue;
     uint16_t max_queues;
     uint16_t curr_queues;
-    size_t config_size;
 } VirtIONet;
 
 /*
@@ -127,7 +126,7 @@  static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
     stw_p(&netcfg.status, n->status);
     stw_p(&netcfg.max_virtqueue_pairs, n->max_queues);
     memcpy(netcfg.mac, n->mac, ETH_ALEN);
-    memcpy(config, &netcfg, n->config_size);
+    memcpy(config, &netcfg, vdev->config_len);
 }
 
 static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
@@ -135,7 +134,7 @@  static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
     VirtIONet *n = to_virtio_net(vdev);
     struct virtio_net_config netcfg = {};
 
-    memcpy(&netcfg, config, n->config_size);
+    memcpy(&netcfg, config, vdev->config_len);
 
     if (!(n->vdev.guest_features >> VIRTIO_NET_F_CTRL_MAC_ADDR & 1) &&
         memcmp(netcfg.mac, n->mac, ETH_ALEN)) {
@@ -1316,7 +1315,6 @@  VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
     n = (VirtIONet *)virtio_common_init("virtio-net", VIRTIO_ID_NET,
                                         config_size, sizeof(VirtIONet));
 
-    n->config_size = config_size;
     n->vdev.get_config = virtio_net_get_config;
     n->vdev.set_config = virtio_net_set_config;
     n->vdev.get_features = virtio_net_get_features;