*** linux/drivers/char/n_hdlc.c	Fri Feb  9 20:30:22 2001
--- linux-2.4.3/drivers/char/n_hdlc.c	Tue May  1 17:25:06 2001
***************
*** 235,243 ****
  		printk("%s(%d)n_hdlc_release() called\n",__FILE__,__LINE__);
  		
  	/* Ensure that the n_hdlcd process is not hanging on select()/poll() */
! 	wake_up_interruptible (&n_hdlc->read_wait);
! 	wake_up_interruptible (&n_hdlc->poll_wait);
! 	wake_up_interruptible (&n_hdlc->write_wait);
  
  	if (tty != NULL && tty->disc_data == n_hdlc)
  		tty->disc_data = NULL;	/* Break the tty->n_hdlc link */
--- 235,242 ----
  		printk("%s(%d)n_hdlc_release() called\n",__FILE__,__LINE__);
  		
  	/* Ensure that the n_hdlcd process is not hanging on select()/poll() */
! 	wake_up_interruptible (&tty->read_wait);
! 	wake_up_interruptible (&tty->write_wait);
  
  	if (tty != NULL && tty->disc_data == n_hdlc)
  		tty->disc_data = NULL;	/* Break the tty->n_hdlc link */
***************
*** 432,439 ****
  			n_hdlc->tbuf = NULL;
  			
  			/* wait up sleeping writers */
! 			wake_up_interruptible(&n_hdlc->write_wait);
! 			wake_up_interruptible(&n_hdlc->poll_wait);
  	
  			/* get next pending transmit buffer */
  			tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list);
--- 431,437 ----
  			n_hdlc->tbuf = NULL;
  			
  			/* wait up sleeping writers */
! 			wake_up_interruptible(&tty->write_wait);
  	
  			/* get next pending transmit buffer */
  			tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list);
***************
*** 575,582 ****
  	n_hdlc_buf_put(&n_hdlc->rx_buf_list,buf);
  	
  	/* wake up any blocked reads and perform async signalling */
! 	wake_up_interruptible (&n_hdlc->read_wait);
! 	wake_up_interruptible (&n_hdlc->poll_wait);
  	if (n_hdlc->tty->fasync != NULL)
  		kill_fasync (&n_hdlc->tty->fasync, SIGIO, POLL_IN);
  
--- 573,579 ----
  	n_hdlc_buf_put(&n_hdlc->rx_buf_list,buf);
  	
  	/* wake up any blocked reads and perform async signalling */
! 	wake_up_interruptible (&tty->read_wait);
  	if (n_hdlc->tty->fasync != NULL)
  		kill_fasync (&n_hdlc->tty->fasync, SIGIO, POLL_IN);
  
***************
*** 621,626 ****
--- 618,626 ----
  	}
  
  	for (;;) {
+ 		if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
+ 			return -EIO;
+ 
  		n_hdlc = tty2n_hdlc (tty);
  		if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC ||
  			 tty != n_hdlc->tty)
***************
*** 634,640 ****
  		if (file->f_flags & O_NONBLOCK)
  			return -EAGAIN;
  			
! 		interruptible_sleep_on (&n_hdlc->read_wait);
  		if (signal_pending(current))
  			return -EINTR;
  	}
--- 634,640 ----
  		if (file->f_flags & O_NONBLOCK)
  			return -EAGAIN;
  			
! 		interruptible_sleep_on (&tty->read_wait);
  		if (signal_pending(current))
  			return -EINTR;
  	}
***************
*** 703,709 ****
  		count = maxframe;
  	}
  	
! 	add_wait_queue(&n_hdlc->write_wait, &wait);
  	set_current_state(TASK_INTERRUPTIBLE);
  	
  	/* Allocate transmit buffer */
--- 703,709 ----
  		count = maxframe;
  	}
  	
! 	add_wait_queue(&tty->write_wait, &wait);
  	set_current_state(TASK_INTERRUPTIBLE);
  	
  	/* Allocate transmit buffer */
***************
*** 726,732 ****
  	}
  
  	set_current_state(TASK_RUNNING);
! 	remove_wait_queue(&n_hdlc->write_wait, &wait);
  
  	if (!error) {		
  		/* Retrieve the user's buffer */
--- 726,732 ----
  	}
  
  	set_current_state(TASK_RUNNING);
! 	remove_wait_queue(&tty->write_wait, &wait);
  
  	if (!error) {		
  		/* Retrieve the user's buffer */
***************
*** 836,847 ****
  	if (n_hdlc && n_hdlc->magic == HDLC_MAGIC && tty == n_hdlc->tty) {
  		/* queue current process into any wait queue that */
  		/* may awaken in the future (read and write) */
! 		poll_wait(filp, &n_hdlc->poll_wait, wait);
  
  		/* set bits for operations that wont block */
  		if(n_hdlc->rx_buf_list.head)
  			mask |= POLLIN | POLLRDNORM;	/* readable */
! 		if(tty->flags & (1 << TTY_OTHER_CLOSED))
  			mask |= POLLHUP;
  		if(tty_hung_up_p(filp))
  			mask |= POLLHUP;
--- 836,849 ----
  	if (n_hdlc && n_hdlc->magic == HDLC_MAGIC && tty == n_hdlc->tty) {
  		/* queue current process into any wait queue that */
  		/* may awaken in the future (read and write) */
! 
! 		poll_wait(filp, &tty->read_wait, wait);
! 		poll_wait(filp, &tty->write_wait, wait);
  
  		/* set bits for operations that wont block */
  		if(n_hdlc->rx_buf_list.head)
  			mask |= POLLIN | POLLRDNORM;	/* readable */
! 		if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
  			mask |= POLLHUP;
  		if(tty_hung_up_p(filp))
  			mask |= POLLHUP;
