Commit 46324511 authored by Jan Kiszka's avatar Jan Kiszka Committed by David S. Miller

CAPI: Establish install/cleanup handlers for capiminor TTYs

Properly associate/disassociate a capiminor object with its TTY via the
install/cleanup handlers instead of trying to guess first open and last
close.
Signed-off-by: default avatarJan Kiszka <jan.kiszka@web.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0159d549
...@@ -1005,16 +1005,34 @@ static const struct file_operations capi_fops = ...@@ -1005,16 +1005,34 @@ static const struct file_operations capi_fops =
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
/* -------- tty_operations for capincci ----------------------------- */ /* -------- tty_operations for capincci ----------------------------- */
static int capinc_tty_open(struct tty_struct * tty, struct file * file) static int
capinc_tty_install(struct tty_driver *driver, struct tty_struct *tty)
{ {
struct capiminor *mp; int idx = tty->index;
unsigned long flags; struct capiminor *mp = capiminor_get(idx);
int ret = tty_init_termios(tty);
if (ret == 0) {
tty_driver_kref_get(driver);
tty->count++;
tty->driver_data = mp;
driver->ttys[idx] = tty;
} else
capiminor_put(mp);
return ret;
}
mp = capiminor_get(iminor(file->f_path.dentry->d_inode)); static void capinc_tty_cleanup(struct tty_struct *tty)
if (mp->nccip == NULL) {
return -ENXIO; struct capiminor *mp = tty->driver_data;
tty->driver_data = NULL;
capiminor_put(mp);
}
tty->driver_data = (void *)mp; static int capinc_tty_open(struct tty_struct * tty, struct file * file)
{
struct capiminor *mp = tty->driver_data;
unsigned long flags;
spin_lock_irqsave(&workaround_lock, flags); spin_lock_irqsave(&workaround_lock, flags);
if (atomic_read(&mp->ttyopencount) == 0) if (atomic_read(&mp->ttyopencount) == 0)
...@@ -1030,15 +1048,12 @@ static int capinc_tty_open(struct tty_struct * tty, struct file * file) ...@@ -1030,15 +1048,12 @@ static int capinc_tty_open(struct tty_struct * tty, struct file * file)
static void capinc_tty_close(struct tty_struct * tty, struct file * file) static void capinc_tty_close(struct tty_struct * tty, struct file * file)
{ {
struct capiminor *mp; struct capiminor *mp = tty->driver_data;
mp = (struct capiminor *)tty->driver_data;
if (mp) {
if (atomic_dec_and_test(&mp->ttyopencount)) { if (atomic_dec_and_test(&mp->ttyopencount)) {
#ifdef _DEBUG_REFCOUNT #ifdef _DEBUG_REFCOUNT
printk(KERN_DEBUG "capinc_tty_close lastclose\n"); printk(KERN_DEBUG "capinc_tty_close lastclose\n");
#endif #endif
tty->driver_data = NULL;
mp->tty = NULL; mp->tty = NULL;
} }
#ifdef _DEBUG_REFCOUNT #ifdef _DEBUG_REFCOUNT
...@@ -1047,9 +1062,6 @@ static void capinc_tty_close(struct tty_struct * tty, struct file * file) ...@@ -1047,9 +1062,6 @@ static void capinc_tty_close(struct tty_struct * tty, struct file * file)
if (mp->nccip == NULL) if (mp->nccip == NULL)
capiminor_free(mp); capiminor_free(mp);
capiminor_put(mp);
}
#ifdef _DEBUG_REFCOUNT #ifdef _DEBUG_REFCOUNT
printk(KERN_DEBUG "capinc_tty_close\n"); printk(KERN_DEBUG "capinc_tty_close\n");
#endif #endif
...@@ -1333,6 +1345,8 @@ static const struct tty_operations capinc_ops = { ...@@ -1333,6 +1345,8 @@ static const struct tty_operations capinc_ops = {
.flush_buffer = capinc_tty_flush_buffer, .flush_buffer = capinc_tty_flush_buffer,
.set_ldisc = capinc_tty_set_ldisc, .set_ldisc = capinc_tty_set_ldisc,
.send_xchar = capinc_tty_send_xchar, .send_xchar = capinc_tty_send_xchar,
.install = capinc_tty_install,
.cleanup = capinc_tty_cleanup,
}; };
static int __init capinc_tty_init(void) static int __init capinc_tty_init(void)
......
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