From patchwork Sun Jan 12 16:24:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Schaefer X-Patchwork-Id: 21534 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1W2NpT-0007Wh-IU; Sun, 12 Jan 2014 17:24:03 +0100 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.72/mailfrontend-6) with esmtp id 1W2NpR-0007yW-4U; Sun, 12 Jan 2014 17:24:03 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751216AbaALQXz (ORCPT + 1 other); Sun, 12 Jan 2014 11:23:55 -0500 Received: from mail-ea0-f171.google.com ([209.85.215.171]:39436 "EHLO mail-ea0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751028AbaALQXx (ORCPT ); Sun, 12 Jan 2014 11:23:53 -0500 Received: by mail-ea0-f171.google.com with SMTP id h10so2869543eak.16 for ; Sun, 12 Jan 2014 08:23:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=SDcDJbMLQ898LmdKV2UbiqRq5ljfSEZ7LiV2G0WF9wE=; b=NHOWyQrurzAfP286NTRqjRWk0CiMXHTJqTY7Hj0FMMw7cRdoiVFLzmJnngCEmd3Pjq undrJVNKHZ37zqSI2MoWEVqhF6ICl7mmPOZUy59XRGOlCxEhaATkMIAEAbdhYk0WQ6rX wEnj2rlZKQROCPfo980nQjk1L8UlXACaRaR1twHS8OYzurGBfDHKEna/VfTsfRUMgcVC PkKXoWOVdsRcFBVH3kc7bMZvQfFwA6EcKBTrgdlgaMwEzTmNBVSLU088i8hV1DOJ8srQ 9Jmpd8AbbIS0g38TAZKMNu9jMKkxoEWgQbsxBF+Tt8Wh5u6OHlVc+sq07FEMRvWOEP7r G1Gg== X-Received: by 10.15.36.135 with SMTP id i7mr22453771eev.93.1389543832387; Sun, 12 Jan 2014 08:23:52 -0800 (PST) Received: from Athlon64X2-5000.site (ip-178-200-114-182.unitymediagroup.de. [178.200.114.182]) by mx.google.com with ESMTPSA id o47sm32222713eem.21.2014.01.12.08.23.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Jan 2014 08:23:51 -0800 (PST) From: =?UTF-8?q?Frank=20Sch=C3=A4fer?= To: m.chehab@samsung.com Cc: linux-media@vger.kernel.org, =?UTF-8?q?Frank=20Sch=C3=A4fer?= Subject: [RFT/RFC PATCH 8/8] em28xx-v4l: fix the freeing of the video devices memory Date: Sun, 12 Jan 2014 17:24:25 +0100 Message-Id: <1389543865-2534-9-git-send-email-fschaefer.oss@googlemail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1389543865-2534-1-git-send-email-fschaefer.oss@googlemail.com> References: <1389543865-2534-1-git-send-email-fschaefer.oss@googlemail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2014.1.12.161515 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, CT_TEXT_PLAIN_UTF8_CAPS 0, DKIM_SIGNATURE 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_MEDIA_BODY 0, __CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __FRAUD_BODY_WEBMAIL 0, __FRAUD_WEBMAIL 0, __FRAUD_WEBMAIL_FROM 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __PHISH_SPEAR_STRUCTURE_1 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS , __YOUTUBE_RCVD 0' Remove some dead code from em28xx_v4l2_fini() and fix the leaking of the video, vbi and radio video_device struct memories. Signed-off-by: Frank Schäfer --- drivers/media/usb/em28xx/em28xx-video.c | 56 +++++++++++++++++-------------- 1 Datei geändert, 30 Zeilen hinzugefügt(+), 26 Zeilen entfernt(-) diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c index 87b140f..a643adda 100644 --- a/drivers/media/usb/em28xx/em28xx-video.c +++ b/drivers/media/usb/em28xx/em28xx-video.c @@ -1899,29 +1899,19 @@ static int em28xx_v4l2_fini(struct em28xx *dev) em28xx_uninit_usb_xfer(dev, EM28XX_ANALOG_MODE); if (dev->radio_dev) { - if (video_is_registered(dev->radio_dev)) - video_unregister_device(dev->radio_dev); - else - video_device_release(dev->radio_dev); - dev->radio_dev = NULL; + em28xx_info("V4L2 device %s deregistered\n", + video_device_node_name(dev->radio_dev)); + video_unregister_device(dev->radio_dev); } if (dev->vbi_dev) { em28xx_info("V4L2 device %s deregistered\n", video_device_node_name(dev->vbi_dev)); - if (video_is_registered(dev->vbi_dev)) - video_unregister_device(dev->vbi_dev); - else - video_device_release(dev->vbi_dev); - dev->vbi_dev = NULL; + video_unregister_device(dev->vbi_dev); } if (dev->vdev) { em28xx_info("V4L2 device %s deregistered\n", video_device_node_name(dev->vdev)); - if (video_is_registered(dev->vdev)) - video_unregister_device(dev->vdev); - else - video_device_release(dev->vdev); - dev->vdev = NULL; + video_unregister_device(dev->vdev); } v4l2_ctrl_handler_free(&dev->ctrl_handler); @@ -1955,9 +1945,7 @@ static int em28xx_v4l2_close(struct file *filp) mutex_lock(&dev->lock); if (dev->users == 1) { - /* the device is already disconnect, - free the remaining resources */ - + /* free the remaining resources if device is disconnected */ if (dev->disconnected) { kfree(dev->alt_max_pkt_size_isoc); goto exit; @@ -1985,6 +1973,23 @@ exit: return 0; } +/* + * em28xx_videodevice_release() + * called when the last user of the video device exits and frees the memeory + */ +static void em28xx_videodevice_release(struct video_device *vdev) +{ + struct em28xx *dev = video_get_drvdata(vdev); + + video_device_release(vdev); + if (vdev == dev->vdev) + dev->vdev = NULL; + else if (vdev == dev->vbi_dev) + dev->vbi_dev = NULL; + else if (vdev == dev->radio_dev) + dev->radio_dev = NULL; +} + static const struct v4l2_file_operations em28xx_v4l_fops = { .owner = THIS_MODULE, .open = em28xx_v4l2_open, @@ -2039,11 +2044,10 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = { }; static const struct video_device em28xx_video_template = { - .fops = &em28xx_v4l_fops, - .release = video_device_release_empty, - .ioctl_ops = &video_ioctl_ops, - - .tvnorms = V4L2_STD_ALL, + .fops = &em28xx_v4l_fops, + .ioctl_ops = &video_ioctl_ops, + .release = em28xx_videodevice_release, + .tvnorms = V4L2_STD_ALL, }; static const struct v4l2_file_operations radio_fops = { @@ -2069,9 +2073,9 @@ static const struct v4l2_ioctl_ops radio_ioctl_ops = { }; static struct video_device em28xx_radio_template = { - .name = "em28xx-radio", - .fops = &radio_fops, - .ioctl_ops = &radio_ioctl_ops, + .fops = &radio_fops, + .ioctl_ops = &radio_ioctl_ops, + .release = em28xx_videodevice_release, }; /* I2C possible address to saa7115, tvp5150, msp3400, tvaudio */