DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] librte_ether: fix crashes in rte_ethdev functions.
@ 2015-12-17 17:23 Bernard Iremonger
  2015-12-21  9:03 ` Qiu, Michael
  0 siblings, 1 reply; 5+ messages in thread
From: Bernard Iremonger @ 2015-12-17 17:23 UTC (permalink / raw)
  To: dev

The nb_rx_queues and nb_tx_queues are initialised before
the tx_queue and rx_queue arrays are allocated. The arrays
are allocated when the ethdev port is started.

If any of the following functions are called before the ethdev
port is started there is a segmentation fault:

rte_eth_stats_get
rte_eth_stats_reset
rte_eth_xstats_get
rte_eth_xstats_reset

Fixes: af75078fece3 ("first public release")
Fixes: ce757f5c9a4d ("ethdev: new method to retrieve extended statistics")
Fixes: d4fef8b0d5e5 ("ethdev: expose generic and driver specific stats in xstats")
Signed-off-by: Bernard Iremonger <bernard.iremonger@intel.com>
---
 lib/librte_ether/rte_ethdev.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index ed971b4..a0ee84d 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1441,7 +1441,10 @@ rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
 	memset(stats, 0, sizeof(*stats));
 
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
-	(*dev->dev_ops->stats_get)(dev, stats);
+
+	if (dev->data->dev_started)
+		(*dev->dev_ops->stats_get)(dev, stats);
+
 	stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
 	return 0;
 }
@@ -1455,7 +1458,10 @@ rte_eth_stats_reset(uint8_t port_id)
 	dev = &rte_eth_devices[port_id];
 
 	RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
-	(*dev->dev_ops->stats_reset)(dev);
+
+	if (dev->data->dev_started)
+		(*dev->dev_ops->stats_reset)(dev);
+
 	dev->data->rx_mbuf_alloc_failed = 0;
 }
 
@@ -1479,7 +1485,8 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 		(dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
 
 	/* implemented by the driver */
-	if (dev->dev_ops->xstats_get != NULL) {
+	if ((dev->dev_ops->xstats_get != NULL) &&
+		(dev->data->dev_started)) {
 		/* Retrieve the xstats from the driver at the end of the
 		 * xstats struct.
 		 */
@@ -1548,7 +1555,8 @@ rte_eth_xstats_reset(uint8_t port_id)
 	dev = &rte_eth_devices[port_id];
 
 	/* implemented by the driver */
-	if (dev->dev_ops->xstats_reset != NULL) {
+	if ((dev->dev_ops->xstats_reset != NULL) &&
+		(dev->data->dev_started)) {
 		(*dev->dev_ops->xstats_reset)(dev);
 		return;
 	}
-- 
2.6.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-12-21 15:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-17 17:23 [dpdk-dev] [PATCH] librte_ether: fix crashes in rte_ethdev functions Bernard Iremonger
2015-12-21  9:03 ` Qiu, Michael
2015-12-21 11:40   ` Iremonger, Bernard
2015-12-21 12:01     ` Ananyev, Konstantin
2015-12-21 15:01       ` Iremonger, Bernard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).