|
@@ -581,8 +581,9 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
|
|
__u8 __user *buf, size_t nr)
|
|
__u8 __user *buf, size_t nr)
|
|
{
|
|
{
|
|
struct n_hdlc *n_hdlc = tty2n_hdlc(tty);
|
|
struct n_hdlc *n_hdlc = tty2n_hdlc(tty);
|
|
- int ret;
|
|
|
|
|
|
+ int ret = 0;
|
|
struct n_hdlc_buf *rbuf;
|
|
struct n_hdlc_buf *rbuf;
|
|
|
|
+ DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
|
if (debuglevel >= DEBUG_LEVEL_INFO)
|
|
if (debuglevel >= DEBUG_LEVEL_INFO)
|
|
printk("%s(%d)n_hdlc_tty_read() called\n",__FILE__,__LINE__);
|
|
printk("%s(%d)n_hdlc_tty_read() called\n",__FILE__,__LINE__);
|
|
@@ -598,57 +599,55 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
|
|
return -EFAULT;
|
|
return -EFAULT;
|
|
}
|
|
}
|
|
|
|
|
|
- tty_lock();
|
|
|
|
|
|
+ add_wait_queue(&tty->read_wait, &wait);
|
|
|
|
|
|
for (;;) {
|
|
for (;;) {
|
|
if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
|
|
if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
|
|
- tty_unlock();
|
|
|
|
- return -EIO;
|
|
|
|
|
|
+ ret = -EIO;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
+ if (tty_hung_up_p(file))
|
|
|
|
+ break;
|
|
|
|
|
|
- n_hdlc = tty2n_hdlc (tty);
|
|
|
|
- if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC ||
|
|
|
|
- tty != n_hdlc->tty) {
|
|
|
|
- tty_unlock();
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
|
|
+ set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
|
|
rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list);
|
|
rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list);
|
|
- if (rbuf)
|
|
|
|
|
|
+ if (rbuf) {
|
|
|
|
+ if (rbuf->count > nr) {
|
|
|
|
+ /* too large for caller's buffer */
|
|
|
|
+ ret = -EOVERFLOW;
|
|
|
|
+ } else {
|
|
|
|
+ if (copy_to_user(buf, rbuf->buf, rbuf->count))
|
|
|
|
+ ret = -EFAULT;
|
|
|
|
+ else
|
|
|
|
+ ret = rbuf->count;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (n_hdlc->rx_free_buf_list.count >
|
|
|
|
+ DEFAULT_RX_BUF_COUNT)
|
|
|
|
+ kfree(rbuf);
|
|
|
|
+ else
|
|
|
|
+ n_hdlc_buf_put(&n_hdlc->rx_free_buf_list, rbuf);
|
|
break;
|
|
break;
|
|
|
|
+ }
|
|
|
|
|
|
/* no data */
|
|
/* no data */
|
|
if (file->f_flags & O_NONBLOCK) {
|
|
if (file->f_flags & O_NONBLOCK) {
|
|
- tty_unlock();
|
|
|
|
- return -EAGAIN;
|
|
|
|
|
|
+ ret = -EAGAIN;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
-
|
|
|
|
- interruptible_sleep_on (&tty->read_wait);
|
|
|
|
|
|
+
|
|
|
|
+ schedule();
|
|
|
|
+
|
|
if (signal_pending(current)) {
|
|
if (signal_pending(current)) {
|
|
- tty_unlock();
|
|
|
|
- return -EINTR;
|
|
|
|
|
|
+ ret = -EINTR;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (rbuf->count > nr)
|
|
|
|
- /* frame too large for caller's buffer (discard frame) */
|
|
|
|
- ret = -EOVERFLOW;
|
|
|
|
- else {
|
|
|
|
- /* Copy the data to the caller's buffer */
|
|
|
|
- if (copy_to_user(buf, rbuf->buf, rbuf->count))
|
|
|
|
- ret = -EFAULT;
|
|
|
|
- else
|
|
|
|
- ret = rbuf->count;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /* return HDLC buffer to free list unless the free list */
|
|
|
|
- /* count has exceeded the default value, in which case the */
|
|
|
|
- /* buffer is freed back to the OS to conserve memory */
|
|
|
|
- if (n_hdlc->rx_free_buf_list.count > DEFAULT_RX_BUF_COUNT)
|
|
|
|
- kfree(rbuf);
|
|
|
|
- else
|
|
|
|
- n_hdlc_buf_put(&n_hdlc->rx_free_buf_list,rbuf);
|
|
|
|
- tty_unlock();
|
|
|
|
|
|
+
|
|
|
|
+ remove_wait_queue(&tty->read_wait, &wait);
|
|
|
|
+ __set_current_state(TASK_RUNNING);
|
|
|
|
+
|
|
return ret;
|
|
return ret;
|
|
|
|
|
|
} /* end of n_hdlc_tty_read() */
|
|
} /* end of n_hdlc_tty_read() */
|
|
@@ -691,14 +690,15 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
|
|
count = maxframe;
|
|
count = maxframe;
|
|
}
|
|
}
|
|
|
|
|
|
- tty_lock();
|
|
|
|
-
|
|
|
|
add_wait_queue(&tty->write_wait, &wait);
|
|
add_wait_queue(&tty->write_wait, &wait);
|
|
- set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
|
|
+
|
|
|
|
+ for (;;) {
|
|
|
|
+ set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
|
|
- /* Allocate transmit buffer */
|
|
|
|
- /* sleep until transmit buffer available */
|
|
|
|
- while (!(tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list))) {
|
|
|
|
|
|
+ tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list);
|
|
|
|
+ if (tbuf)
|
|
|
|
+ break;
|
|
|
|
+
|
|
if (file->f_flags & O_NONBLOCK) {
|
|
if (file->f_flags & O_NONBLOCK) {
|
|
error = -EAGAIN;
|
|
error = -EAGAIN;
|
|
break;
|
|
break;
|
|
@@ -719,7 +719,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- set_current_state(TASK_RUNNING);
|
|
|
|
|
|
+ __set_current_state(TASK_RUNNING);
|
|
remove_wait_queue(&tty->write_wait, &wait);
|
|
remove_wait_queue(&tty->write_wait, &wait);
|
|
|
|
|
|
if (!error) {
|
|
if (!error) {
|
|
@@ -731,7 +731,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
|
|
n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf);
|
|
n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf);
|
|
n_hdlc_send_frames(n_hdlc,tty);
|
|
n_hdlc_send_frames(n_hdlc,tty);
|
|
}
|
|
}
|
|
- tty_unlock();
|
|
|
|
|
|
+
|
|
return error;
|
|
return error;
|
|
|
|
|
|
} /* end of n_hdlc_tty_write() */
|
|
} /* end of n_hdlc_tty_write() */
|