aquantia: Fix "ethtool -S" crash when adapter down.
authorPavel Belous <pavel.belous@aquantia.com>
Thu, 4 May 2017 20:10:56 +0000 (23:10 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 8 May 2017 16:53:12 +0000 (12:53 -0400)
This patch fixes the crash that happens when driver tries to collect statistics
from already released "aq_vec" object.
If adapter is in "down" state we still allow user to see statistics from HW.

V2: fixed braces around "aq_vec_free".

Fixes: 97bde5c4f909 ("net: ethernet: aquantia: Support for NIC-specific code")
Signed-off-by: Pavel Belous <pavel.belous@aquantia.com>
Tested-by: David Arcari <darcari@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/aquantia/atlantic/aq_nic.c

index cdb02991f249c6354b7095d9d777316617c2be42..9ee1c501678409719f460912c6316b803c2dc7fc 100644 (file)
@@ -755,7 +755,7 @@ void aq_nic_get_stats(struct aq_nic_s *self, u64 *data)
        count = 0U;
 
        for (i = 0U, aq_vec = self->aq_vec[0];
-               self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i]) {
+               aq_vec && self->aq_vecs > i; ++i, aq_vec = self->aq_vec[i]) {
                data += count;
                aq_vec_get_sw_stats(aq_vec, data, &count);
        }
@@ -959,8 +959,10 @@ void aq_nic_free_hot_resources(struct aq_nic_s *self)
                goto err_exit;
 
        for (i = AQ_DIMOF(self->aq_vec); i--;) {
-               if (self->aq_vec[i])
+               if (self->aq_vec[i]) {
                        aq_vec_free(self->aq_vec[i]);
+                       self->aq_vec[i] = NULL;
+               }
        }
 
 err_exit:;