diff mbox series

[ovs-dev] netdev-linux: dev_stats should be initialized before used

Message ID 1509180037-13812-1-git-send-email-zhongbaisong@huawei.com
State Changes Requested
Headers show
Series [ovs-dev] netdev-linux: dev_stats should be initialized before used | expand

Commit Message

zhongbaisong Oct. 28, 2017, 8:40 a.m. UTC
From: zhongbasiong <zhongbaisong@huawei.com>

struct netdev_stats dev_stats was used without initialized.
As result, the output of 'ovs-vsctl list interface' has some random
values.

Signed-off-by: zhongbasiong <zhongbaisong@huawei.com>
---
 lib/netdev-linux.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Ben Pfaff Jan. 24, 2018, 3:44 a.m. UTC | #1
On Sat, Oct 28, 2017 at 04:40:37PM +0800, zhongbaisong wrote:
> From: zhongbasiong <zhongbaisong@huawei.com>
> 
> struct netdev_stats dev_stats was used without initialized.
> As result, the output of 'ovs-vsctl list interface' has some random
> values.
> 
> Signed-off-by: zhongbasiong <zhongbaisong@huawei.com>
> ---
>  lib/netdev-linux.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
> index 2ff3e2b..09f174b 100644
> --- a/lib/netdev-linux.c
> +++ b/lib/netdev-linux.c
> @@ -1726,6 +1726,7 @@ netdev_linux_get_stats(const struct netdev *netdev_,
>      int error;
>  
>      ovs_mutex_lock(&netdev->mutex);
> +    memset(&dev_stats, 0, sizeof(struct netdev_stats));
>      get_stats_via_vport(netdev_, stats);
>      error = get_stats_via_netlink(netdev_, &dev_stats);
>      if (error) {
> @@ -1777,6 +1778,7 @@ netdev_tap_get_stats(const struct netdev *netdev_, struct netdev_stats *stats)
>      int error;
>  
>      ovs_mutex_lock(&netdev->mutex);
> +    memset(&dev_stats, 0, sizeof(struct netdev_stats));
>      get_stats_via_vport(netdev_, stats);
>      error = get_stats_via_netlink(netdev_, &dev_stats);
>      if (error) {

Can you help me to understand this better?  The first statement in
get_stats_via_netlink() is
    memset(stats, 0xFF, sizeof(struct netdev_stats));
which would seem to overwrite the zeroing in any case.

Thanks,

Ben.
diff mbox series

Patch

diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 2ff3e2b..09f174b 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -1726,6 +1726,7 @@  netdev_linux_get_stats(const struct netdev *netdev_,
     int error;
 
     ovs_mutex_lock(&netdev->mutex);
+    memset(&dev_stats, 0, sizeof(struct netdev_stats));
     get_stats_via_vport(netdev_, stats);
     error = get_stats_via_netlink(netdev_, &dev_stats);
     if (error) {
@@ -1777,6 +1778,7 @@  netdev_tap_get_stats(const struct netdev *netdev_, struct netdev_stats *stats)
     int error;
 
     ovs_mutex_lock(&netdev->mutex);
+    memset(&dev_stats, 0, sizeof(struct netdev_stats));
     get_stats_via_vport(netdev_, stats);
     error = get_stats_via_netlink(netdev_, &dev_stats);
     if (error) {