IPoIB: Fix address handle refcounting for multicast groups

Multiple ipoib_neigh structures on mcast->neigh_list may point to the
same ah. This means that ipoib_mcast_free() can't just make a list of
ah structs to free, since this might end up trying to add the same ah
to the list more than once. Handle this in ipoib_multicast.c in the
same way as it is handled in ipoib_main.c for struct ipoib_path.

Signed-off-by: Eli Cohen <eli@mellanox.co.il>
Signed-off-by: Michael S. Tsirkin <mst@mellanox.co.il>
Signed-off-by: Roland Dreier <rolandd@cisco.com>

authored by

Eli Cohen and committed by
Roland Dreier
97460df3 70b4c8cd

+7 -6
+7 -6
drivers/infiniband/ulp/ipoib/ipoib_multicast.c
··· 97 97 struct ipoib_dev_priv *priv = netdev_priv(dev); 98 98 struct ipoib_neigh *neigh, *tmp; 99 99 unsigned long flags; 100 - LIST_HEAD(ah_list); 101 - struct ipoib_ah *ah, *tah; 102 100 103 101 ipoib_dbg_mcast(netdev_priv(dev), 104 102 "deleting multicast group " IPOIB_GID_FMT "\n", ··· 105 107 spin_lock_irqsave(&priv->lock, flags); 106 108 107 109 list_for_each_entry_safe(neigh, tmp, &mcast->neigh_list, list) { 110 + /* 111 + * It's safe to call ipoib_put_ah() inside priv->lock 112 + * here, because we know that mcast->ah will always 113 + * hold one more reference, so ipoib_put_ah() will 114 + * never do more than decrement the ref count. 115 + */ 108 116 if (neigh->ah) 109 - list_add_tail(&neigh->ah->list, &ah_list); 117 + ipoib_put_ah(neigh->ah); 110 118 *to_ipoib_neigh(neigh->neighbour) = NULL; 111 119 neigh->neighbour->ops->destructor = NULL; 112 120 kfree(neigh); 113 121 } 114 122 115 123 spin_unlock_irqrestore(&priv->lock, flags); 116 - 117 - list_for_each_entry_safe(ah, tah, &ah_list, list) 118 - ipoib_put_ah(ah); 119 124 120 125 if (mcast->ah) 121 126 ipoib_put_ah(mcast->ah);