diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-08-03 13:58:29 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-08-04 16:46:30 -0400 |
commit | 18eac1cc100fa2afd5f39085aae6b694e417734b (patch) | |
tree | 52ac69ef9832c77a0c6865f9eff39dd4f287776e /drivers/char/tty_ldisc.c | |
parent | a33a052f19a21d727847391c8c1aff3fb221c472 (diff) |
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: Linus Torvalds <torvalds@linux-foundation.org>
Tested-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Tested-by: Sergey Senozhatsky <sergey.senozhatsky@mail.by>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/char/tty_ldisc.c')
-rw-r--r-- | drivers/char/tty_ldisc.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c index acd76b767d4c..fd175e60aad5 100644 --- a/drivers/char/tty_ldisc.c +++ b/drivers/char/tty_ldisc.c | |||
@@ -142,7 +142,7 @@ static struct tty_ldisc *tty_ldisc_try_get(int disc) | |||
142 | /* lock it */ | 142 | /* lock it */ |
143 | ldops->refcount++; | 143 | ldops->refcount++; |
144 | ld->ops = ldops; | 144 | ld->ops = ldops; |
145 | ld->refcount = 0; | 145 | atomic_set(&ld->users, 0); |
146 | err = 0; | 146 | err = 0; |
147 | } | 147 | } |
148 | } | 148 | } |
@@ -206,7 +206,7 @@ static void tty_ldisc_put(struct tty_ldisc *ld) | |||
206 | ldo->refcount--; | 206 | ldo->refcount--; |
207 | module_put(ldo->owner); | 207 | module_put(ldo->owner); |
208 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 208 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
209 | WARN_ON(ld->refcount); | 209 | WARN_ON(atomic_read(&ld->users)); |
210 | kfree(ld); | 210 | kfree(ld); |
211 | } | 211 | } |
212 | 212 | ||
@@ -297,7 +297,7 @@ static int tty_ldisc_try(struct tty_struct *tty) | |||
297 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 297 | spin_lock_irqsave(&tty_ldisc_lock, flags); |
298 | ld = tty->ldisc; | 298 | ld = tty->ldisc; |
299 | if (test_bit(TTY_LDISC, &tty->flags)) { | 299 | if (test_bit(TTY_LDISC, &tty->flags)) { |
300 | ld->refcount++; | 300 | atomic_inc(&ld->users); |
301 | ret = 1; | 301 | ret = 1; |
302 | } | 302 | } |
303 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 303 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
@@ -324,7 +324,7 @@ struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) | |||
324 | { | 324 | { |
325 | /* wait_event is a macro */ | 325 | /* wait_event is a macro */ |
326 | wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); | 326 | wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); |
327 | WARN_ON(tty->ldisc->refcount == 0); | 327 | WARN_ON(atomic_read(&tty->ldisc->users) == 0); |
328 | return tty->ldisc; | 328 | return tty->ldisc; |
329 | } | 329 | } |
330 | EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); | 330 | EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); |
@@ -365,11 +365,9 @@ void tty_ldisc_deref(struct tty_ldisc *ld) | |||
365 | BUG_ON(ld == NULL); | 365 | BUG_ON(ld == NULL); |
366 | 366 | ||
367 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 367 | spin_lock_irqsave(&tty_ldisc_lock, flags); |
368 | if (ld->refcount == 0) | 368 | if (atomic_read(&ld->users) == 0) |
369 | printk(KERN_ERR "tty_ldisc_deref: no references.\n"); | 369 | printk(KERN_ERR "tty_ldisc_deref: no references.\n"); |
370 | else | 370 | else if (atomic_dec_and_test(&ld->users)) |
371 | ld->refcount--; | ||
372 | if (ld->refcount == 0) | ||
373 | wake_up(&tty_ldisc_wait); | 371 | wake_up(&tty_ldisc_wait); |
374 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 372 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
375 | } | 373 | } |
@@ -536,10 +534,10 @@ static int tty_ldisc_wait_idle(struct tty_struct *tty) | |||
536 | { | 534 | { |
537 | unsigned long flags; | 535 | unsigned long flags; |
538 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 536 | spin_lock_irqsave(&tty_ldisc_lock, flags); |
539 | while (tty->ldisc->refcount) { | 537 | while (atomic_read(&tty->ldisc->users)) { |
540 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); | 538 | spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
541 | if (wait_event_timeout(tty_ldisc_wait, | 539 | if (wait_event_timeout(tty_ldisc_wait, |
542 | tty->ldisc->refcount == 0, 5 * HZ) == 0) | 540 | atomic_read(&tty->ldisc->users) == 0, 5 * HZ) == 0) |
543 | return -EBUSY; | 541 | return -EBUSY; |
544 | spin_lock_irqsave(&tty_ldisc_lock, flags); | 542 | spin_lock_irqsave(&tty_ldisc_lock, flags); |
545 | } | 543 | } |