Skip to content

Commit e5cce44

Browse files
Mike Marciniszynjgunthorpe
authored andcommitted
IB/hfi1: Fix tstats alloc and dealloc
The tstats allocation is done in the accelerated ndo_init function but the allocation is not tested to succeed. The deallocation is not done in the accelerated ndo_uninit function. Resolve issues by testing for an allocation failure and adding the free_percpu in the uninit function. Fixes: aa0616a ("IB/hfi1: switch to core handling of rx/tx byte/packet counters") Link: https://lore.kernel.org/r/1642287756-182313-5-git-send-email-mike.marciniszyn@cornelisnetworks.com Reviewed-by: Dennis Dalessandro <[email protected]> Signed-off-by: Mike Marciniszyn <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 5f8f55b commit e5cce44

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/infiniband/hw/hfi1/ipoib_main.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,35 @@ static int hfi1_ipoib_dev_init(struct net_device *dev)
2222
int ret;
2323

2424
dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
25+
if (!dev->tstats)
26+
return -ENOMEM;
2527

2628
ret = priv->netdev_ops->ndo_init(dev);
2729
if (ret)
28-
return ret;
30+
goto out_ret;
2931

3032
ret = hfi1_netdev_add_data(priv->dd,
3133
qpn_from_mac(priv->netdev->dev_addr),
3234
dev);
3335
if (ret < 0) {
3436
priv->netdev_ops->ndo_uninit(dev);
35-
return ret;
37+
goto out_ret;
3638
}
3739

3840
return 0;
41+
out_ret:
42+
free_percpu(dev->tstats);
43+
dev->tstats = NULL;
44+
return ret;
3945
}
4046

4147
static void hfi1_ipoib_dev_uninit(struct net_device *dev)
4248
{
4349
struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);
4450

51+
free_percpu(dev->tstats);
52+
dev->tstats = NULL;
53+
4554
hfi1_netdev_remove_data(priv->dd, qpn_from_mac(priv->netdev->dev_addr));
4655

4756
priv->netdev_ops->ndo_uninit(dev);
@@ -166,6 +175,7 @@ static void hfi1_ipoib_netdev_dtor(struct net_device *dev)
166175
hfi1_ipoib_rxq_deinit(priv->netdev);
167176

168177
free_percpu(dev->tstats);
178+
dev->tstats = NULL;
169179
}
170180

171181
static void hfi1_ipoib_set_id(struct net_device *dev, int id)

0 commit comments

Comments
 (0)