diff mbox

drm/i915: bail in alloc_pdp when !FULL_48BIT_PPGTT

Message ID 1461661687-23888-1-git-send-email-matthew.auld@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Matthew Auld April 26, 2016, 9:08 a.m. UTC
If we are not in FULL_48BIT_PPGTT mode then we really shouldn't
continue on with our allocations, given that the call to free_pdp would
bail early without freeing everything, thus leaking memory.

v2:
(Joonas Lahtinen)
  - tidy up with goto teardown path
v3:
(Joonas Lahtinen)
  - use more appropriate goto label name

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Chris Wilson April 26, 2016, 9:31 a.m. UTC | #1
On Tue, Apr 26, 2016 at 10:08:07AM +0100, Matthew Auld wrote:
> If we are not in FULL_48BIT_PPGTT mode then we really shouldn't
> continue on with our allocations, given that the call to free_pdp would
> bail early without freeing everything, thus leaking memory.

Why? Why are you second guessing the caller who asked for a
i915_page_directory struct to be allocated? Is there any reason for a
warn here?
-Chris
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 0d666b3..3ace3d0 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -567,13 +567,16 @@  static struct
 i915_page_directory_pointer *alloc_pdp(struct drm_device *dev)
 {
 	struct i915_page_directory_pointer *pdp;
-	int ret = -ENOMEM;
+	int ret = -EINVAL;
 
-	WARN_ON(!USES_FULL_48BIT_PPGTT(dev));
+	if (WARN_ON(!USES_FULL_48BIT_PPGTT(dev)))
+		goto fail;
 
 	pdp = kzalloc(sizeof(*pdp), GFP_KERNEL);
-	if (!pdp)
-		return ERR_PTR(-ENOMEM);
+	if (!pdp) {
+		ret = -ENOMEM;
+		goto fail;
+	}
 
 	ret = __pdp_init(dev, pdp);
 	if (ret)
@@ -589,7 +592,7 @@  fail_page_m:
 	__pdp_fini(pdp);
 fail_bitmap:
 	kfree(pdp);
-
+fail:
 	return ERR_PTR(ret);
 }