Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915/gem: Fix oops in error handling code

This code will Oops when it tries to i915_gem_object_free(obj) because
"obj" is an error pointer.

Fixes: 97d553963250 ("drm/i915/region: convert object_create into object_init")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/YA6FkPn5S4ZDUGxq@mwanda
(cherry picked from commit ad8db423a30f0ac39a5483dfd726058135ff2bd2)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

authored by

Dan Carpenter and committed by
Rodrigo Vivi
54fd4b9a fbb2bdd2

+4 -8
+4 -8
drivers/gpu/drm/i915/gem/i915_gem_stolen.c
··· 753 753 mutex_lock(&i915->mm.stolen_lock); 754 754 ret = drm_mm_reserve_node(&i915->mm.stolen, stolen); 755 755 mutex_unlock(&i915->mm.stolen_lock); 756 - if (ret) { 757 - obj = ERR_PTR(ret); 756 + if (ret) 758 757 goto err_free; 759 - } 760 758 761 759 obj = i915_gem_object_alloc(); 762 760 if (!obj) { 763 - obj = ERR_PTR(-ENOMEM); 761 + ret = -ENOMEM; 764 762 goto err_stolen; 765 763 } 766 764 767 765 ret = __i915_gem_object_create_stolen(mem, obj, stolen); 768 - if (ret) { 769 - obj = ERR_PTR(ret); 766 + if (ret) 770 767 goto err_object_free; 771 - } 772 768 773 769 i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE); 774 770 return obj; ··· 775 779 i915_gem_stolen_remove_node(i915, stolen); 776 780 err_free: 777 781 kfree(stolen); 778 - return obj; 782 + return ERR_PTR(ret); 779 783 } 780 784 781 785 bool i915_gem_object_is_stolen(const struct drm_i915_gem_object *obj)