From patchwork Wed Oct 30 23:11:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wang yanqing X-Patchwork-Id: 3118001 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 6F1E9BF924 for ; Wed, 30 Oct 2013 23:12:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EC02D2039F for ; Wed, 30 Oct 2013 23:12:07 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 766972039C for ; Wed, 30 Oct 2013 23:12:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0AA19EF0D1; Wed, 30 Oct 2013 16:12:01 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com [209.85.192.169]) by gabe.freedesktop.org (Postfix) with ESMTP id EBDEEEF0D1 for ; Wed, 30 Oct 2013 16:11:59 -0700 (PDT) Received: by mail-pd0-f169.google.com with SMTP id q10so1658049pdj.28 for ; Wed, 30 Oct 2013 16:11:59 -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=vpAmDwsVLcqDR43OsPypTAQaxVNz308mwZAQwX2KfCI=; b=NA5a+BL4l3cObtt9fyQFzzmqWSjb77Czg2FsNk23XyNs+2xVedmfXjmtlgdivtkpsB O5fqxmYD8NuuDSjBf5qFgECZuPYfb1una4hSUQGXBMe6MjL2SyaQhVN825jLHEjBGQal XGKvV5QwkdSQ1ZNPMNWaVyW6GW0NHP8BT2k6LJtNs2vfeoPucYr6edw955uXan//9O3S Xtjsa8PlZ6fbMHI2qQxg/Od7m6qKDQ88xRyQvXxQUlMUZxUg71kjdcOoKmIMooeXCJDt yqzVkr5La660WI+fASvqzNeXzR3fsQzn0T3ISRuy4J4dCyvP3Tdw+lAznvhREaPSksJx oI+g== X-Received: by 10.66.145.4 with SMTP id sq4mr224841pab.178.1383174719763; Wed, 30 Oct 2013 16:11:59 -0700 (PDT) Received: from udknight.localhost ([120.42.56.66]) by mx.google.com with ESMTPSA id wp8sm341758pbc.26.2013.10.30.16.11.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Oct 2013 16:11:59 -0700 (PDT) Received: from udknight.localhost (udknight.localhost [127.0.0.1]) by udknight.localhost (8.14.4/8.14.4) with ESMTP id r9UNBa8S005752; Thu, 31 Oct 2013 07:11:36 +0800 Received: (from root@localhost) by udknight.localhost (8.14.4/8.14.4/Submit) id r9UNBZbt005749; Thu, 31 Oct 2013 07:11:35 +0800 Date: Thu, 31 Oct 2013 07:11:35 +0800 From: Wang YanQing To: airlied@linux.ie Subject: [PATCH 4/5] drm:drm_usb: fix resource leak in drm_get_usb_dev Message-ID: <20131030231135.GB5719@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=ham 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_usb.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_usb.c b/drivers/gpu/drm/drm_usb.c index 34a156f..7e4de60 100644 --- a/drivers/gpu/drm/drm_usb.c +++ b/drivers/gpu/drm/drm_usb.c @@ -31,23 +31,23 @@ int drm_get_usb_dev(struct usb_interface *interface, usb_set_intfdata(interface, dev); 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 */ 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); @@ -58,11 +58,15 @@ int drm_get_usb_dev(struct usb_interface *interface, 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: drm_put_minor(&dev->control); +err_g2: + drm_cleanup_in_dev(dev); err_g1: kfree(dev); mutex_unlock(&drm_global_mutex);