From patchwork Wed Oct 30 23:05:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wang yanqing X-Patchwork-Id: 3117941 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 C16EB9F3E2 for ; Wed, 30 Oct 2013 23:06:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 394542037D for ; Wed, 30 Oct 2013 23:06:17 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id B9042201BE for ; Wed, 30 Oct 2013 23:06:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 45EB5EF075; Wed, 30 Oct 2013 16:06:10 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pd0-f178.google.com (mail-pd0-f178.google.com [209.85.192.178]) by gabe.freedesktop.org (Postfix) with ESMTP id B6D5DEF075 for ; Wed, 30 Oct 2013 16:06:05 -0700 (PDT) Received: by mail-pd0-f178.google.com with SMTP id x10so1639534pdj.9 for ; Wed, 30 Oct 2013 16:06:05 -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=M7TW/lyON95VryH1rr8q5JjexY/zDPi/qrcfzK23cvE=; b=xmRhN05SWB4e2FeQoVlQp0w6Abzm2h4hARogWgyVnCiXjiUalHa6kNCn/AFVx+7EVv v9FwONMIJkxxWfk88vaXxM9oytRrUHAzv2T0W562yR+zHQyjO/bUSvFKaxAazSUhPKdM 1X0I8m/sx0rkboMMbcYns14bYjQoNjpzC6uoEo2VTZhsLh0utGfIWSGlfHyRxZP38+pt QJCE6thLkDWoPWELvEvh+W8Jq4ylwnTx1Fi2e3yCXqEyCzALyipWRxIjZ/Bj/Evk16EE RJ93EPUJbHXAbo3Mn5rHev8bOcPd4a0y99ciMPdkwpFGYStHaJLR95Keh5gBImS1U7pH sCIA== X-Received: by 10.66.189.98 with SMTP id gh2mr901411pac.60.1383174365088; Wed, 30 Oct 2013 16:06:05 -0700 (PDT) Received: from udknight.localhost ([120.42.56.66]) by mx.google.com with ESMTPSA id hw10sm325865pbc.24.2013.10.30.16.06.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Oct 2013 16:06:04 -0700 (PDT) Received: from udknight.localhost (udknight.localhost [127.0.0.1]) by udknight.localhost (8.14.4/8.14.4) with ESMTP id r9UN5fjK005592; Thu, 31 Oct 2013 07:05:41 +0800 Received: (from root@localhost) by udknight.localhost (8.14.4/8.14.4/Submit) id r9UN5eeD005589; Thu, 31 Oct 2013 07:05:40 +0800 Date: Thu, 31 Oct 2013 07:05:40 +0800 From: Wang YanQing To: airlied@linux.ie Subject: [PATCH 1/5] drm:drm_stub: add new function drm_cleanup_in_dev Message-ID: <20131030230540.GA5553@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 Introduce a new function, drm_cleanup_in_dev, we could use it to release resources allocated by drm_fill_in_dev in the error handle code path after drm_fill_in_dev have been called. Signed-off-by: Wang YanQing --- drivers/gpu/drm/drm_stub.c | 62 ++++++++++++++++++++++++---------------------- include/drm/drmP.h | 1 + 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c index 16f3ec5..3f3b167 100644 --- a/drivers/gpu/drm/drm_stub.c +++ b/drivers/gpu/drm/drm_stub.c @@ -250,6 +250,37 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data, return 0; } +void drm_cleanup_in_dev(struct drm_device *dev) +{ + struct drm_driver *driver; + struct drm_map_list *r_list, *list_temp; + + driver = dev->driver; + if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) && + dev->agp && dev->agp->agp_mtrr >= 0) { + int retval; + retval = mtrr_del(dev->agp->agp_mtrr, + dev->agp->agp_info.aper_base, + dev->agp->agp_info.aper_size * 1024 * 1024); + DRM_DEBUG("mtrr_del=%d\n", retval); + } + + if (drm_core_has_AGP(dev) && dev->agp) { + kfree(dev->agp); + dev->agp = NULL; + } + + list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) + drm_rmmap(dev, r_list->map); + drm_ht_remove(&dev->map_hash); + + drm_ctxbitmap_cleanup(dev); + + if (dev->driver->driver_features & DRIVER_GEM) + drm_gem_destroy(dev); +} +EXPORT_SYMBOL(drm_cleanup_in_dev); + int drm_fill_in_dev(struct drm_device *dev, const struct pci_device_id *ent, struct drm_driver *driver) @@ -438,52 +469,23 @@ static void drm_unplug_minor(struct drm_minor *minor) */ void drm_put_dev(struct drm_device *dev) { - struct drm_driver *driver; - struct drm_map_list *r_list, *list_temp; - DRM_DEBUG("\n"); - if (!dev) { DRM_ERROR("cleanup called no dev\n"); return; } - driver = dev->driver; drm_lastclose(dev); - if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) && - dev->agp && dev->agp->agp_mtrr >= 0) { - int retval; - retval = mtrr_del(dev->agp->agp_mtrr, - dev->agp->agp_info.aper_base, - dev->agp->agp_info.aper_size * 1024 * 1024); - DRM_DEBUG("mtrr_del=%d\n", retval); - } - if (dev->driver->unload) dev->driver->unload(dev); - if (drm_core_has_AGP(dev) && dev->agp) { - kfree(dev->agp); - dev->agp = NULL; - } - drm_vblank_cleanup(dev); - - list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) - drm_rmmap(dev, r_list->map); - drm_ht_remove(&dev->map_hash); - - drm_ctxbitmap_cleanup(dev); + drm_cleanup_in_dev(dev); if (drm_core_check_feature(dev, DRIVER_MODESET)) drm_put_minor(&dev->control); - - if (driver->driver_features & DRIVER_GEM) - drm_gem_destroy(dev); - drm_put_minor(&dev->primary); - list_del(&dev->driver_item); kfree(dev->devname); kfree(dev); diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 63d17ee..2dcf83a 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -1761,6 +1761,7 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map) #include +extern void drm_cleanup_in_dev(struct drm_device *dev); extern int drm_fill_in_dev(struct drm_device *dev, const struct pci_device_id *ent, struct drm_driver *driver);