Skip to content

Commit

Permalink
V4L/DVB (13554a): v4l: Use the video_drvdata function in drivers
Browse files Browse the repository at this point in the history
Fix all device drivers to use the video_drvdata function instead of
maintaining a local list of minor to private data mappings. Call
video_set_drvdata to register the driver private pointer when not
already done.

Where applicable, the local list of mappings is completely removed when
it becomes unused.

[mchehab.redhat.com: removed tm6000 changes as tm6000 is not ready yet for submission even on staging]

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Laurent Pinchart authored and Mauro Carvalho Chehab committed Dec 16, 2009
1 parent f0813b4 commit 63b0d5a
Show file tree
Hide file tree
Showing 35 changed files with 178 additions and 555 deletions.
32 changes: 7 additions & 25 deletions drivers/media/common/saa7146_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,42 +195,24 @@ void saa7146_buffer_timeout(unsigned long data)
static int fops_open(struct file *file)
{
unsigned int minor = video_devdata(file)->minor;
struct saa7146_dev *h = NULL, *dev = NULL;
struct list_head *list;
struct video_device *vdev = video_devdata(file);
struct saa7146_dev *dev = video_drvdata(file);
struct saa7146_fh *fh = NULL;
int result = 0;

enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
enum v4l2_buf_type type;

DEB_EE(("file:%p, minor:%d\n", file, minor));

if (mutex_lock_interruptible(&saa7146_devices_lock))
return -ERESTARTSYS;

list_for_each(list,&saa7146_devices) {
h = list_entry(list, struct saa7146_dev, item);
if( NULL == h->vv_data ) {
DEB_D(("device %p has not registered video devices.\n",h));
continue;
}
DEB_D(("trying: %p @ major %d,%d\n",h,h->vv_data->video_minor,h->vv_data->vbi_minor));

if (h->vv_data->video_minor == minor) {
dev = h;
}
if (h->vv_data->vbi_minor == minor) {
type = V4L2_BUF_TYPE_VBI_CAPTURE;
dev = h;
}
}
if (NULL == dev) {
DEB_S(("no such video device.\n"));
result = -ENODEV;
goto out;
}

DEB_D(("using: %p\n",dev));

type = vdev->vfl_type == VFL_TYPE_GRABBER
? V4L2_BUF_TYPE_VIDEO_CAPTURE
: V4L2_BUF_TYPE_VBI_CAPTURE;

/* check if an extension is registered */
if( NULL == dev->ext ) {
DEB_S(("no extension registered for this device.\n"));
Expand Down
35 changes: 8 additions & 27 deletions drivers/media/video/au0828/au0828-video.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include "au0828.h"
#include "au0828-reg.h"

static LIST_HEAD(au0828_devlist);
static DEFINE_MUTEX(au0828_sysfs_lock);

#define AU0828_VERSION_CODE KERNEL_VERSION(0, 0, 1)
Expand Down Expand Up @@ -693,10 +692,8 @@ void au0828_analog_unregister(struct au0828_dev *dev)
dprintk(1, "au0828_release_resources called\n");
mutex_lock(&au0828_sysfs_lock);

if (dev->vdev) {
list_del(&dev->au0828list);
if (dev->vdev)
video_unregister_device(dev->vdev);
}
if (dev->vbi_dev)
video_unregister_device(dev->vbi_dev);

Expand Down Expand Up @@ -737,29 +734,15 @@ static void res_free(struct au0828_fh *fh)

static int au0828_v4l2_open(struct file *filp)
{
int minor = video_devdata(filp)->minor;
int ret = 0;
struct au0828_dev *h, *dev = NULL;
struct au0828_dev *dev = video_drvdata(filp);
struct au0828_fh *fh;
int type = 0;
struct list_head *list;

list_for_each(list, &au0828_devlist) {
h = list_entry(list, struct au0828_dev, au0828list);
if (h->vdev->minor == minor) {
dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

#ifdef VBI_IS_WORKING
if (h->vbi_dev->minor == minor) {
dev = h;
type = V4L2_BUF_TYPE_VBI_CAPTURE;
}
if (video_devdata(filp)->vfl_type == VFL_TYPE_GRABBER)
type = V4L2_BUF_TYPE_VBI_CAPTURE;
#endif
}

if (NULL == dev)
return -ENODEV;

fh = kzalloc(sizeof(struct au0828_fh), GFP_KERNEL);
if (NULL == fh) {
Expand Down Expand Up @@ -1676,25 +1659,23 @@ int au0828_analog_register(struct au0828_dev *dev,
strcpy(dev->vbi_dev->name, "au0828a vbi");
#endif

list_add_tail(&dev->au0828list, &au0828_devlist);

/* Register the v4l2 device */
video_set_drvdata(dev->vdev, dev);
retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1);
if (retval != 0) {
dprintk(1, "unable to register video device (error = %d).\n",
retval);
list_del(&dev->au0828list);
video_device_release(dev->vdev);
return -ENODEV;
}

#ifdef VBI_IS_WORKING
/* Register the vbi device */
video_set_drvdata(dev->vbi_dev, dev);
retval = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, -1);
if (retval != 0) {
dprintk(1, "unable to register vbi device (error = %d).\n",
retval);
list_del(&dev->au0828list);
video_device_release(dev->vbi_dev);
video_device_release(dev->vdev);
return -ENODEV;
Expand Down
1 change: 0 additions & 1 deletion drivers/media/video/au0828/au0828.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ struct au0828_dev {
struct au0828_dvb dvb;

/* Analog */
struct list_head au0828list;
struct v4l2_device v4l2_dev;
int users;
unsigned int stream_on:1; /* Locks streams */
Expand Down
26 changes: 0 additions & 26 deletions drivers/media/video/cx231xx/cx231xx-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,6 @@ MODULE_PARM_DESC(alt, "alternate setting to use for video endpoint");
static LIST_HEAD(cx231xx_devlist);
static DEFINE_MUTEX(cx231xx_devlist_mutex);

struct cx231xx *cx231xx_get_device(int minor,
enum v4l2_buf_type *fh_type, int *has_radio)
{
struct cx231xx *h, *dev = NULL;

*fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
*has_radio = 0;

mutex_lock(&cx231xx_devlist_mutex);
list_for_each_entry(h, &cx231xx_devlist, devlist) {
if (h->vdev->minor == minor)
dev = h;
if (h->vbi_dev->minor == minor) {
dev = h;
*fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
}
if (h->radio_dev && h->radio_dev->minor == minor) {
dev = h;
*has_radio = 1;
}
}
mutex_unlock(&cx231xx_devlist_mutex);

return dev;
}

/*
* cx231xx_realease_resources()
* unregisters the v4l2,i2c and usb devices
Expand Down
18 changes: 14 additions & 4 deletions drivers/media/video/cx231xx/cx231xx-video.c
Original file line number Diff line number Diff line change
Expand Up @@ -1918,13 +1918,22 @@ static int cx231xx_v4l2_open(struct file *filp)
{
int minor = video_devdata(filp)->minor;
int errCode = 0, radio = 0;
struct cx231xx *dev = NULL;
struct video_device *vdev = video_devdata(filp);
struct cx231xx *dev = video_drvdata(filp);
struct cx231xx_fh *fh;
enum v4l2_buf_type fh_type = 0;

dev = cx231xx_get_device(minor, &fh_type, &radio);
if (NULL == dev)
return -ENODEV;
switch (vdev->vfl_type) {
case VFL_TYPE_GRABBER:
fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
break;
case VFL_TYPE_VBI:
fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
break;
case VFL_TYPE_RADIO:
radio = 1;
break;
}

mutex_lock(&dev->lock);

Expand Down Expand Up @@ -2326,6 +2335,7 @@ static struct video_device *cx231xx_vdev_init(struct cx231xx *dev,

snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);

video_set_drvdata(vfd, dev);
return vfd;
}

Expand Down
2 changes: 0 additions & 2 deletions drivers/media/video/cx231xx/cx231xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,6 @@ void cx231xx_release_analog_resources(struct cx231xx *dev);
int cx231xx_register_analog_devices(struct cx231xx *dev);
void cx231xx_remove_from_devlist(struct cx231xx *dev);
void cx231xx_add_into_devlist(struct cx231xx *dev);
struct cx231xx *cx231xx_get_device(int minor,
enum v4l2_buf_type *fh_type, int *has_radio);
void cx231xx_init_extension(struct cx231xx *dev);
void cx231xx_close_extension(struct cx231xx *dev);

Expand Down
22 changes: 4 additions & 18 deletions drivers/media/video/cx23885/cx23885-417.c
Original file line number Diff line number Diff line change
Expand Up @@ -1568,35 +1568,20 @@ static int vidioc_queryctrl(struct file *file, void *priv,

static int mpeg_open(struct file *file)
{
int minor = video_devdata(file)->minor;
struct cx23885_dev *h, *dev = NULL;
struct list_head *list;
struct cx23885_dev *dev = video_drvdata(file);
struct cx23885_fh *fh;

dprintk(2, "%s()\n", __func__);

lock_kernel();
list_for_each(list, &cx23885_devlist) {
h = list_entry(list, struct cx23885_dev, devlist);
if (h->v4l_device &&
h->v4l_device->minor == minor) {
dev = h;
break;
}
}

if (dev == NULL) {
unlock_kernel();
return -ENODEV;
}

/* allocate + initialize per filehandle data */
fh = kzalloc(sizeof(*fh), GFP_KERNEL);
if (NULL == fh) {
unlock_kernel();
return -ENOMEM;
}

lock_kernel();

file->private_data = fh;
fh->dev = dev;

Expand Down Expand Up @@ -1803,6 +1788,7 @@ int cx23885_417_register(struct cx23885_dev *dev)
/* Allocate and initialize V4L video device */
dev->v4l_device = cx23885_video_dev_alloc(tsport,
dev->pci, &cx23885_mpeg_template, "mpeg");
video_set_drvdata(dev->v4l_device, dev);
err = video_register_device(dev->v4l_device,
VFL_TYPE_GRABBER, -1);
if (err < 0) {
Expand Down
11 changes: 0 additions & 11 deletions drivers/media/video/cx23885/cx23885-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ MODULE_PARM_DESC(card, "card type");

static unsigned int cx23885_devcount;

static DEFINE_MUTEX(devlist);
LIST_HEAD(cx23885_devlist);

#define NO_SYNC_LINE (-1U)

/* FIXME, these allocations will change when
Expand Down Expand Up @@ -785,10 +782,6 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
dev->nr = cx23885_devcount++;
sprintf(dev->name, "cx23885[%d]", dev->nr);

mutex_lock(&devlist);
list_add_tail(&dev->devlist, &cx23885_devlist);
mutex_unlock(&devlist);

/* Configure the internal memory */
if (dev->pci->device == 0x8880) {
/* Could be 887 or 888, assume a default */
Expand Down Expand Up @@ -2008,10 +2001,6 @@ static void __devexit cx23885_finidev(struct pci_dev *pci_dev)
/* unregister stuff */
free_irq(pci_dev->irq, dev);

mutex_lock(&devlist);
list_del(&dev->devlist);
mutex_unlock(&devlist);

cx23885_dev_unregister(dev);
v4l2_device_unregister(v4l2_dev);
kfree(dev);
Expand Down
44 changes: 17 additions & 27 deletions drivers/media/video/cx23885/cx23885-video.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ static struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
vfd->release = video_device_release;
snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
dev->name, type, cx23885_boards[dev->board].name);
video_set_drvdata(vfd, dev);
return vfd;
}

Expand Down Expand Up @@ -717,45 +718,34 @@ static int get_resource(struct cx23885_fh *fh)
static int video_open(struct file *file)
{
int minor = video_devdata(file)->minor;
struct cx23885_dev *h, *dev = NULL;
struct video_device *vdev = video_devdata(file);
struct cx23885_dev *dev = video_drvdata(file);
struct cx23885_fh *fh;
struct list_head *list;
enum v4l2_buf_type type = 0;
int radio = 0;

lock_kernel();
list_for_each(list, &cx23885_devlist) {
h = list_entry(list, struct cx23885_dev, devlist);
if (h->video_dev &&
h->video_dev->minor == minor) {
dev = h;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
}
if (h->vbi_dev &&
h->vbi_dev->minor == minor) {
dev = h;
type = V4L2_BUF_TYPE_VBI_CAPTURE;
}
if (h->radio_dev &&
h->radio_dev->minor == minor) {
radio = 1;
dev = h;
}
}
if (NULL == dev) {
unlock_kernel();
return -ENODEV;
switch (vdev->vfl_type) {
case VFL_TYPE_GRABBER:
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
break;
case VFL_TYPE_VBI:
type = V4L2_BUF_TYPE_VBI_CAPTURE;
break;
case VFL_TYPE_RADIO:
radio = 1;
break;
}

dprintk(1, "open minor=%d radio=%d type=%s\n",
minor, radio, v4l2_type_names[type]);

/* allocate + initialize per filehandle data */
fh = kzalloc(sizeof(*fh), GFP_KERNEL);
if (NULL == fh) {
unlock_kernel();
if (NULL == fh)
return -ENOMEM;
}

lock_kernel();

file->private_data = fh;
fh->dev = dev;
fh->radio = radio;
Expand Down
3 changes: 0 additions & 3 deletions drivers/media/video/cx23885/cx23885.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ struct cx23885_tsport {
};

struct cx23885_dev {
struct list_head devlist;
atomic_t refcount;
struct v4l2_device v4l2_dev;

Expand Down Expand Up @@ -399,8 +398,6 @@ static inline struct cx23885_dev *to_cx23885(struct v4l2_device *v4l2_dev)

extern struct v4l2_subdev *cx23885_find_hw(struct cx23885_dev *dev, u32 hw);

extern struct list_head cx23885_devlist;

#define SRAM_CH01 0 /* Video A */
#define SRAM_CH02 1 /* VBI A */
#define SRAM_CH03 2 /* Video B */
Expand Down
Loading

0 comments on commit 63b0d5a

Please sign in to comment.