Skip to content

Commit

Permalink
IB/hfi1: Fix tstats alloc and dealloc
Browse files Browse the repository at this point in the history
commit e5cce44 upstream.

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 <dennis.dalessandro@cornelisnetworks.com>
Signed-off-by: Mike Marciniszyn <mike.marciniszyn@cornelisnetworks.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Mike Marciniszyn authored and gregkh committed Feb 8, 2022
1 parent 447c3d4 commit c2f79ff
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions drivers/infiniband/hw/hfi1/ipoib_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,35 @@ static int hfi1_ipoib_dev_init(struct net_device *dev)
int ret;

dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
if (!dev->tstats)
return -ENOMEM;

ret = priv->netdev_ops->ndo_init(dev);
if (ret)
return ret;
goto out_ret;

ret = hfi1_netdev_add_data(priv->dd,
qpn_from_mac(priv->netdev->dev_addr),
dev);
if (ret < 0) {
priv->netdev_ops->ndo_uninit(dev);
return ret;
goto out_ret;
}

return 0;
out_ret:
free_percpu(dev->tstats);
dev->tstats = NULL;
return ret;
}

static void hfi1_ipoib_dev_uninit(struct net_device *dev)
{
struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);

free_percpu(dev->tstats);
dev->tstats = NULL;

hfi1_netdev_remove_data(priv->dd, qpn_from_mac(priv->netdev->dev_addr));

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

free_percpu(dev->tstats);
dev->tstats = NULL;
}

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

0 comments on commit c2f79ff

Please sign in to comment.