@@ -48,10 +48,18 @@ static int spk_ttyio_ldisc_open(struct t
if (tty->ops->write == NULL)
return -EOPNOTSUPP;
+
+ mutex_lock(&speakup_tty_mutex);
+ if (speakup_tty) {
+ mutex_unlock(&speakup_tty_mutex);
+ return -EBUSY;
+ }
speakup_tty = tty;
ldisc_data = kmalloc(sizeof(struct spk_ldisc_data), GFP_KERNEL);
if (!ldisc_data) {
+ speakup_tty = NULL;
+ mutex_unlock(&speakup_tty_mutex);
pr_err("speakup: Failed to allocate ldisc_data.\n");
return -ENOMEM;
}
@@ -59,6 +67,7 @@ static int spk_ttyio_ldisc_open(struct t
sema_init(&ldisc_data->sem, 0);
ldisc_data->buf_free = true;
speakup_tty->disc_data = ldisc_data;
+ mutex_unlock(&speakup_tty_mutex);
return 0;
}