Skip to content

Commit

Permalink
dvb: Push down BKL into ioctl functions
Browse files Browse the repository at this point in the history
This requires changing all users of dvb_usercopy to
omit the inode argument.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
  • Loading branch information
Arnd Bergmann authored and Frederic Weisbecker committed May 17, 2010
1 parent ce8273a commit 16ef8de
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 58 deletions.
31 changes: 22 additions & 9 deletions drivers/media/dvb/dvb-core/dmxdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/module.h>
#include <linux/smp_lock.h>
#include <linux/poll.h>
#include <linux/ioctl.h>
#include <linux/wait.h>
Expand Down Expand Up @@ -963,7 +964,7 @@ dvb_demux_read(struct file *file, char __user *buf, size_t count,
return ret;
}

static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
static int dvb_demux_do_ioctl(struct file *file,
unsigned int cmd, void *parg)
{
struct dmxdev_filter *dmxdevfilter = file->private_data;
Expand Down Expand Up @@ -1084,10 +1085,16 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
return ret;
}

static int dvb_demux_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
static long dvb_demux_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
return dvb_usercopy(inode, file, cmd, arg, dvb_demux_do_ioctl);
int ret;

lock_kernel();
ret = dvb_usercopy(file, cmd, arg, dvb_demux_do_ioctl);
unlock_kernel();

return ret;
}

static unsigned int dvb_demux_poll(struct file *file, poll_table *wait)
Expand Down Expand Up @@ -1139,7 +1146,7 @@ static int dvb_demux_release(struct inode *inode, struct file *file)
static const struct file_operations dvb_demux_fops = {
.owner = THIS_MODULE,
.read = dvb_demux_read,
.ioctl = dvb_demux_ioctl,
.unlocked_ioctl = dvb_demux_ioctl,
.open = dvb_demux_open,
.release = dvb_demux_release,
.poll = dvb_demux_poll,
Expand All @@ -1152,7 +1159,7 @@ static struct dvb_device dvbdev_demux = {
.fops = &dvb_demux_fops
};

static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file,
static int dvb_dvr_do_ioctl(struct file *file,
unsigned int cmd, void *parg)
{
struct dvb_device *dvbdev = file->private_data;
Expand All @@ -1176,10 +1183,16 @@ static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file,
return ret;
}

static int dvb_dvr_ioctl(struct inode *inode, struct file *file,
static long dvb_dvr_ioctl(struct file *file,
unsigned int cmd, unsigned long arg)
{
return dvb_usercopy(inode, file, cmd, arg, dvb_dvr_do_ioctl);
int ret;

lock_kernel();
ret = dvb_usercopy(file, cmd, arg, dvb_dvr_do_ioctl);
unlock_kernel();

return ret;
}

static unsigned int dvb_dvr_poll(struct file *file, poll_table *wait)
Expand Down Expand Up @@ -1208,7 +1221,7 @@ static const struct file_operations dvb_dvr_fops = {
.owner = THIS_MODULE,
.read = dvb_dvr_read,
.write = dvb_dvr_write,
.ioctl = dvb_dvr_ioctl,
.unlocked_ioctl = dvb_dvr_ioctl,
.open = dvb_dvr_open,
.release = dvb_dvr_release,
.poll = dvb_dvr_poll,
Expand Down
17 changes: 12 additions & 5 deletions drivers/media/dvb/dvb-core/dvb_ca_en50221.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <linux/sched.h>
#include <linux/smp_lock.h>
#include <linux/kthread.h>

#include "dvb_ca_en50221.h"
Expand Down Expand Up @@ -1181,7 +1182,7 @@ static int dvb_ca_en50221_thread(void *data)
*
* @return 0 on success, <0 on error.
*/
static int dvb_ca_en50221_io_do_ioctl(struct inode *inode, struct file *file,
static int dvb_ca_en50221_io_do_ioctl(struct file *file,
unsigned int cmd, void *parg)
{
struct dvb_device *dvbdev = file->private_data;
Expand Down Expand Up @@ -1255,10 +1256,16 @@ static int dvb_ca_en50221_io_do_ioctl(struct inode *inode, struct file *file,
*
* @return 0 on success, <0 on error.
*/
static int dvb_ca_en50221_io_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
static long dvb_ca_en50221_io_ioctl(struct file *file,
unsigned int cmd, unsigned long arg)
{
return dvb_usercopy(inode, file, cmd, arg, dvb_ca_en50221_io_do_ioctl);
int ret;

lock_kernel();
ret = dvb_usercopy(file, cmd, arg, dvb_ca_en50221_io_do_ioctl);
unlock_kernel();

return ret;
}


Expand Down Expand Up @@ -1611,7 +1618,7 @@ static const struct file_operations dvb_ca_fops = {
.owner = THIS_MODULE,
.read = dvb_ca_en50221_io_read,
.write = dvb_ca_en50221_io_write,
.ioctl = dvb_ca_en50221_io_ioctl,
.unlocked_ioctl = dvb_ca_en50221_io_ioctl,
.open = dvb_ca_en50221_io_open,
.release = dvb_ca_en50221_io_release,
.poll = dvb_ca_en50221_io_poll,
Expand Down
30 changes: 15 additions & 15 deletions drivers/media/dvb/dvb-core/dvb_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <linux/list.h>
#include <linux/freezer.h>
#include <linux/jiffies.h>
#include <linux/smp_lock.h>
#include <linux/kthread.h>
#include <asm/processor.h>

Expand Down Expand Up @@ -1188,14 +1189,14 @@ static void dtv_property_cache_submit(struct dvb_frontend *fe)
}
}

static int dvb_frontend_ioctl_legacy(struct inode *inode, struct file *file,
static int dvb_frontend_ioctl_legacy(struct file *file,
unsigned int cmd, void *parg);
static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
static int dvb_frontend_ioctl_properties(struct file *file,
unsigned int cmd, void *parg);

static int dtv_property_process_get(struct dvb_frontend *fe,
struct dtv_property *tvp,
struct inode *inode, struct file *file)
struct file *file)
{
int r = 0;

Expand Down Expand Up @@ -1328,7 +1329,6 @@ static int dtv_property_process_get(struct dvb_frontend *fe,

static int dtv_property_process_set(struct dvb_frontend *fe,
struct dtv_property *tvp,
struct inode *inode,
struct file *file)
{
int r = 0;
Expand Down Expand Up @@ -1359,7 +1359,7 @@ static int dtv_property_process_set(struct dvb_frontend *fe,
dprintk("%s() Finalised property cache\n", __func__);
dtv_property_cache_submit(fe);

r |= dvb_frontend_ioctl_legacy(inode, file, FE_SET_FRONTEND,
r |= dvb_frontend_ioctl_legacy(file, FE_SET_FRONTEND,
&fepriv->parameters);
break;
case DTV_FREQUENCY:
Expand Down Expand Up @@ -1391,12 +1391,12 @@ static int dtv_property_process_set(struct dvb_frontend *fe,
break;
case DTV_VOLTAGE:
fe->dtv_property_cache.voltage = tvp->u.data;
r = dvb_frontend_ioctl_legacy(inode, file, FE_SET_VOLTAGE,
r = dvb_frontend_ioctl_legacy(file, FE_SET_VOLTAGE,
(void *)fe->dtv_property_cache.voltage);
break;
case DTV_TONE:
fe->dtv_property_cache.sectone = tvp->u.data;
r = dvb_frontend_ioctl_legacy(inode, file, FE_SET_TONE,
r = dvb_frontend_ioctl_legacy(file, FE_SET_TONE,
(void *)fe->dtv_property_cache.sectone);
break;
case DTV_CODE_RATE_HP:
Expand Down Expand Up @@ -1480,7 +1480,7 @@ static int dtv_property_process_set(struct dvb_frontend *fe,
return r;
}

static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
static int dvb_frontend_ioctl(struct file *file,
unsigned int cmd, void *parg)
{
struct dvb_device *dvbdev = file->private_data;
Expand All @@ -1502,17 +1502,17 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
return -ERESTARTSYS;

if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY))
err = dvb_frontend_ioctl_properties(inode, file, cmd, parg);
err = dvb_frontend_ioctl_properties(file, cmd, parg);
else {
fe->dtv_property_cache.state = DTV_UNDEFINED;
err = dvb_frontend_ioctl_legacy(inode, file, cmd, parg);
err = dvb_frontend_ioctl_legacy(file, cmd, parg);
}

up(&fepriv->sem);
return err;
}

static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
static int dvb_frontend_ioctl_properties(struct file *file,
unsigned int cmd, void *parg)
{
struct dvb_device *dvbdev = file->private_data;
Expand Down Expand Up @@ -1548,7 +1548,7 @@ static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
}

for (i = 0; i < tvps->num; i++) {
(tvp + i)->result = dtv_property_process_set(fe, tvp + i, inode, file);
(tvp + i)->result = dtv_property_process_set(fe, tvp + i, file);
err |= (tvp + i)->result;
}

Expand Down Expand Up @@ -1580,7 +1580,7 @@ static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
}

for (i = 0; i < tvps->num; i++) {
(tvp + i)->result = dtv_property_process_get(fe, tvp + i, inode, file);
(tvp + i)->result = dtv_property_process_get(fe, tvp + i, file);
err |= (tvp + i)->result;
}

Expand All @@ -1597,7 +1597,7 @@ static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
return err;
}

static int dvb_frontend_ioctl_legacy(struct inode *inode, struct file *file,
static int dvb_frontend_ioctl_legacy(struct file *file,
unsigned int cmd, void *parg)
{
struct dvb_device *dvbdev = file->private_data;
Expand Down Expand Up @@ -2022,7 +2022,7 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)

static const struct file_operations dvb_frontend_fops = {
.owner = THIS_MODULE,
.ioctl = dvb_generic_ioctl,
.unlocked_ioctl = dvb_generic_ioctl,
.poll = dvb_frontend_poll,
.open = dvb_frontend_open,
.release = dvb_frontend_release
Expand Down
15 changes: 11 additions & 4 deletions drivers/media/dvb/dvb-core/dvb_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/dvb/net.h>
#include <linux/smp_lock.h>
#include <linux/uio.h>
#include <asm/uaccess.h>
#include <linux/crc32.h>
Expand Down Expand Up @@ -1333,7 +1334,7 @@ static int dvb_net_remove_if(struct dvb_net *dvbnet, unsigned long num)
return 0;
}

static int dvb_net_do_ioctl(struct inode *inode, struct file *file,
static int dvb_net_do_ioctl(struct file *file,
unsigned int cmd, void *parg)
{
struct dvb_device *dvbdev = file->private_data;
Expand Down Expand Up @@ -1435,10 +1436,16 @@ static int dvb_net_do_ioctl(struct inode *inode, struct file *file,
return 0;
}

static int dvb_net_ioctl(struct inode *inode, struct file *file,
static long dvb_net_ioctl(struct file *file,
unsigned int cmd, unsigned long arg)
{
return dvb_usercopy(inode, file, cmd, arg, dvb_net_do_ioctl);
int ret;

lock_kernel();
ret = dvb_usercopy(file, cmd, arg, dvb_net_do_ioctl);
unlock_kernel();

return ret;
}

static int dvb_net_close(struct inode *inode, struct file *file)
Expand All @@ -1459,7 +1466,7 @@ static int dvb_net_close(struct inode *inode, struct file *file)

static const struct file_operations dvb_net_fops = {
.owner = THIS_MODULE,
.ioctl = dvb_net_ioctl,
.unlocked_ioctl = dvb_net_ioctl,
.open = dvb_generic_open,
.release = dvb_net_close,
};
Expand Down
17 changes: 11 additions & 6 deletions drivers/media/dvb/dvb-core/dvbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,23 @@ int dvb_generic_release(struct inode *inode, struct file *file)
EXPORT_SYMBOL(dvb_generic_release);


int dvb_generic_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
long dvb_generic_ioctl(struct file *file,
unsigned int cmd, unsigned long arg)
{
struct dvb_device *dvbdev = file->private_data;
int ret;

if (!dvbdev)
return -ENODEV;

if (!dvbdev->kernel_ioctl)
return -EINVAL;

return dvb_usercopy (inode, file, cmd, arg, dvbdev->kernel_ioctl);
lock_kernel();
ret = dvb_usercopy(file, cmd, arg, dvbdev->kernel_ioctl);
unlock_kernel();

return ret;
}
EXPORT_SYMBOL(dvb_generic_ioctl);

Expand Down Expand Up @@ -377,9 +382,9 @@ EXPORT_SYMBOL(dvb_unregister_adapter);
define this as video_usercopy(). this will introduce a dependecy
to the v4l "videodev.o" module, which is unnecessary for some
cards (ie. the budget dvb-cards don't need the v4l module...) */
int dvb_usercopy(struct inode *inode, struct file *file,
int dvb_usercopy(struct file *file,
unsigned int cmd, unsigned long arg,
int (*func)(struct inode *inode, struct file *file,
int (*func)(struct file *file,
unsigned int cmd, void *arg))
{
char sbuf[128];
Expand Down Expand Up @@ -416,7 +421,7 @@ int dvb_usercopy(struct inode *inode, struct file *file,
}

/* call driver */
if ((err = func(inode, file, cmd, parg)) == -ENOIOCTLCMD)
if ((err = func(file, cmd, parg)) == -ENOIOCTLCMD)
err = -EINVAL;

if (err < 0)
Expand Down
11 changes: 4 additions & 7 deletions drivers/media/dvb/dvb-core/dvbdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ struct dvb_device {

wait_queue_head_t wait_queue;
/* don't really need those !? -- FIXME: use video_usercopy */
int (*kernel_ioctl)(struct inode *inode, struct file *file,
unsigned int cmd, void *arg);
int (*kernel_ioctl)(struct file *file, unsigned int cmd, void *arg);

void *priv;
};
Expand All @@ -138,17 +137,15 @@ extern void dvb_unregister_device (struct dvb_device *dvbdev);

extern int dvb_generic_open (struct inode *inode, struct file *file);
extern int dvb_generic_release (struct inode *inode, struct file *file);
extern int dvb_generic_ioctl (struct inode *inode, struct file *file,
extern long dvb_generic_ioctl (struct file *file,
unsigned int cmd, unsigned long arg);

/* we don't mess with video_usercopy() any more,
we simply define out own dvb_usercopy(), which will hopefully become
generic_usercopy() someday... */

extern int dvb_usercopy(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg,
int (*func)(struct inode *inode, struct file *file,
unsigned int cmd, void *arg));
extern int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
int (*func)(struct file *file, unsigned int cmd, void *arg));

/** generic DVB attach function. */
#ifdef CONFIG_MEDIA_ATTACH
Expand Down
5 changes: 2 additions & 3 deletions drivers/media/dvb/firewire/firedtv-ci.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ static int fdtv_ca_send_msg(struct firedtv *fdtv, void *arg)
return err;
}

static int fdtv_ca_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, void *arg)
static int fdtv_ca_ioctl(struct file *file, unsigned int cmd, void *arg)
{
struct dvb_device *dvbdev = file->private_data;
struct firedtv *fdtv = dvbdev->priv;
Expand Down Expand Up @@ -217,7 +216,7 @@ static unsigned int fdtv_ca_io_poll(struct file *file, poll_table *wait)

static const struct file_operations fdtv_ca_fops = {
.owner = THIS_MODULE,
.ioctl = dvb_generic_ioctl,
.unlocked_ioctl = dvb_generic_ioctl,
.open = dvb_generic_open,
.release = dvb_generic_release,
.poll = fdtv_ca_io_poll,
Expand Down
Loading

0 comments on commit 16ef8de

Please sign in to comment.