From 8aa9eb9059f6246b530d664f271e5c32858222ed Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Tue, 3 Feb 2015 15:00:25 -0300 Subject: [media] au0828: Delete unnecessary checks before the function call "video_unregister_device" The video_unregister_device() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/au0828/au0828-video.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'drivers/media/usb/au0828') diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c index a27cb5fcdef8..b49fe9192559 100644 --- a/drivers/media/usb/au0828/au0828-video.c +++ b/drivers/media/usb/au0828/au0828-video.c @@ -899,12 +899,8 @@ void au0828_analog_unregister(struct au0828_dev *dev) { dprintk(1, "au0828_analog_unregister called\n"); mutex_lock(&au0828_sysfs_lock); - - if (dev->vdev) - video_unregister_device(dev->vdev); - if (dev->vbi_dev) - video_unregister_device(dev->vbi_dev); - + video_unregister_device(dev->vdev); + video_unregister_device(dev->vbi_dev); mutex_unlock(&au0828_sysfs_lock); } -- cgit v1.2.3 From c5036d61e0bed3f4f51391a145638b426825e69c Mon Sep 17 00:00:00 2001 From: "Lad, Prabhakar" Date: Tue, 24 Feb 2015 10:00:29 -0300 Subject: [media] media: au0828: drop vbi_buffer_filled() and re-use buffer_filled() The vbi_buffer_filled() and buffer_filled() did the same functionality except for incrementing the buffer sequence, this patch drops the vbi_buffer_filled() and re-uses buffer_filled() for vbi buffers as well by adding the check for vb2-queue type while incrementing the sequence numbers. Along side this patch aligns the input parameters of buffer_filled() function appropriately. Signed-off-by: Lad, Prabhakar Acked-by: Shuah Khan Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/au0828/au0828-video.c | 36 +++++++++++++-------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'drivers/media/usb/au0828') diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c index b49fe9192559..61e525fcdcc3 100644 --- a/drivers/media/usb/au0828/au0828-video.c +++ b/drivers/media/usb/au0828/au0828-video.c @@ -299,29 +299,23 @@ static int au0828_init_isoc(struct au0828_dev *dev, int max_packets, * Announces that a buffer were filled and request the next */ static inline void buffer_filled(struct au0828_dev *dev, - struct au0828_dmaqueue *dma_q, - struct au0828_buffer *buf) + struct au0828_dmaqueue *dma_q, + struct au0828_buffer *buf) { - /* Advice that buffer was filled */ - au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->top_field); - - buf->vb.v4l2_buf.sequence = dev->frame_count++; - buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED; - v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp); - vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE); -} + struct vb2_buffer vb = buf->vb; + struct vb2_queue *q = vb.vb2_queue; -static inline void vbi_buffer_filled(struct au0828_dev *dev, - struct au0828_dmaqueue *dma_q, - struct au0828_buffer *buf) -{ /* Advice that buffer was filled */ au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->top_field); - buf->vb.v4l2_buf.sequence = dev->vbi_frame_count++; - buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED; - v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp); - vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE); + if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) + vb.v4l2_buf.sequence = dev->frame_count++; + else + vb.v4l2_buf.sequence = dev->vbi_frame_count++; + + vb.v4l2_buf.field = V4L2_FIELD_INTERLACED; + v4l2_get_timestamp(&vb.v4l2_buf.timestamp); + vb2_buffer_done(&vb, VB2_BUF_STATE_DONE); } /* @@ -574,9 +568,7 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb) if (fbyte & 0x40) { /* VBI */ if (vbi_buf != NULL) - vbi_buffer_filled(dev, - vbi_dma_q, - vbi_buf); + buffer_filled(dev, vbi_dma_q, vbi_buf); vbi_get_next_buf(vbi_dma_q, &vbi_buf); if (vbi_buf == NULL) vbioutp = NULL; @@ -945,7 +937,7 @@ static void au0828_vbi_buffer_timeout(unsigned long data) if (buf != NULL) { vbi_data = vb2_plane_vaddr(&buf->vb, 0); memset(vbi_data, 0x00, buf->length); - vbi_buffer_filled(dev, dma_q, buf); + buffer_filled(dev, dma_q, buf); } vbi_get_next_buf(dma_q, &buf); -- cgit v1.2.3 From 41071bb8c78e4d0b36c51c71b6620d74cb7e2ceb Mon Sep 17 00:00:00 2001 From: Shuah Khan Date: Thu, 26 Feb 2015 19:33:13 -0300 Subject: [media] media: au0828 - embed vdev and vbi_dev structs in au0828_dev Embed video_device structs vdev and vbi_dev in au0828_dev. With this change, dynamic allocation and error path logic in au0828_analog_register() is removed as it doesn't need to allocate and handle allocation errors. Unregister path doesn't need to free the now static video_device structures, hence, changed video_device.release in au0828_video_template to point to video_device_release_empty. Signed-off-by: Shuah Khan Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/au0828/au0828-video.c | 64 ++++++++++++--------------------- drivers/media/usb/au0828/au0828.h | 4 +-- 2 files changed, 24 insertions(+), 44 deletions(-) (limited to 'drivers/media/usb/au0828') diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c index 61e525fcdcc3..bf990a931d4e 100644 --- a/drivers/media/usb/au0828/au0828-video.c +++ b/drivers/media/usb/au0828/au0828-video.c @@ -891,8 +891,8 @@ void au0828_analog_unregister(struct au0828_dev *dev) { dprintk(1, "au0828_analog_unregister called\n"); mutex_lock(&au0828_sysfs_lock); - video_unregister_device(dev->vdev); - video_unregister_device(dev->vbi_dev); + video_unregister_device(&dev->vdev); + video_unregister_device(&dev->vbi_dev); mutex_unlock(&au0828_sysfs_lock); } @@ -1274,7 +1274,7 @@ static int vidioc_enum_input(struct file *file, void *priv, input->audioset = 2; } - input->std = dev->vdev->tvnorms; + input->std = dev->vdev.tvnorms; return 0; } @@ -1692,7 +1692,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = { static const struct video_device au0828_video_template = { .fops = &au0828_v4l_fops, - .release = video_device_release, + .release = video_device_release_empty, .ioctl_ops = &video_ioctl_ops, .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL_M, }; @@ -1802,52 +1802,36 @@ int au0828_analog_register(struct au0828_dev *dev, dev->std = V4L2_STD_NTSC_M; au0828_s_input(dev, 0); - /* allocate and fill v4l2 video struct */ - dev->vdev = video_device_alloc(); - if (NULL == dev->vdev) { - dprintk(1, "Can't allocate video_device.\n"); - return -ENOMEM; - } - - /* allocate the VBI struct */ - dev->vbi_dev = video_device_alloc(); - if (NULL == dev->vbi_dev) { - dprintk(1, "Can't allocate vbi_device.\n"); - ret = -ENOMEM; - goto err_vdev; - } - mutex_init(&dev->vb_queue_lock); mutex_init(&dev->vb_vbi_queue_lock); /* Fill the video capture device struct */ - *dev->vdev = au0828_video_template; - dev->vdev->v4l2_dev = &dev->v4l2_dev; - dev->vdev->lock = &dev->lock; - dev->vdev->queue = &dev->vb_vidq; - dev->vdev->queue->lock = &dev->vb_queue_lock; - strcpy(dev->vdev->name, "au0828a video"); + dev->vdev = au0828_video_template; + dev->vdev.v4l2_dev = &dev->v4l2_dev; + dev->vdev.lock = &dev->lock; + dev->vdev.queue = &dev->vb_vidq; + dev->vdev.queue->lock = &dev->vb_queue_lock; + strcpy(dev->vdev.name, "au0828a video"); /* Setup the VBI device */ - *dev->vbi_dev = au0828_video_template; - dev->vbi_dev->v4l2_dev = &dev->v4l2_dev; - dev->vbi_dev->lock = &dev->lock; - dev->vbi_dev->queue = &dev->vb_vbiq; - dev->vbi_dev->queue->lock = &dev->vb_vbi_queue_lock; - strcpy(dev->vbi_dev->name, "au0828a vbi"); + dev->vbi_dev = au0828_video_template; + dev->vbi_dev.v4l2_dev = &dev->v4l2_dev; + dev->vbi_dev.lock = &dev->lock; + dev->vbi_dev.queue = &dev->vb_vbiq; + dev->vbi_dev.queue->lock = &dev->vb_vbi_queue_lock; + strcpy(dev->vbi_dev.name, "au0828a vbi"); /* initialize videobuf2 stuff */ retval = au0828_vb2_setup(dev); if (retval != 0) { dprintk(1, "unable to setup videobuf2 queues (error = %d).\n", retval); - ret = -ENODEV; - goto err_vbi_dev; + return -ENODEV; } /* Register the v4l2 device */ - video_set_drvdata(dev->vdev, dev); - retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1); + 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); @@ -1856,8 +1840,8 @@ int au0828_analog_register(struct au0828_dev *dev, } /* Register the vbi device */ - video_set_drvdata(dev->vbi_dev, dev); - retval = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, -1); + 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); @@ -1870,14 +1854,10 @@ int au0828_analog_register(struct au0828_dev *dev, return 0; err_reg_vbi_dev: - video_unregister_device(dev->vdev); + video_unregister_device(&dev->vdev); err_reg_vdev: vb2_queue_release(&dev->vb_vidq); vb2_queue_release(&dev->vb_vbiq); -err_vbi_dev: - video_device_release(dev->vbi_dev); -err_vdev: - video_device_release(dev->vdev); return ret; } diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h index eb1518742ae6..3b480005ce3b 100644 --- a/drivers/media/usb/au0828/au0828.h +++ b/drivers/media/usb/au0828/au0828.h @@ -209,8 +209,8 @@ struct au0828_dev { struct au0828_rc *ir; #endif - struct video_device *vdev; - struct video_device *vbi_dev; + struct video_device vdev; + struct video_device vbi_dev; /* Videobuf2 */ struct vb2_queue vb_vidq; -- cgit v1.2.3 From 8a55ddd94c3a763f701f003fd56e39f7c317063d Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Fri, 13 Mar 2015 10:41:39 -0300 Subject: [media] au0828: fix broken streaming Commit c5036d61e0bed3f4f51391a145638b426825e69c ("media: au0828: drop vbi_buffer_filled() and re-use buffer_filled()") broke video and vbi streaming. The vb2_buffer struct was copied instead of taking a pointer to it, but vb2_buffer_done() needs the real object, not a copy, since it is hooking the buffer into a different list. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/au0828/au0828-video.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'drivers/media/usb/au0828') diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c index bf990a931d4e..1a362a041ab3 100644 --- a/drivers/media/usb/au0828/au0828-video.c +++ b/drivers/media/usb/au0828/au0828-video.c @@ -302,20 +302,20 @@ static inline void buffer_filled(struct au0828_dev *dev, struct au0828_dmaqueue *dma_q, struct au0828_buffer *buf) { - struct vb2_buffer vb = buf->vb; - struct vb2_queue *q = vb.vb2_queue; + struct vb2_buffer *vb = &buf->vb; + struct vb2_queue *q = vb->vb2_queue; /* Advice that buffer was filled */ au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->top_field); if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) - vb.v4l2_buf.sequence = dev->frame_count++; + vb->v4l2_buf.sequence = dev->frame_count++; else - vb.v4l2_buf.sequence = dev->vbi_frame_count++; + vb->v4l2_buf.sequence = dev->vbi_frame_count++; - vb.v4l2_buf.field = V4L2_FIELD_INTERLACED; - v4l2_get_timestamp(&vb.v4l2_buf.timestamp); - vb2_buffer_done(&vb, VB2_BUF_STATE_DONE); + vb->v4l2_buf.field = V4L2_FIELD_INTERLACED; + v4l2_get_timestamp(&vb->v4l2_buf.timestamp); + vb2_buffer_done(vb, VB2_BUF_STATE_DONE); } /* -- cgit v1.2.3