From patchwork Wed Oct 30 23:09:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wang yanqing X-Patchwork-Id: 3117961 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9F69EBF924 for ; Wed, 30 Oct 2013 23:09:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2AADE202FE for ; Wed, 30 Oct 2013 23:09:53 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9A64A20375 for ; Wed, 30 Oct 2013 23:09:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 61DC8EF0D0; Wed, 30 Oct 2013 16:09:45 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pb0-f49.google.com (mail-pb0-f49.google.com [209.85.160.49]) by gabe.freedesktop.org (Postfix) with ESMTP id E0B32EF0D0 for ; Wed, 30 Oct 2013 16:09:43 -0700 (PDT) Received: by mail-pb0-f49.google.com with SMTP id xb4so2061768pbc.22 for ; Wed, 30 Oct 2013 16:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mail-followup-to:mime-version :content-type:content-disposition:user-agent; bh=ROIgZDNpgjgJzO3DEkU46xLikaTLsTP6fUtRXYE5ESI=; b=0SkzKl/I6Q0i8Nt41Vl6zeeSKhjBVlU87cUYwjaIzEqdPzunKAc3f2+iVsAUKlOMbw SBaTg6knbAtRV8j44DgTQkSIhqJmhXcPd4DOVqZfd4eZ8hwKMQFPSqcrx2w2u8ZRcbxa EXh1uIyDdDANf4gu2agw/TgaAG6Xg7ivhtPfRr02OYu0KURnEauJ1Qx4hH9MN79KYoxr 1wvaHRpuqHnOycwrqPXtC5e+E9bWg0+HmFSto2VBwGbe2fvOKzznP8BvPiWP7aRXLvkj Ra1LrFkEDb63y0KMtRiCv1pUruEL2V/6kH1sYOOM0sEAl3cgB6lqlh1oG7Jc0gFTnwxW 5HKA== X-Received: by 10.68.253.67 with SMTP id zy3mr91011pbc.137.1383174583718; Wed, 30 Oct 2013 16:09:43 -0700 (PDT) Received: from udknight.localhost ([120.42.56.66]) by mx.google.com with ESMTPSA id ta10sm1028525pab.5.2013.10.30.16.09.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Oct 2013 16:09:42 -0700 (PDT) Received: from udknight.localhost (udknight.localhost [127.0.0.1]) by udknight.localhost (8.14.4/8.14.4) with ESMTP id r9UN9H5b005716; Thu, 31 Oct 2013 07:09:17 +0800 Received: (from root@localhost) by udknight.localhost (8.14.4/8.14.4/Submit) id r9UN9Hv4005713; Thu, 31 Oct 2013 07:09:17 +0800 Date: Thu, 31 Oct 2013 07:09:17 +0800 From: Wang YanQing To: airlied@linux.ie Subject: [PATCH 2/5] drm:drm_pci: fix resource leak in drm_get_pci_dev Message-ID: <20131030230914.GA5697@udknight> Mail-Followup-To: Wang YanQing , airlied@linux.ie, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 We should call drm_cleanup_in_dev in error handle code path after drm_fill_in_dev had been called, or it will cause resource leak heavily, vmalloc leak etc. This patch also add call to dev->unload in error handle code path. Signed-off-by: Wang YanQing --- drivers/gpu/drm/drm_pci.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c index 14194b6..5f15805 100644 --- a/drivers/gpu/drm/drm_pci.c +++ b/drivers/gpu/drm/drm_pci.c @@ -345,16 +345,16 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent, pci_set_drvdata(pdev, dev); ret = drm_get_minor(dev, &dev->control, DRM_MINOR_CONTROL); if (ret) - goto err_g2; + goto err_g3; } if ((ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY))) - goto err_g3; + goto err_g4; if (dev->driver->load) { ret = dev->driver->load(dev, ent->driver_data); if (ret) - goto err_g4; + goto err_g5; } /* setup the grouping for the legacy output */ @@ -362,7 +362,7 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent, ret = drm_mode_group_init_legacy_group(dev, &dev->primary->mode_group); if (ret) - goto err_g4; + goto err_g6; } list_add_tail(&dev->driver_item, &driver->device_list); @@ -373,12 +373,16 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent, mutex_unlock(&drm_global_mutex); return 0; - -err_g4: +err_g6: + if (dev->driver->unload) + dev->driver->unload(dev); +err_g5: drm_put_minor(&dev->primary); -err_g3: +err_g4: if (drm_core_check_feature(dev, DRIVER_MODESET)) drm_put_minor(&dev->control); +err_g3: + drm_cleanup_in_dev(dev); err_g2: pci_disable_device(pdev); err_g1: