V4L/DVB (6314): saa7134: Replace list_for_each+list_entry with list_for_each_entry
authorTrent Piepho <xyzzy@speakeasy.org>
Wed, 10 Oct 2007 08:37:42 +0000 (05:37 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Wed, 10 Oct 2007 16:35:07 +0000 (13:35 -0300)
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>
drivers/media/video/saa7134/saa7134-core.c
drivers/media/video/saa7134/saa7134-empress.c
drivers/media/video/saa7134/saa7134-oss.c
drivers/media/video/saa7134/saa7134-video.c

index 80f04f252fced35f2fe52385db4b9a127e856a0b..1a4a24471f204da1bd71cfd6c3578725a09d4da7 100644 (file)
@@ -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;
 
@@ -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);
 
@@ -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 */
@@ -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--;
 
@@ -1237,14 +1231,11 @@ 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;
@@ -1252,15 +1243,12 @@ int saa7134_ts_register(struct saa7134_mpeg_ops *ops)
 
 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);
 }
 
index a16df57af63a09f73c892ee07bfed31cd366e551..34ca874dd7fe4e8a65a8643a682954ae1fb80e15 100644 (file)
@@ -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;
index 1a737b6473663af6e7b4a86225a4347a3b230255..aedf04653e0e8c0617890e7a857cb23ad1a4969b 100644 (file)
@@ -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;
@@ -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)
@@ -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;
index 7c97ac15e665192f436d907f2498ab27f799675d..471b92793c124aca8a94626390ef079175a3c53c 100644 (file)
@@ -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]);