tty: drop tty_ldisc_ops::refcount

The refcount is checked only in tty_unregister_ldisc and EBUSY returned
if it is nonzero. But none of the tty_unregister_ldisc callers act
anyhow if this (or any other) error is returned. So remove
tty_ldisc_ops::refcount completely and make tty_unregister_ldisc return
'void' in the next patches. That means we assume tty_unregister_ldisc is
not called while the ldisc might be in use. That relies on
try_module_get in get_ldops and module_put in put_ldops.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210505091928.22010-18-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Jiri Slaby 2021-05-05 11:19:10 +02:00 committed by Greg Kroah-Hartman
parent f81ee8b8b8
commit 1947520933
3 changed files with 4 additions and 14 deletions

View File

@ -2450,7 +2450,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
{ {
*ops = n_tty_ops; *ops = n_tty_ops;
ops->owner = NULL; ops->owner = NULL;
ops->refcount = ops->flags = 0; ops->flags = 0;
} }
EXPORT_SYMBOL_GPL(n_tty_inherit_ops); EXPORT_SYMBOL_GPL(n_tty_inherit_ops);

View File

@ -69,7 +69,6 @@ int tty_register_ldisc(struct tty_ldisc_ops *new_ldisc)
raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
tty_ldiscs[new_ldisc->num] = new_ldisc; tty_ldiscs[new_ldisc->num] = new_ldisc;
new_ldisc->refcount = 0;
raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
return ret; return ret;
@ -90,16 +89,12 @@ EXPORT_SYMBOL(tty_register_ldisc);
int tty_unregister_ldisc(struct tty_ldisc_ops *ldisc) int tty_unregister_ldisc(struct tty_ldisc_ops *ldisc)
{ {
unsigned long flags; unsigned long flags;
int ret = 0;
raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
if (tty_ldiscs[ldisc->num]->refcount) tty_ldiscs[ldisc->num] = NULL;
ret = -EBUSY;
else
tty_ldiscs[ldisc->num] = NULL;
raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
return ret; return 0;
} }
EXPORT_SYMBOL(tty_unregister_ldisc); EXPORT_SYMBOL(tty_unregister_ldisc);
@ -113,10 +108,8 @@ static struct tty_ldisc_ops *get_ldops(int disc)
ldops = tty_ldiscs[disc]; ldops = tty_ldiscs[disc];
if (ldops) { if (ldops) {
ret = ERR_PTR(-EAGAIN); ret = ERR_PTR(-EAGAIN);
if (try_module_get(ldops->owner)) { if (try_module_get(ldops->owner))
ldops->refcount++;
ret = ldops; ret = ldops;
}
} }
raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
return ret; return ret;
@ -127,7 +120,6 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
unsigned long flags; unsigned long flags;
raw_spin_lock_irqsave(&tty_ldiscs_lock, flags); raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
ldops->refcount--;
module_put(ldops->owner); module_put(ldops->owner);
raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags); raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
} }

View File

@ -208,8 +208,6 @@ struct tty_ldisc_ops {
const char *fp, int count); const char *fp, int count);
struct module *owner; struct module *owner;
int refcount;
}; };
struct tty_ldisc { struct tty_ldisc {