Skip to content

Commit 4b4de39

Browse files
WillLesterdavem330
authored andcommitted
mkiss: Use refcount_t for refcount
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: David S. Miller <[email protected]>
1 parent 31168a6 commit 4b4de39

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/net/hamradio/mkiss.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/skbuff.h>
2626
#include <linux/if_arp.h>
2727
#include <linux/jiffies.h>
28+
#include <linux/refcount.h>
2829

2930
#include <net/ax25.h>
3031

@@ -70,7 +71,7 @@ struct mkiss {
7071
#define CRC_MODE_FLEX_TEST 3
7172
#define CRC_MODE_SMACK_TEST 4
7273

73-
atomic_t refcnt;
74+
refcount_t refcnt;
7475
struct completion dead;
7576
};
7677

@@ -668,15 +669,15 @@ static struct mkiss *mkiss_get(struct tty_struct *tty)
668669
read_lock(&disc_data_lock);
669670
ax = tty->disc_data;
670671
if (ax)
671-
atomic_inc(&ax->refcnt);
672+
refcount_inc(&ax->refcnt);
672673
read_unlock(&disc_data_lock);
673674

674675
return ax;
675676
}
676677

677678
static void mkiss_put(struct mkiss *ax)
678679
{
679-
if (atomic_dec_and_test(&ax->refcnt))
680+
if (refcount_dec_and_test(&ax->refcnt))
680681
complete(&ax->dead);
681682
}
682683

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

706707
spin_lock_init(&ax->buflock);
707-
atomic_set(&ax->refcnt, 1);
708+
refcount_set(&ax->refcnt, 1);
708709
init_completion(&ax->dead);
709710

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

0 commit comments

Comments
 (0)