From patchwork Wed Oct 30 23:10:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wang yanqing X-Patchwork-Id: 3117981 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 11FF29F3E2 for ; Wed, 30 Oct 2013 23:11:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 97C2B2037D for ; Wed, 30 Oct 2013 23:11:00 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1CDEB201BE for ; Wed, 30 Oct 2013 23:10:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4C36BEF0D2; Wed, 30 Oct 2013 16:10:53 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by gabe.freedesktop.org (Postfix) with ESMTP id 6226EEF0C8 for ; Wed, 30 Oct 2013 16:10:51 -0700 (PDT) Received: by mail-pa0-f46.google.com with SMTP id rd3so1642001pab.5 for ; Wed, 30 Oct 2013 16:10:51 -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=sUFeqTVlbLWF5yJfL6ktwbTmHviQmmLHxZoWPcEOivg=; b=F1nY8MxdwiT5yRGeJbnFWMzgjAhnmUbLwTikW794hIV7Ss10b06OoT7SH45ufMyYmb flqkSQt9ArehsGgSm4jCdoaHUoCyQvFeAL0ioFH4m5FTsQC9EwMFxbXOYtdfciwVu8wX aIYCK3Whs7Ho5+aan0XJy/l+sm9yNrhGykYFKMf2bf+TiifXFOz7v10KpPhK/pNiLfre yfX7BZZjTVmt92DxNC+zi/65FKuonZwmrXHReLA0zEDXbtrruLr5GY9syo3qsZBjdfDp lsIGhdeqGmRG+LOO3mS8FnpvAb8xsviTm+jtH329BSjOqbNu9Mi3299Z0ZVvhvE61aK1 TjrA== X-Received: by 10.68.191.106 with SMTP id gx10mr136869pbc.47.1383174651051; Wed, 30 Oct 2013 16:10:51 -0700 (PDT) Received: from udknight.localhost ([120.42.56.66]) by mx.google.com with ESMTPSA id b3sm326747pbu.38.2013.10.30.16.10.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Oct 2013 16:10:50 -0700 (PDT) Received: from udknight.localhost (udknight.localhost [127.0.0.1]) by udknight.localhost (8.14.4/8.14.4) with ESMTP id r9UNAO7d005737; Thu, 31 Oct 2013 07:10:24 +0800 Received: (from root@localhost) by udknight.localhost (8.14.4/8.14.4/Submit) id r9UNAOdX005734; Thu, 31 Oct 2013 07:10:24 +0800 Date: Thu, 31 Oct 2013 07:10:24 +0800 From: Wang YanQing To: airlied@linux.ie Subject: [PATCH 3/5] drm:drm_platform: fix resource leak in drm_get_platform_dev Message-ID: <20131030231023.GA5719@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_platform.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_platform.c b/drivers/gpu/drm/drm_platform.c index b8a282e..1198fa4 100644 --- a/drivers/gpu/drm/drm_platform.c +++ b/drivers/gpu/drm/drm_platform.c @@ -66,17 +66,17 @@ int drm_get_platform_dev(struct platform_device *platdev, if (drm_core_check_feature(dev, DRIVER_MODESET)) { ret = drm_get_minor(dev, &dev->control, DRM_MINOR_CONTROL); if (ret) - goto err_g1; + goto err_g2; } ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY); if (ret) - goto err_g2; + goto err_g3; if (dev->driver->load) { ret = dev->driver->load(dev, 0); if (ret) - goto err_g3; + goto err_g4; } /* setup the grouping for the legacy output */ @@ -84,7 +84,7 @@ int drm_get_platform_dev(struct platform_device *platdev, ret = drm_mode_group_init_legacy_group(dev, &dev->primary->mode_group); if (ret) - goto err_g3; + goto err_g5; } list_add_tail(&dev->driver_item, &driver->device_list); @@ -96,12 +96,16 @@ int drm_get_platform_dev(struct platform_device *platdev, driver->date, dev->primary->index); return 0; - -err_g3: +err_g5: + if (dev->driver->unload) + dev->driver->unload(dev); +err_g4: drm_put_minor(&dev->primary); -err_g2: +err_g3: if (drm_core_check_feature(dev, DRIVER_MODESET)) drm_put_minor(&dev->control); +err_g2: + drm_cleanup_in_dev(dev); err_g1: kfree(dev); mutex_unlock(&drm_global_mutex);