fail non-blocking I/O in case of span unassignment
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>
Mon, 19 Jun 2017 12:13:06 +0000 (15:13 +0300)
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>
Mon, 26 Jun 2017 14:49:13 +0000 (17:49 +0300)
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.cohen@xorcom.com>

drivers/dahdi/dahdi-base.c

index 305ea67..618754d 100644 (file)
@@ -2414,6 +2414,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) {
@@ -2531,6 +2534,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)) {