Index: drivers/dahdi/dahdi-base.c =================================================================== --- drivers/dahdi/dahdi-base.c (revision 9205) +++ drivers/dahdi/dahdi-base.c (working copy) @@ -2053,13 +2053,33 @@ int res, rv; int oldbuf,x; unsigned long flags; + static int last_badchan_count = 0; /* Make sure count never exceeds 65k, and make sure it's unsigned */ count &= 0xffff; - if (!chan) + if (!chan) { + if (++last_badchan_count > 3) { + /* Give userspace something to work with, if it's not going to pay attention to our -EINVAL */ + char nothing[128] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + }; + if (copy_to_user(usrbuf, nothing, count < 128 ? count : 128)) + return -EFAULT; + return count < 128 ? count : 128; + } return -EINVAL; + } + last_badchan_count = 0; + if (count < 1) return -EINVAL; @@ -2177,12 +2197,18 @@ unsigned long flags; struct dahdi_chan *chan = chans[unit]; int res, amnt, oldbuf, rv, x; + static int last_badchan_count = 0; /* Make sure count never exceeds 65k, and make sure it's unsigned */ count &= 0xffff; - if (!chan) + if (!chan) { + if (++last_badchan_count > 3) { + /* If userspace is going to ignore our -EINVAL, then tell it what it wants to hear. */ + return count; + } return -EINVAL; + } if (count < 1) { return -EINVAL;