Commit 18eac1cc authored by Linus Torvalds's avatar Linus Torvalds Committed by Greg Kroah-Hartman

tty-ldisc: make refcount be atomic_t 'users' count

This is pure preparation of changing the ldisc reference counting to be
a true refcount that defines the lifetime of the ldisc.  But this is a
purely syntactic change for now to make the next steps easier.

This patch should make no semantic changes at all. But I wanted to make
the ldisc refcount be an atomic (I will be touching it without locks
soon enough), and I wanted to rename it so that there isn't quite as
much confusion between 'ldo->refcount' (ldisk operations refcount) and
'ld->refcount' (ldisc refcount itself) in the same file.

So it's now an atomic 'ld->users' count. It still starts at zero,
despite having a reference from 'tty->ldisc', but that will change once
we turn it into a _real_ refcount.
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Tested-by: default avatarOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Tested-by: default avatarSergey Senozhatsky <sergey.senozhatsky@mail.by>
Acked-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent a33a052f
......@@ -142,7 +142,7 @@ static struct tty_ldisc *tty_ldisc_try_get(int disc)
/* lock it */
ldops->refcount++;
ld->ops = ldops;
ld->refcount = 0;
atomic_set(&ld->users, 0);
err = 0;
}
}
......@@ -206,7 +206,7 @@ static void tty_ldisc_put(struct tty_ldisc *ld)
ldo->refcount--;
module_put(ldo->owner);
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
WARN_ON(ld->refcount);
WARN_ON(atomic_read(&ld->users));
kfree(ld);
}
......@@ -297,7 +297,7 @@ static int tty_ldisc_try(struct tty_struct *tty)
spin_lock_irqsave(&tty_ldisc_lock, flags);
ld = tty->ldisc;
if (test_bit(TTY_LDISC, &tty->flags)) {
ld->refcount++;
atomic_inc(&ld->users);
ret = 1;
}
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
......@@ -324,7 +324,7 @@ struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
{
/* wait_event is a macro */
wait_event(tty_ldisc_wait, tty_ldisc_try(tty));
WARN_ON(tty->ldisc->refcount == 0);
WARN_ON(atomic_read(&tty->ldisc->users) == 0);
return tty->ldisc;
}
EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
......@@ -365,11 +365,9 @@ void tty_ldisc_deref(struct tty_ldisc *ld)
BUG_ON(ld == NULL);
spin_lock_irqsave(&tty_ldisc_lock, flags);
if (ld->refcount == 0)
if (atomic_read(&ld->users) == 0)
printk(KERN_ERR "tty_ldisc_deref: no references.\n");
else
ld->refcount--;
if (ld->refcount == 0)
else if (atomic_dec_and_test(&ld->users))
wake_up(&tty_ldisc_wait);
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
}
......@@ -536,10 +534,10 @@ static int tty_ldisc_wait_idle(struct tty_struct *tty)
{
unsigned long flags;
spin_lock_irqsave(&tty_ldisc_lock, flags);
while (tty->ldisc->refcount) {
while (atomic_read(&tty->ldisc->users)) {
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
if (wait_event_timeout(tty_ldisc_wait,
tty->ldisc->refcount == 0, 5 * HZ) == 0)
atomic_read(&tty->ldisc->users) == 0, 5 * HZ) == 0)
return -EBUSY;
spin_lock_irqsave(&tty_ldisc_lock, flags);
}
......
......@@ -144,7 +144,7 @@ struct tty_ldisc_ops {
struct tty_ldisc {
struct tty_ldisc_ops *ops;
int refcount;
atomic_t users;
};
#define TTY_LDISC_MAGIC 0x5403
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment