[dpdk-dev] virtio: fix crash on querying xstats

Message ID 1466419843-1321-1-git-send-email-yuanhan.liu@linux.intel.com (mailing list archive)
State Accepted, archived
Delegated to: Yuanhan Liu
Headers

Commit Message

Yuanhan Liu June 20, 2016, 10:50 a.m. UTC
  Trying to access xstats_names after "if (stats_names == NULL)" is
obviously wrong, which would result to a crash while running "show
port xstats 0" in testpmd with virtio PMD.

The fix is also straightforward: just revese the check.

Fixes: baf91c395b18 ("net/virtio: fetch extended statistics with integer ids")

Cc: Remy Horton <remy.horton@intel.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 drivers/net/virtio/virtio_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Remy Horton June 20, 2016, 11:02 a.m. UTC | #1
On 20/06/2016 11:50, Yuanhan Liu wrote:
> Trying to access xstats_names after "if (stats_names == NULL)" is
> obviously wrong, which would result to a crash while running "show
> port xstats 0" in testpmd with virtio PMD.
>
> The fix is also straightforward: just revese the check.
>
> Fixes: baf91c395b18 ("net/virtio: fetch extended statistics with integer ids")
>
> Cc: Remy Horton <remy.horton@intel.com>
> Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>

Acked-by: Remy Horton <remy.horton@intel.com>
  
Yuanhan Liu June 20, 2016, 11:47 a.m. UTC | #2
On Mon, Jun 20, 2016 at 12:02:16PM +0100, Remy Horton wrote:
> 
> On 20/06/2016 11:50, Yuanhan Liu wrote:
> >Trying to access xstats_names after "if (stats_names == NULL)" is
> >obviously wrong, which would result to a crash while running "show
> >port xstats 0" in testpmd with virtio PMD.
> >
> >The fix is also straightforward: just revese the check.
> >
> >Fixes: baf91c395b18 ("net/virtio: fetch extended statistics with integer ids")
> >
> >Cc: Remy Horton <remy.horton@intel.com>
> >Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> 
> Acked-by: Remy Horton <remy.horton@intel.com>

Applied to dpdk-next-virtio.

	--yliu
  

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 19d5d8a..12fa640 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -776,7 +776,7 @@  static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
 	unsigned nstats = dev->data->nb_tx_queues * VIRTIO_NB_TXQ_XSTATS +
 		dev->data->nb_rx_queues * VIRTIO_NB_RXQ_XSTATS;
 
-	if (xstats_names == NULL) {
+	if (xstats_names != NULL) {
 		/* Note: limit checked in rte_eth_xstats_names() */
 
 		for (i = 0; i < dev->data->nb_rx_queues; i++) {