From 3b1d2d4a1438156a001325fbfdeb4af8e863c2fd Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Wed, 4 Nov 2009 01:29:32 -0600 Subject: [PATCH 2/2] dahdi-base: Use unlocked_ioctl and compat_ioctl instead of ioctl. dahdi-base needs compat_ioctl in order to allow 32-bit userspace applications to call the DAHDI ioctls in a 64-bit kernel. (related to issue 14808) --- drivers/dahdi/dahdi-base.c | 61 ++++++++++++++++++++++++++++++++----------- 1 files changed, 45 insertions(+), 16 deletions(-) diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c index 5def807..f2efcdf 100644 --- a/drivers/dahdi/dahdi-base.c +++ b/drivers/dahdi/dahdi-base.c @@ -48,6 +48,10 @@ #include #include +#ifdef HAVE_UNLOCKED_IOCTL +#include +#endif + #include #include @@ -3352,7 +3356,7 @@ static void __do_dtmf(struct dahdi_chan *chan) __qevent(chan, DAHDI_EVENT_DIALCOMPLETE); } -static int dahdi_release(struct file *file) +static int dahdi_release(struct inode *inode, struct file *file) { int unit = UNIT(file); int res; @@ -5614,45 +5618,67 @@ static int dahdi_prechan_ioctl(struct file *file, unsigned int cmd, unsigned lon return 0; } -static int dahdi_ioctl(struct file *file, unsigned int cmd, unsigned long data) +#ifdef HAVE_UNLOCKED_IOCTL +static long dahdi_ioctl(struct file *file, unsigned int cmd, unsigned long data) +#else +static int dahdi_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long data) +#endif { int unit = UNIT(file); struct dahdi_chan *chan; struct dahdi_timer *timer; + int ret; - if (!unit) - return dahdi_ctl_ioctl(file, cmd, data); +#ifdef HAVE_UNLOCKED_IOCTL + lock_kernel(); +#endif + + if (!unit) { + ret = dahdi_ctl_ioctl(file, cmd, data); + goto unlock_exit; + } if (unit == 250) { /* dahdi_transcode should have updated the file_operations on * this file object on open, so we shouldn't be here. */ WARN_ON(1); - return -EFAULT; + ret = -EFAULT; + goto unlock_exit; } if (unit == 253) { timer = file->private_data; if (timer) - return dahdi_timer_ioctl(file, cmd, data, timer); + ret = dahdi_timer_ioctl(file, cmd, data, timer); else - return -EINVAL; + ret = -EINVAL; + goto unlock_exit; } if (unit == 254) { chan = file->private_data; if (chan) - return dahdi_chan_ioctl(file, cmd, data, chan->channo); + ret = dahdi_chan_ioctl(file, cmd, data, chan->channo); else - return dahdi_prechan_ioctl(file, cmd, data, unit); + ret = dahdi_prechan_ioctl(file, cmd, data, unit); + goto unlock_exit; } if (unit == 255) { chan = file->private_data; if (!chan) { module_printk(KERN_NOTICE, "No pseudo channel structure to read?\n"); - return -EINVAL; + ret = -EINVAL; + goto unlock_exit; } - return dahdi_chanandpseudo_ioctl(file, cmd, data, chan->channo); + ret = dahdi_chanandpseudo_ioctl(file, cmd, data, chan->channo); + goto unlock_exit; } - return dahdi_chan_ioctl(file, cmd, data, unit); + ret = dahdi_chan_ioctl(file, cmd, data, unit); + +unlock_exit: +#ifdef HAVE_UNLOCKED_IOCTL + unlock_kernel(); +#endif + return ret; } @@ -8320,17 +8346,20 @@ module_param(deftaps, int, 0644); static struct file_operations dahdi_fops = { .owner = THIS_MODULE, - .llseek = NULL, .open = dahdi_open, .release = dahdi_release, +#ifdef HAVE_UNLOCKED_IOCTL + .unlocked_ioctl = dahdi_ioctl, +#ifdef HAVE_COMPAT_IOCTL + .compat_ioctl = dahdi_ioctl, +#endif +#else .ioctl = dahdi_ioctl, +#endif .read = dahdi_read, .write = dahdi_write, .poll = dahdi_poll, .mmap = dahdi_mmap, - .flush = NULL, - .fsync = NULL, - .fasync = NULL, }; #ifdef CONFIG_DAHDI_WATCHDOG -- 1.6.5.2