Skip to content

Commit

Permalink
mkiss: 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 <hslester96@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Chuhong Yuan authored and David S. Miller committed Aug 9, 2019
1 parent 31168a6 commit 4b4de39
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions drivers/net/hamradio/mkiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <linux/skbuff.h>
#include <linux/if_arp.h>
#include <linux/jiffies.h>
#include <linux/refcount.h>

#include <net/ax25.h>

Expand Down Expand Up @@ -70,7 +71,7 @@ struct mkiss {
#define CRC_MODE_FLEX_TEST 3
#define CRC_MODE_SMACK_TEST 4

atomic_t refcnt;
refcount_t refcnt;
struct completion dead;
};

Expand Down Expand Up @@ -668,15 +669,15 @@ static struct mkiss *mkiss_get(struct tty_struct *tty)
read_lock(&disc_data_lock);
ax = tty->disc_data;
if (ax)
atomic_inc(&ax->refcnt);
refcount_inc(&ax->refcnt);
read_unlock(&disc_data_lock);

return ax;
}

static void mkiss_put(struct mkiss *ax)
{
if (atomic_dec_and_test(&ax->refcnt))
if (refcount_dec_and_test(&ax->refcnt))
complete(&ax->dead);
}

Expand Down Expand Up @@ -704,7 +705,7 @@ static int mkiss_open(struct tty_struct *tty)
ax->dev = dev;

spin_lock_init(&ax->buflock);
atomic_set(&ax->refcnt, 1);
refcount_set(&ax->refcnt, 1);
init_completion(&ax->dead);

ax->tty = tty;
Expand Down Expand Up @@ -784,7 +785,7 @@ static void mkiss_close(struct tty_struct *tty)
* We have now ensured that nobody can start using ap from now on, but
* we have to wait for all existing users to finish.
*/
if (!atomic_dec_and_test(&ax->refcnt))
if (!refcount_dec_and_test(&ax->refcnt))
wait_for_completion(&ax->dead);
/*
* Halt the transmit queue so that a new transmit cannot scribble
Expand Down

0 comments on commit 4b4de39

Please sign in to comment.