[asterisk-dev] [PATCH] fail non-blocking I/O in case of span unassignment

Tzafrir Cohen tzafrir.cohen at xorcom.com
Tue Jun 20 07:19:56 CDT 2017


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 at 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




More information about the asterisk-dev mailing list