drm/i915: bail in alloc_pdp when !FULL_48BIT_PPGTT
Subsystems (2)
PATCH 2/3 drm/i915: bail in alloc_pdp when !FULL_48BIT_PPGTT
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
--- drivers/gpu/drm/i915/i915_gem_gtt.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +8 -5
@@ -567,13 +567,16 @@ static structi915_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; pdp =kzalloc (sizeof (*pdp),GFP_KERNEL ); -if (!pdp) -return ERR_PTR (-ENOMEM ); +if (!pdp) { + ret = -ENOMEM ; + goto fail_pdp; + } ret =__pdp_init (dev, pdp);if (ret)
@@ -589,7 +592,7 @@ fail_page_m:__pdp_fini (pdp); fail_bitmap:kfree (pdp); - +fail_pdp:return ERR_PTR (ret); }
Signature · 6 lines
2.5.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 44 lines · Matthew Auld
If we are not in
FULL_48BIT_PPGTTmode then we really shouldn't continue on with our allocations, given that the call tofree_pdpwould bail early without freeing everything, thus leaking memory.v2:
(Joonas Lahtinen)
- tidy up with goto teardown pathCc Chris Wilson <[email protected]>Cc Joonas Lahtinen <[email protected]>Signed-off-by Matthew Auld <[email protected]>---
drivers/gpu/drm/i915/i915_gem_gtt.c | 13 ++++++++-----1 file changed, 8 insertions(+), 5 deletions(-)drivers/gpu/drm/i915/i915_gem_gtt.c +1
-1@@ -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 ;drivers/gpu/drm/i915/i915_gem_gtt.c +2
-1-WARN_ON (!USES_FULL_48BIT_PPGTT (dev)); +if (WARN_ON (!USES_FULL_48BIT_PPGTT (dev))) + goto fail_pdp;
pdp =kzalloc(sizeof(*pdp), GFP_KERNEL);drivers/gpu/drm/i915/i915_gem_gtt.c +4
-2-if (!pdp) -return ERR_PTR (-ENOMEM ); +if (!pdp) { + ret = -ENOMEM ; + goto fail_pdp; + }
ret =__pdp_init(dev, pdp);
if (ret)drivers/gpu/drm/i915/i915_gem_gtt.c +0
-0@@ -589,7 +592,7 @@ fail_page_m: __pdp_fini(pdp);fail_bitmap:
kfree(pdp);
drivers/gpu/drm/i915/i915_gem_gtt.c fail_page_m: · line 595
Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +1
-1- +fail_pdp:
According to the Kernel Coding Style Chapter 7: "Centralized exiting of functions", the naming of this label should likely just be "fail:", as it does not free anything. The label should describe what is done under the label, not why the label is entered (which may vary as function grows).
With that,
Regards, Joonas
Quoted 3 lines
return
ERR_PTR(ret);
}
Signature · 7 lines
Joonas Lahtinen Open Source Technology Center Intel Corporation _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx