Skip to content

Commit

Permalink
net/mlx5e: Use refcount_t for refcount
Browse files Browse the repository at this point in the history
refcount_t is better for reference counters since its
implementation can prevent overflows.
So convert atomic_t ref counters to refcount_t.

Signed-off-by: Chuhong Yuan <[email protected]>
Signed-off-by: Saeed Mahameed <[email protected]>
  • Loading branch information
WillLester authored and Saeed Mahameed committed Aug 9, 2019
1 parent c938451 commit b51c225
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/refcount.h>
#include <linux/mlx5/driver.h>
#include <net/vxlan.h>
#include "mlx5_core.h"
Expand All @@ -48,7 +49,7 @@ struct mlx5_vxlan {

struct mlx5_vxlan_port {
struct hlist_node hlist;
atomic_t refcount;
refcount_t refcount;
u16 udp_port;
};

Expand Down Expand Up @@ -113,7 +114,7 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port)

vxlanp = mlx5_vxlan_lookup_port(vxlan, port);
if (vxlanp) {
atomic_inc(&vxlanp->refcount);
refcount_inc(&vxlanp->refcount);
return 0;
}

Expand All @@ -137,7 +138,7 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port)
}

vxlanp->udp_port = port;
atomic_set(&vxlanp->refcount, 1);
refcount_set(&vxlanp->refcount, 1);

spin_lock_bh(&vxlan->lock);
hash_add(vxlan->htable, &vxlanp->hlist, port);
Expand Down Expand Up @@ -170,7 +171,7 @@ int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port)
goto out_unlock;
}

if (atomic_dec_and_test(&vxlanp->refcount)) {
if (refcount_dec_and_test(&vxlanp->refcount)) {
hash_del(&vxlanp->hlist);
remove = true;
}
Expand Down

0 comments on commit b51c225

Please sign in to comment.