Skip to content

Commit

Permalink
V4L/DVB (6314): saa7134: Replace list_for_each+list_entry with list_f…
Browse files Browse the repository at this point in the history
…or_each_entry

A couple loops weren't changed because they expected the loop iterator
to be left as NULL if the list was empty.  Maybe the code should just
check for that first, then loop?

Adjust some of the loop logic to be simpler.

Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
  • Loading branch information
Trent Piepho authored and Mauro Carvalho Chehab committed Oct 10, 2007
1 parent 805a439 commit 6d28e98
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 64 deletions.
20 changes: 4 additions & 16 deletions drivers/media/video/saa7134/saa7134-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,6 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
const struct pci_device_id *pci_id)
{
struct saa7134_dev *dev;
struct list_head *item;
struct saa7134_mpeg_ops *mops;
int err;

Expand Down Expand Up @@ -1072,10 +1071,8 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
saa7134_devcount++;

mutex_lock(&devlist_lock);
list_for_each(item,&mops_list) {
mops = list_entry(item, struct saa7134_mpeg_ops, next);
list_for_each_entry(mops, &mops_list, next)
mpeg_ops_attach(mops, dev);
}
list_add_tail(&dev->devlist,&saa7134_devlist);
mutex_unlock(&devlist_lock);

Expand Down Expand Up @@ -1109,7 +1106,6 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
{
struct saa7134_dev *dev = pci_get_drvdata(pci_dev);
struct list_head *item;
struct saa7134_mpeg_ops *mops;

/* Release DMA sound modules if present */
Expand Down Expand Up @@ -1138,10 +1134,8 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
/* unregister */
mutex_lock(&devlist_lock);
list_del(&dev->devlist);
list_for_each(item,&mops_list) {
mops = list_entry(item, struct saa7134_mpeg_ops, next);
list_for_each_entry(mops, &mops_list, next)
mpeg_ops_detach(mops, dev);
}
mutex_unlock(&devlist_lock);
saa7134_devcount--;

Expand Down Expand Up @@ -1237,30 +1231,24 @@ static int saa7134_resume(struct pci_dev *pci_dev)

int saa7134_ts_register(struct saa7134_mpeg_ops *ops)
{
struct list_head *item;
struct saa7134_dev *dev;

mutex_lock(&devlist_lock);
list_for_each(item,&saa7134_devlist) {
dev = list_entry(item, struct saa7134_dev, devlist);
list_for_each_entry(dev, &saa7134_devlist, devlist)
mpeg_ops_attach(ops, dev);
}
list_add_tail(&ops->next,&mops_list);
mutex_unlock(&devlist_lock);
return 0;
}

void saa7134_ts_unregister(struct saa7134_mpeg_ops *ops)
{
struct list_head *item;
struct saa7134_dev *dev;

mutex_lock(&devlist_lock);
list_del(&ops->next);
list_for_each(item,&saa7134_devlist) {
dev = list_entry(item, struct saa7134_dev, devlist);
list_for_each_entry(dev, &saa7134_devlist, devlist)
mpeg_ops_detach(ops, dev);
}
mutex_unlock(&devlist_lock);
}

Expand Down
15 changes: 6 additions & 9 deletions drivers/media/video/saa7134/saa7134-empress.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,14 @@ static int ts_init_encoder(struct saa7134_dev* dev)
static int ts_open(struct inode *inode, struct file *file)
{
int minor = iminor(inode);
struct saa7134_dev *h,*dev = NULL;
struct list_head *list;
struct saa7134_dev *dev;
int err;

list_for_each(list,&saa7134_devlist) {
h = list_entry(list, struct saa7134_dev, devlist);
if (h->empress_dev && h->empress_dev->minor == minor)
dev = h;
}
if (NULL == dev)
return -ENODEV;
list_for_each_entry(dev, &saa7134_devlist, devlist)
if (dev->empress_dev && dev->empress_dev->minor == minor)
goto found;
return -ENODEV;
found:

dprintk("open minor=%d\n",minor);
err = -EBUSY;
Expand Down
42 changes: 15 additions & 27 deletions drivers/media/video/saa7134/saa7134-oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,14 @@ static int dsp_rec_stop(struct saa7134_dev *dev)
static int dsp_open(struct inode *inode, struct file *file)
{
int minor = iminor(inode);
struct saa7134_dev *h,*dev = NULL;
struct list_head *list;
struct saa7134_dev *dev;
int err;

list_for_each(list,&saa7134_devlist) {
h = list_entry(list, struct saa7134_dev, devlist);
if (h->dmasound.minor_dsp == minor)
dev = h;
}
if (NULL == dev)
return -ENODEV;
list_for_each_entry(dev, &saa7134_devlist, devlist)
if (dev->dmasound.minor_dsp == minor)
goto found;
return -ENODEV;
found:

mutex_lock(&dev->dmasound.lock);
err = -EBUSY;
Expand Down Expand Up @@ -680,19 +677,14 @@ mixer_level(struct saa7134_dev *dev, enum saa7134_audio_in src, int level)
static int mixer_open(struct inode *inode, struct file *file)
{
int minor = iminor(inode);
struct saa7134_dev *h,*dev = NULL;
struct list_head *list;
struct saa7134_dev *dev;

list_for_each(list,&saa7134_devlist) {
h = list_entry(list, struct saa7134_dev, devlist);
if (h->dmasound.minor_mixer == minor)
dev = h;
}
if (NULL == dev)
return -ENODEV;

file->private_data = dev;
return 0;
list_for_each_entry(dev, &saa7134_devlist, devlist)
if (dev->dmasound.minor_mixer == minor) {
file->private_data = dev;
return 0;
}
return -ENODEV;
}

static int mixer_release(struct inode *inode, struct file *file)
Expand Down Expand Up @@ -1022,18 +1014,14 @@ static int saa7134_oss_init(void)

static void saa7134_oss_exit(void)
{
struct saa7134_dev *dev = NULL;
struct list_head *list;

list_for_each(list,&saa7134_devlist) {
dev = list_entry(list, struct saa7134_dev, devlist);
struct saa7134_dev *dev;

list_for_each_entry(dev, &saa7134_devlist, devlist) {
/* Device isn't registered by OSS, probably ALSA's */
if (!dev->dmasound.minor_dsp)
continue;

oss_device_exit(dev);

}

saa7134_dmasound_init = NULL;
Expand Down
22 changes: 10 additions & 12 deletions drivers/media/video/saa7134/saa7134-video.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,26 +1285,24 @@ static int saa7134_resource(struct saa7134_fh *fh)
static int video_open(struct inode *inode, struct file *file)
{
int minor = iminor(inode);
struct saa7134_dev *h,*dev = NULL;
struct saa7134_dev *dev;
struct saa7134_fh *fh;
struct list_head *list;
enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
int radio = 0;
list_for_each(list,&saa7134_devlist) {
h = list_entry(list, struct saa7134_dev, devlist);
if (h->video_dev && (h->video_dev->minor == minor))
dev = h;
if (h->radio_dev && (h->radio_dev->minor == minor)) {
list_for_each_entry(dev, &saa7134_devlist, devlist) {
if (dev->video_dev && (dev->video_dev->minor == minor))
goto found;
if (dev->radio_dev && (dev->radio_dev->minor == minor)) {
radio = 1;
dev = h;
goto found;
}
if (h->vbi_dev && (h->vbi_dev->minor == minor)) {
if (dev->vbi_dev && (dev->vbi_dev->minor == minor)) {
type = V4L2_BUF_TYPE_VBI_CAPTURE;
dev = h;
goto found;
}
}
if (NULL == dev)
return -ENODEV;
return -ENODEV;
found:

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

0 comments on commit 6d28e98

Please sign in to comment.