From patchwork Sat May 11 02:30:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Pablo Carballo X-Patchwork-Id: 2552871 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from bear.ext.ti.com (bear.ext.ti.com [192.94.94.41]) by patchwork2.kernel.org (Postfix) with ESMTP id 2E893DF2A2 for ; Sat, 11 May 2013 02:32:18 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id r4B2Upxx010386; Fri, 10 May 2013 21:30:52 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id r4B2UpB3027210; Fri, 10 May 2013 21:30:51 -0500 Received: from dlelxv23.itg.ti.com (172.17.1.198) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.2.342.3; Fri, 10 May 2013 21:30:51 -0500 Received: from linux.omap.com (dlelxs01.itg.ti.com [157.170.227.31]) by dlelxv23.itg.ti.com (8.13.8/8.13.8) with ESMTP id r4B2UoID032582; Fri, 10 May 2013 21:30:51 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 6ED9780627; Fri, 10 May 2013 21:30:50 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflp51.itg.ti.com (dflp51.itg.ti.com [128.247.22.94]) by linux.omap.com (Postfix) with ESMTP id 19CCD80626 for ; Fri, 10 May 2013 21:30:49 -0500 (CDT) Received: from neches.ext.ti.com (neches.ext.ti.com [192.91.81.29]) by dflp51.itg.ti.com (8.13.7/8.13.8) with ESMTP id r4B2UmbT011275 for ; Fri, 10 May 2013 21:30:48 -0500 (CDT) Received: from mail6.bemta12.messagelabs.com (mail6.bemta12.messagelabs.com [216.82.250.247]) by neches.ext.ti.com (8.13.7/8.13.7) with ESMTP id r4B2UmxD000308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 10 May 2013 21:30:48 -0500 Received: from [216.82.250.51:55230] by server-13.bemta-12.messagelabs.com id 00/A8-17479-85DAD815; Sat, 11 May 2013 02:30:48 +0000 X-Env-Sender: jose.carballo@ridgerun.com X-Msg-Ref: server-16.tower-108.messagelabs.com!1368239446!7801310!1 X-Originating-IP: [209.85.214.179] X-SpamReason: No, hits=0.9 required=7.0 tests=HTML_40_50,HTML_MESSAGE, RCVD_BY_IP X-StarScan-Received: X-StarScan-Version: 6.9.6; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17774 invoked from network); 11 May 2013 02:30:47 -0000 Received: from mail-ob0-f179.google.com (HELO mail-ob0-f179.google.com) (209.85.214.179) by server-16.tower-108.messagelabs.com with RC4-SHA encrypted SMTP; 11 May 2013 02:30:47 -0000 Received: by mail-ob0-f179.google.com with SMTP id xn12so4850871obc.38 for ; Fri, 10 May 2013 19:30:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:x-originating-ip:date:message-id:subject :from:to:content-type:x-gm-message-state; bh=gg2meiSUsF/0Vjc4/6Vtn80QFwnuCIXVo52ZawMXGX0=; b=mZsCA/vgeynjNHdqIRg3uAtfT0FOrUnCC+ijkx+umFnTVgLyw/K28W+huW8oATmvvr QJWPaScXHoIF3YayEMW4Gus4QsbyrktgdcbugAGkDyOEhPC+lhWhWO2hTAPFvatEQJ2b VZ8/sgcIcBLZVBCa4w2MNzCxGdTD8uqRCXGC3Za30tWXVlv+gN2rcwb6uclOyzPN2B/2 AjtSqoKYH1dZO0rl2RZUQm6oEh82JSvvaxlwuycVeUC5PW0u8LPbRB8W6nkwEPfFZUQh hguNe+t399SwJ0GAn+NhOhlhCTuk9viHgjmCAqUhPktRXffntIj76zQKG99nh9vCCrF5 ZHqw== MIME-Version: 1.0 X-Received: by 10.60.132.238 with SMTP id ox14mr8197665oeb.102.1368239445632; Fri, 10 May 2013 19:30:45 -0700 (PDT) Received: by 10.182.118.230 with HTTP; Fri, 10 May 2013 19:30:45 -0700 (PDT) X-Originating-IP: [181.193.1.26] Date: Fri, 10 May 2013 20:30:45 -0600 Message-ID: Subject: Patch for vpfe_remove() From: Jose Pablo Carballo To: X-Gm-Message-State: ALoCoQk1CZ7AgETvgkxE3XAsn0BhbpKbyqOkOIir38lm5rh3woQmkcHazzuXvOt/n1srQpz1XHjK X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com Hi, In file drivers/media/platform/davinci/vpfe_capture.c, function vpfe_remove(): According to my understanding, the story of vpfe_dev->video_dev is as follows: 1. It starts to exist at vpfe_probe(), through the function video_device_alloc(): vfd = video_device_alloc(); ... vfd->release = video_device_release; ... vpfe_dev->video_dev = vfd; ... ret = video_register_device(vpfe_dev->video_dev, VFL_TYPE_GRABBER, -1); Note that video_device_alloc() is fundamentally a call to kzalloc(), and video_device_release() is the respective call to kfree(). 2. It ends to exist in vpfe_remove(): video_unregister_device(vpfe_dev->video_dev); ... kfree(vpfe_dev); <- I believe this won't free the memory pointed by vpfe_dev->video_dev If you look at the implementation of video_unregister_device(), you would notice it doesn't call video_device_release(). Unless that calls happens automatically at some point, given that vpfe_dev->video_dev->release points to video_device_release(), the explicit call to video_device_release() is needed. Another hint to this, is that if you look at the error handling logic at the vpfe_probe() function, you will see the proposed chain of events do happen: probe_out_v4l2_unregister: v4l2_device_unregister(&vpfe_dev->v4l2_dev); probe_out_video_release: if (!video_is_registered(vpfe_dev->video_dev)) video_device_release(vpfe_dev->video_dev); <- Explicitly freed this memory Thanks, JP diff --git a/drivers/media/platform/davinci/vpfe_capture.c b/drivers/media/platform/davinci/vpfe_capture.c index 28d019d..f0f272f 100644 --- a/drivers/media/platform/davinci/vpfe_capture.c +++ b/drivers/media/platform/davinci/vpfe_capture.c @@ -2045,6 +2045,7 @@ static int vpfe_remove(struct platform_device *pdev) kfree(vpfe_dev->sd); v4l2_device_unregister(&vpfe_dev->v4l2_dev); video_unregister_device(vpfe_dev->video_dev); + video_device_release(vpfe_dev->video_dev); kfree(vpfe_dev); kfree(ccdc_cfg); return 0;