In case a user has a file descriptor that is used for non-blocking I/O
and the span to which it belongs gets unassigned, its reads and writes
will still yield -EAGAIN.

This commit adds a test for such a case and returns the proper -ENODEV.

Signed-off-by: Tzafrir Cohen <tzafrir.co...@xorcom.com>
---
 drivers/dahdi/dahdi-base.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c
index f2caad0..84a2f1c 100644
--- a/drivers/dahdi/dahdi-base.c
+++ b/drivers/dahdi/dahdi-base.c
@@ -2409,6 +2409,9 @@ static ssize_t dahdi_chan_read(struct file *file, char 
__user *usrbuf,
        if (unlikely(count < 1))
                return -EINVAL;
 
+       if (unlikely(!test_bit(DAHDI_FLAGBIT_REGISTERED, &chan->flags)))
+               return -ENODEV;
+
        for (;;) {
                spin_lock_irqsave(&chan->lock, flags);
                if (chan->eventinidx != chan->eventoutidx) {
@@ -2526,6 +2529,9 @@ static ssize_t dahdi_chan_write(struct file *file, const 
char __user *usrbuf,
        if (unlikely(count < 1))
                return -EINVAL;
 
+       if (unlikely(!test_bit(DAHDI_FLAGBIT_REGISTERED, &chan->flags)))
+               return -ENODEV;
+
        for (;;) {
                spin_lock_irqsave(&chan->lock, flags);
                if ((chan->curtone || chan->pdialcount) && 
!is_pseudo_chan(chan)) {
-- 
2.11.0


-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev

Reply via email to