From be7ce2bbca39c33e8a6299974320d470dba69b3a Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Sun, 29 Aug 2010 00:22:06 -0500 Subject: [PATCH 2/2] dahdi: Sleep a bit before returning -ENODEV from read/write. Since DAHDI should only return -ENODEV on read or write when there was a surprise device removal on a running system this sleep can prevent the system from becoming unresponsive if the userspace application does not check for the -ENODEV error and constantly tries to call read with elevated privileges. (issue #17669) Signed-off-by: Shaun Ruffell --- drivers/dahdi/dahdi-base.c | 30 ++++++++++++++++++++++++------ 1 files changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c index b9fd29c..1b7d02a 100644 --- a/drivers/dahdi/dahdi-base.c +++ b/drivers/dahdi/dahdi-base.c @@ -2067,10 +2067,19 @@ static ssize_t dahdi_chan_read(struct file *file, char __user *usrbuf, /* Make sure count never exceeds 65k, and make sure it's unsigned */ count &= 0xffff; - if (!chan) - return -EINVAL; + if (unlikely(!chan)) { + /* We would typically be here because of surprise hardware + * removal or driver unbinding while a user space application + * has a channel open. Most telephony applications are run at + * elevated priorities so this sleep can prevent the high + * priority threads from consuming the CPU if they're not + * expecting surprise device removal. + */ + msleep(5); + return -ENODEV; + } - if (count < 1) + if (unlikely(count < 1)) return -EINVAL; for (;;) { @@ -2192,10 +2201,19 @@ static ssize_t dahdi_chan_write(struct file *file, const char __user *usrbuf, /* Make sure count never exceeds 65k, and make sure it's unsigned */ count &= 0xffff; - if (!chan) - return -EINVAL; + if (unlikely(!chan)) { + /* We would typically be here because of surprise hardware + * removal or driver unbinding while a user space application + * has a channel open. Most telephony applications are run at + * elevated priorities so this sleep can prevent the high + * priority threads from consuming the CPU if they're not + * expecting surprise device removal. + */ + msleep(5); + return -ENODEV; + } - if (count < 1) { + if (unlikely(count < 1)) { return -EINVAL; } -- 1.7.2.1.44.g721e7