Skip to content

Commit 4b51493

Browse files
emuslndavem330
authored andcommitted
ionic: fix stats memory dereference
When the netdev is down, the queues and their debug stats do not exist, so don't try using a pointer to them when when printing the ethtool stats. Fixes: e470355 ("ionic: Add driver stats") Signed-off-by: Shannon Nelson <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7359db6 commit 4b51493

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

drivers/net/ethernet/pensando/ionic/ionic_lif.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ struct ionic_lif {
182182

183183
#define lif_to_txqcq(lif, i) ((lif)->txqcqs[i].qcq)
184184
#define lif_to_rxqcq(lif, i) ((lif)->rxqcqs[i].qcq)
185+
#define lif_to_txstats(lif, i) ((lif)->txqcqs[i].stats->tx)
186+
#define lif_to_rxstats(lif, i) ((lif)->rxqcqs[i].stats->rx)
185187
#define lif_to_txq(lif, i) (&lif_to_txqcq((lif), i)->q)
186188
#define lif_to_rxq(lif, i) (&lif_to_txqcq((lif), i)->q)
187189

drivers/net/ethernet/pensando/ionic/ionic_stats.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ static u64 ionic_sw_stats_get_count(struct ionic_lif *lif)
117117
/* rx stats */
118118
total += MAX_Q(lif) * IONIC_NUM_RX_STATS;
119119

120-
if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
120+
if (test_bit(IONIC_LIF_UP, lif->state) &&
121+
test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
121122
/* tx debug stats */
122123
total += MAX_Q(lif) * (IONIC_NUM_DBG_CQ_STATS +
123124
IONIC_NUM_TX_Q_STATS +
@@ -149,7 +150,8 @@ static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
149150
*buf += ETH_GSTRING_LEN;
150151
}
151152

152-
if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
153+
if (test_bit(IONIC_LIF_UP, lif->state) &&
154+
test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
153155
for (i = 0; i < IONIC_NUM_TX_Q_STATS; i++) {
154156
snprintf(*buf, ETH_GSTRING_LEN,
155157
"txq_%d_%s",
@@ -187,7 +189,8 @@ static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
187189
*buf += ETH_GSTRING_LEN;
188190
}
189191

190-
if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
192+
if (test_bit(IONIC_LIF_UP, lif->state) &&
193+
test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
191194
for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) {
192195
snprintf(*buf, ETH_GSTRING_LEN,
193196
"rxq_%d_cq_%s",
@@ -223,6 +226,8 @@ static void ionic_sw_stats_get_values(struct ionic_lif *lif, u64 **buf)
223226
{
224227
struct ionic_lif_sw_stats lif_stats;
225228
struct ionic_qcq *txqcq, *rxqcq;
229+
struct ionic_tx_stats *txstats;
230+
struct ionic_rx_stats *rxstats;
226231
int i, q_num;
227232

228233
ionic_get_lif_stats(lif, &lif_stats);
@@ -233,15 +238,17 @@ static void ionic_sw_stats_get_values(struct ionic_lif *lif, u64 **buf)
233238
}
234239

235240
for (q_num = 0; q_num < MAX_Q(lif); q_num++) {
236-
txqcq = lif_to_txqcq(lif, q_num);
241+
txstats = &lif_to_txstats(lif, q_num);
237242

238243
for (i = 0; i < IONIC_NUM_TX_STATS; i++) {
239-
**buf = IONIC_READ_STAT64(&txqcq->stats->tx,
244+
**buf = IONIC_READ_STAT64(txstats,
240245
&ionic_tx_stats_desc[i]);
241246
(*buf)++;
242247
}
243248

244-
if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
249+
if (test_bit(IONIC_LIF_UP, lif->state) &&
250+
test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
251+
txqcq = lif_to_txqcq(lif, q_num);
245252
for (i = 0; i < IONIC_NUM_TX_Q_STATS; i++) {
246253
**buf = IONIC_READ_STAT64(&txqcq->q,
247254
&ionic_txq_stats_desc[i]);
@@ -258,22 +265,24 @@ static void ionic_sw_stats_get_values(struct ionic_lif *lif, u64 **buf)
258265
(*buf)++;
259266
}
260267
for (i = 0; i < IONIC_MAX_NUM_SG_CNTR; i++) {
261-
**buf = txqcq->stats->tx.sg_cntr[i];
268+
**buf = txstats->sg_cntr[i];
262269
(*buf)++;
263270
}
264271
}
265272
}
266273

267274
for (q_num = 0; q_num < MAX_Q(lif); q_num++) {
268-
rxqcq = lif_to_rxqcq(lif, q_num);
275+
rxstats = &lif_to_rxstats(lif, q_num);
269276

270277
for (i = 0; i < IONIC_NUM_RX_STATS; i++) {
271-
**buf = IONIC_READ_STAT64(&rxqcq->stats->rx,
278+
**buf = IONIC_READ_STAT64(rxstats,
272279
&ionic_rx_stats_desc[i]);
273280
(*buf)++;
274281
}
275282

276-
if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
283+
if (test_bit(IONIC_LIF_UP, lif->state) &&
284+
test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) {
285+
rxqcq = lif_to_rxqcq(lif, q_num);
277286
for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) {
278287
**buf = IONIC_READ_STAT64(&rxqcq->cq,
279288
&ionic_dbg_cq_stats_desc[i]);

0 commit comments

Comments
 (0)