From patchwork Thu Feb 26 22:33:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 5896271 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9ADDCBF440 for ; Thu, 26 Feb 2015 22:33:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 995CD203AB for ; Thu, 26 Feb 2015 22:33:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 799A620397 for ; Thu, 26 Feb 2015 22:33:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754586AbbBZWdT (ORCPT ); Thu, 26 Feb 2015 17:33:19 -0500 Received: from resqmta-po-09v.sys.comcast.net ([96.114.154.168]:53328 "EHLO resqmta-po-09v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754578AbbBZWdS (ORCPT ); Thu, 26 Feb 2015 17:33:18 -0500 Received: from resomta-po-18v.sys.comcast.net ([96.114.154.242]) by resqmta-po-09v.sys.comcast.net with comcast id xAYs1p0095E3ZMc01AZHeF; Thu, 26 Feb 2015 22:33:17 +0000 Received: from mail.gonehiking.org ([50.134.149.16]) by resomta-po-18v.sys.comcast.net with comcast id xAZF1p00b0MU7Qa01AZGmv; Thu, 26 Feb 2015 22:33:17 +0000 Received: from lorien.internal (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id 80D0640110; Thu, 26 Feb 2015 15:33:15 -0700 (MST) From: Shuah Khan To: mchehab@osg.samsung.com, hans.verkuil@cisco.com, prabhakar.csengg@gmail.com, Julia.Lawall@lip6.fr Cc: Shuah Khan , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: au0828 - embed vdev and vbi_dev structs in au0828_dev Date: Thu, 26 Feb 2015 15:33:13 -0700 Message-Id: <1424989993-8458-1-git-send-email-shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1424989997; bh=38ZBXiWE8g2Q1/GEqBPC5dgrBym5WlaDftEb0y1tQ3s=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=vACKkyCafdQ7uTqMLhBZ8JhEasQINcQOrjWtQZhFJTsWeWMhvHxEXjD9jCmN5oWbm 6toQcCSV7q75rR6Ke5zHP+NniW2q5QhBrgRWVSPiagp8aS5TR3PIp/NrtLc+bs1MIB M4nERYEynxlnDYNZp6wDGSH5Iy6Uct0vWTu5FweUcPq9Mqy4kLqhCEDmg/bNABU5cG gk6GBMMuSh9AFUb6XeTPvqhj+SPfIy2ixF6bmhI2Xg8+pCWj1ODENUb5ZRB6sqTTR3 N1tRONMJQsplkg4l3tT/V/gIpAU92wQKFBOx2ea9a+Utx9JQbUyXvxhN74Fsd+sucB NyloN1K0Uq39Q== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/media/usb/au0828/au0828-video.c | 66 +++++++++++---------------------- drivers/media/usb/au0828/au0828.h | 4 +- 2 files changed, 24 insertions(+), 46 deletions(-) diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c index a27cb5f..f47ee90 100644 --- a/drivers/media/usb/au0828/au0828-video.c +++ b/drivers/media/usb/au0828/au0828-video.c @@ -900,10 +900,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); } @@ -1286,7 +1284,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; } @@ -1704,7 +1702,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, }; @@ -1814,52 +1812,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); @@ -1868,8 +1850,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); @@ -1882,14 +1864,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 eb15187..3b48000 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;