mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiaotian Feng <dfeng@redhat.com>
To: airlied@linux.ie, dri-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org, Xiaotian Feng <dfeng@redhat.com>
Subject: [PATCH 2/4] gpu/drm: fix memory leak in drm_fill_in_dev fail path
Date: Fri, 31 Jul 2009 16:55:56 +0800	[thread overview]
Message-ID: <1249030558-24143-3-git-send-email-dfeng@redhat.com> (raw)
In-Reply-To: <1249030558-24143-2-git-send-email-dfeng@redhat.com>

In drm_fill_in_dev, drm_ht_create/drm_agp_init/drm_gem_init all allocate
memories. but in the fail path, those memory is not freed, then memory
leaks is resulted.

Signed-off-by: Xiaotian Feng <dfeng@redhat.com>
---
 drivers/gpu/drm/drm_stub.c |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index 55bb8a8..8ac1ddb 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -259,7 +259,7 @@ static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev,
 		    && (dev->agp == NULL)) {
 			DRM_ERROR("Cannot initialize the agpgart module.\n");
 			retcode = -EINVAL;
-			goto error_out_unreg;
+			goto error_agp;
 		}
 		if (drm_core_has_MTRR(dev)) {
 			if (dev->agp)
@@ -274,7 +274,7 @@ static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev,
 	retcode = drm_ctxbitmap_init(dev);
 	if (retcode) {
 		DRM_ERROR("Cannot allocate memory for context bitmap.\n");
-		goto error_out_unreg;
+		goto error_ctxbitmap;
 	}
 
 	if (driver->driver_features & DRIVER_GEM) {
@@ -282,14 +282,29 @@ static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev,
 		if (retcode) {
 			DRM_ERROR("Cannot initialize graphics execution "
 				  "manager (GEM)\n");
-			goto error_out_unreg;
+			goto error_gem;
 		}
 	}
 
 	return 0;
 
-      error_out_unreg:
-	drm_lastclose(dev);
+error_gem:
+	drm_ctxbitmap_cleanup(dev);
+error_ctxbitmap:
+	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;
+	}
+error_agp:
+	drm_ht_remove(&dev->map_hash);
 	return retcode;
 }
 
-- 
1.6.2.5


  reply	other threads:[~2009-07-31  8:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-31  8:55 [PATCH 0/4] gpu/drm: fix memory leak when radeon_driver_load_kms fails Xiaotian Feng
2009-07-31  8:55 ` [PATCH 1/4] gpu/drm/radeon: fix memory leak in radeon_driver_load_kms Xiaotian Feng
2009-07-31  8:55   ` Xiaotian Feng [this message]
2009-07-31  8:55     ` [PATCH 3/4] gpu/drm: introduce drm_cleanup_dev to cleanup memories allocated from drm_fill_in_dev Xiaotian Feng
2009-07-31  8:55       ` [PATCH 4/4] gpu/drm: fix memory leak if dev->driver->load fails Xiaotian Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1249030558-24143-3-git-send-email-dfeng@redhat.com \
    --to=dfeng@redhat.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome