The rest of V4L files.
There is one list_for_each+list_entry in cpia_pp.c that
wasn't changed because it expects the loop iterator to remain NULL if
the list is empty.
A bug in vivi is fixed; the 'safe' version needs to be used because the loop
deletes the list entries.
Simplify a second loop in vivi and get rid if an un-used variable in that loop.
Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
 
 int bttv_sub_del_devices(struct bttv_core *core)
 {
-       struct bttv_sub_device *sub;
-       struct list_head *item,*save;
+       struct bttv_sub_device *sub, *save;
 
-       list_for_each_safe(item,save,&core->subs) {
-               sub = list_entry(item,struct bttv_sub_device,list);
+       list_for_each_entry_safe(sub, save, &core->subs, list) {
                list_del(&sub->list);
                device_unregister(&sub->dev);
        }
 
 {
        struct cx23885_dev *dev = port->dev;
        struct cx23885_buffer *buf;
-       struct list_head *item;
 
        dprintk(5, "%s()\n", __FUNCTION__);
        if (list_empty(&q->active))
        dprintk(2, "restart_queue [%p/%d]: restart dma\n",
                buf, buf->vb.i);
        cx23885_start_dma(port, q, buf);
-       list_for_each(item, &q->active) {
-               buf = list_entry(item, struct cx23885_buffer, vb.queue);
+       list_for_each_entry(buf, &q->active, vb.queue)
                buf->count = q->count++;
-       }
        mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
        return 0;
 }
 
 {
        struct dpc* dpc = NULL;
        struct i2c_client *client;
-       struct list_head *item;
 
        dpc = kzalloc(sizeof(struct dpc), GFP_KERNEL);
        if( NULL == dpc ) {
        }
 
        /* loop through all i2c-devices on the bus and look who is there */
-       list_for_each(item,&dpc->i2c_adapter.clients) {
-               client = list_entry(item, struct i2c_client, list);
+       list_for_each_entry(client, &dpc->i2c_adapter.clients, list)
                if( I2C_SAA7111A == client->addr )
                        dpc->saa7111a = client;
-       }
 
        /* check if all devices are present */
        if( 0 == dpc->saa7111a ) {
 
        int minor = iminor(inode);
        int errCode = 0;
        struct em28xx *h,*dev = NULL;
-       struct list_head *list;
 
-       list_for_each(list,&em28xx_devlist) {
-               h = list_entry(list, struct em28xx, devlist);
+       list_for_each_entry(h, &em28xx_devlist, devlist) {
                if (h->vdev->minor == minor) {
                        dev  = h;
                        dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 
 {
        struct mxb* mxb = NULL;
        struct i2c_client *client;
-       struct list_head *item;
        int result;
 
        if ((result = request_module("saa7111")) < 0) {
        }
 
        /* loop through all i2c-devices on the bus and look who is there */
-       list_for_each(item,&mxb->i2c_adapter.clients) {
-               client = list_entry(item, struct i2c_client, list);
+       list_for_each_entry(client, &mxb->i2c_adapter.clients, list) {
                if( I2C_ADDR_TEA6420_1 == client->addr )
                        mxb->tea6420_1 = client;
                if( I2C_ADDR_TEA6420_2 == client->addr )
 
 
 static int tvmixer_adapters(struct i2c_adapter *adap)
 {
-       struct list_head  *item;
        struct i2c_client *client;
 
-       list_for_each(item,&adap->clients) {
-               client = list_entry(item, struct i2c_client, list);
+       list_for_each_entry(client, &adap->clients, list)
                tvmixer_clients(client);
-       }
        return 0;
 }
 
 
 
 static void v4l2_int_device_try_attach_all(void)
 {
-       struct list_head *head_master;
-
-       list_for_each(head_master, &int_list) {
-               struct list_head *head_slave;
-               struct v4l2_int_device *m =
-                       list_entry(head_master, struct v4l2_int_device, head);
+       struct v4l2_int_device *m, *s;
 
+       list_for_each_entry(m, &int_list, head) {
                if (m->type != v4l2_int_type_master)
                        continue;
 
-               list_for_each(head_slave, &int_list) {
-                       struct v4l2_int_device *s =
-                               list_entry(head_slave,
-                                          struct v4l2_int_device, head);
-
+               list_for_each_entry(s, &int_list, head) {
                        if (s->type != v4l2_int_type_slave)
                                continue;
 
 
 int videobuf_streamon(struct videobuf_queue *q)
 {
        struct videobuf_buffer *buf;
-       struct list_head *list;
        unsigned long flags=0;
        int retval;
 
        q->streaming = 1;
        if (q->irqlock)
                spin_lock_irqsave(q->irqlock,flags);
-       list_for_each(list,&q->stream) {
-               buf = list_entry(list, struct videobuf_buffer, stream);
+       list_for_each_entry(buf, &q->stream, stream)
                if (buf->state == STATE_PREPARED)
                        q->ops->buf_queue(q,buf);
-       }
        if (q->irqlock)
                spin_unlock_irqrestore(q->irqlock,flags);
 
 
 static int restart_video_queue(struct vivi_dmaqueue *dma_q)
 {
        struct vivi_buffer *buf, *prev;
-       struct list_head *item;
 
        dprintk(1,"%s dma_q=0x%08lx\n",__FUNCTION__,(unsigned long)dma_q);
 
 //             vivi_start_thread(dma_q);
 
                /* cancel all outstanding capture / vbi requests */
-               list_for_each(item,&dma_q->active) {
-                       buf = list_entry(item, struct vivi_buffer, vb.queue);
-
+               list_for_each_entry_safe(buf, prev, &dma_q->active, vb.queue) {
                        list_del(&buf->vb.queue);
                        buf->vb.state = STATE_ERROR;
                        wake_up(&buf->vb.done);
 static int vivi_open(struct inode *inode, struct file *file)
 {
        int minor = iminor(inode);
-       struct vivi_dev *h,*dev = NULL;
+       struct vivi_dev *dev;
        struct vivi_fh *fh;
-       struct list_head *list;
-       enum v4l2_buf_type type = 0;
        int i;
 
        printk(KERN_DEBUG "vivi: open called (minor=%d)\n",minor);
 
-       list_for_each(list,&vivi_devlist) {
-               h = list_entry(list, struct vivi_dev, vivi_devlist);
-               if (h->vfd.minor == minor) {
-                       dev  = h;
-                       type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-               }
-       }
-       if (NULL == dev)
-               return -ENODEV;
+       list_for_each_entry(dev, &vivi_devlist, vivi_devlist)
+               if (dev->vfd.minor == minor)
+                       goto found;
+       return -ENODEV;
+found:
 
 
 
        /* If more than one user, mutex should be added */
        dev->users++;
 
-       dprintk(1,"open minor=%d type=%s users=%d\n",
-                               minor,v4l2_type_names[type],dev->users);
+       dprintk(1, "open minor=%d type=%s users=%d\n", minor,
+               v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
 
        /* allocate + initialize per filehandle data */
        fh = kzalloc(sizeof(*fh),GFP_KERNEL);