Skip to content

Commit c62cd3c

Browse files
Sunil Gouthamdavem330
authored andcommitted
net: thunderx: Fix memory leak when changing queue count
Fix for memory leak when changing queue/channel count via ethtool Signed-off-by: Sunil Goutham <[email protected]> Signed-off-by: Aleksey Makarov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 32c1b96 commit c62cd3c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

drivers/net/ethernet/cavium/thunder/nicvf_ethtool.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static void nicvf_set_msglevel(struct net_device *netdev, u32 lvl)
126126

127127
static void nicvf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
128128
{
129+
struct nicvf *nic = netdev_priv(netdev);
129130
int stats, qidx;
130131

131132
if (sset != ETH_SS_STATS)
@@ -141,15 +142,15 @@ static void nicvf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
141142
data += ETH_GSTRING_LEN;
142143
}
143144

144-
for (qidx = 0; qidx < MAX_RCV_QUEUES_PER_QS; qidx++) {
145+
for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
145146
for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
146147
sprintf(data, "rxq%d: %s", qidx,
147148
nicvf_queue_stats[stats].name);
148149
data += ETH_GSTRING_LEN;
149150
}
150151
}
151152

152-
for (qidx = 0; qidx < MAX_SND_QUEUES_PER_QS; qidx++) {
153+
for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
153154
for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
154155
sprintf(data, "txq%d: %s", qidx,
155156
nicvf_queue_stats[stats].name);
@@ -170,12 +171,14 @@ static void nicvf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
170171

171172
static int nicvf_get_sset_count(struct net_device *netdev, int sset)
172173
{
174+
struct nicvf *nic = netdev_priv(netdev);
175+
173176
if (sset != ETH_SS_STATS)
174177
return -EINVAL;
175178

176179
return nicvf_n_hw_stats + nicvf_n_drv_stats +
177180
(nicvf_n_queue_stats *
178-
(MAX_RCV_QUEUES_PER_QS + MAX_SND_QUEUES_PER_QS)) +
181+
(nic->qs->rq_cnt + nic->qs->sq_cnt)) +
179182
BGX_RX_STATS_COUNT + BGX_TX_STATS_COUNT;
180183
}
181184

@@ -197,13 +200,13 @@ static void nicvf_get_ethtool_stats(struct net_device *netdev,
197200
*(data++) = ((u64 *)&nic->drv_stats)
198201
[nicvf_drv_stats[stat].index];
199202

200-
for (qidx = 0; qidx < MAX_RCV_QUEUES_PER_QS; qidx++) {
203+
for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
201204
for (stat = 0; stat < nicvf_n_queue_stats; stat++)
202205
*(data++) = ((u64 *)&nic->qs->rq[qidx].stats)
203206
[nicvf_queue_stats[stat].index];
204207
}
205208

206-
for (qidx = 0; qidx < MAX_SND_QUEUES_PER_QS; qidx++) {
209+
for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
207210
for (stat = 0; stat < nicvf_n_queue_stats; stat++)
208211
*(data++) = ((u64 *)&nic->qs->sq[qidx].stats)
209212
[nicvf_queue_stats[stat].index];
@@ -543,6 +546,7 @@ static int nicvf_set_channels(struct net_device *dev,
543546
{
544547
struct nicvf *nic = netdev_priv(dev);
545548
int err = 0;
549+
bool if_up = netif_running(dev);
546550

547551
if (!channel->rx_count || !channel->tx_count)
548552
return -EINVAL;
@@ -551,6 +555,9 @@ static int nicvf_set_channels(struct net_device *dev,
551555
if (channel->tx_count > MAX_SND_QUEUES_PER_QS)
552556
return -EINVAL;
553557

558+
if (if_up)
559+
nicvf_stop(dev);
560+
554561
nic->qs->rq_cnt = channel->rx_count;
555562
nic->qs->sq_cnt = channel->tx_count;
556563
nic->qs->cq_cnt = max(nic->qs->rq_cnt, nic->qs->sq_cnt);
@@ -559,11 +566,9 @@ static int nicvf_set_channels(struct net_device *dev,
559566
if (err)
560567
return err;
561568

562-
if (!netif_running(dev))
563-
return err;
569+
if (if_up)
570+
nicvf_open(dev);
564571

565-
nicvf_stop(dev);
566-
nicvf_open(dev);
567572
netdev_info(dev, "Setting num Tx rings to %d, Rx rings to %d success\n",
568573
nic->qs->sq_cnt, nic->qs->rq_cnt);
569574

0 commit comments

Comments
 (0)