Message ID | 20190215193554.24579-1-radhakrishna.sripada@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | drm/i915/selftests: Fix resource leak in __sseu_prepare | expand |
Quoting Radhakrishna Sripada (2019-02-15 19:35:54)
> Fix the resource leak reported by static code checker.
The caller already frees spin on error, so you just need to set the
output and report the error.
-Chris
Quoting Chris Wilson (2019-02-15 19:40:06) > Quoting Radhakrishna Sripada (2019-02-15 19:35:54) > > Fix the resource leak reported by static code checker. > > The caller already frees spin on error, so you just need to set the > output and report the error. Nah, doesn't look at tidy as a proper onion unwind. -Chris
Hi Radhakrishna, Thank you for the patch! Yet something to improve: [auto build test ERROR on drm-intel/for-linux-next] [also build test ERROR on next-20190215] [cannot apply to v5.0-rc4] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Radhakrishna-Sripada/drm-i915-selftests-Fix-resource-leak-in-__sseu_prepare/20190216-081923 base: git://anongit.freedesktop.org/drm-intel for-linux-next config: i386-randconfig-s1-201906 (attached as .config) compiler: gcc-6 (Debian 6.5.0-2) 6.5.0 20181026 reproduce: # save the attached .config to linux build tree make ARCH=i386 All errors (new ones prefixed by >>): In file included from drivers/gpu/drm/i915/i915_gem_context.c:1386:0: drivers/gpu/drm/i915/selftests/i915_gem_context.c: In function '__sseu_prepare': >> drivers/gpu/drm/i915/selftests/i915_gem_context.c:753:8: error: 'spin' undeclared (first use in this function) kfree(spin); ^~~~ drivers/gpu/drm/i915/selftests/i915_gem_context.c:753:8: note: each undeclared identifier is reported only once for each function it appears in vim +/spin +753 drivers/gpu/drm/i915/selftests/i915_gem_context.c 706 707 static int 708 __sseu_prepare(struct drm_i915_private *i915, 709 const char *name, 710 unsigned int flags, 711 struct i915_gem_context *ctx, 712 struct intel_engine_cs *engine, 713 struct igt_spinner **spin_out) 714 { 715 int ret = 0; 716 717 if (flags & (TEST_BUSY | TEST_RESET)) { 718 struct igt_spinner *spin; 719 struct i915_request *rq; 720 721 spin = kzalloc(sizeof(*spin), GFP_KERNEL); 722 if (!spin) { 723 ret = -ENOMEM; 724 goto out; 725 } 726 727 ret = igt_spinner_init(spin, i915); 728 if (ret) 729 goto clean; 730 731 rq = igt_spinner_create_request(spin, ctx, engine, MI_NOOP); 732 if (IS_ERR(rq)) { 733 ret = PTR_ERR(rq); 734 igt_spinner_fini(spin); 735 goto clean; 736 } 737 738 i915_request_add(rq); 739 740 if (!igt_wait_for_spinner(spin, rq)) { 741 pr_err("%s: Spinner failed to start!\n", name); 742 igt_spinner_end(spin); 743 igt_spinner_fini(spin); 744 ret = -ETIMEDOUT; 745 goto clean; 746 } 747 748 *spin_out = spin; 749 goto out; 750 } 751 752 clean: > 753 kfree(spin); 754 out: 755 return ret; 756 } 757 --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
Hi Radhakrishna, Thank you for the patch! Yet something to improve: [auto build test ERROR on drm-intel/for-linux-next] [also build test ERROR on next-20190215] [cannot apply to v5.0-rc4] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Radhakrishna-Sripada/drm-i915-selftests-Fix-resource-leak-in-__sseu_prepare/20190216-081923 base: git://anongit.freedesktop.org/drm-intel for-linux-next config: x86_64-randconfig-k1-02151608 (attached as .config) compiler: gcc-8 (Debian 8.2.0-20) 8.2.0 reproduce: # save the attached .config to linux build tree make ARCH=x86_64 All errors (new ones prefixed by >>): In file included from drivers/gpu/drm/i915/i915_gem_context.c:1386: drivers/gpu/drm/i915/selftests/i915_gem_context.c: In function '__sseu_prepare': >> drivers/gpu/drm/i915/selftests/i915_gem_context.c:753:8: error: 'spin' undeclared (first use in this function); did you mean 'fs_pin'? kfree(spin); ^~~~ fs_pin drivers/gpu/drm/i915/selftests/i915_gem_context.c:753:8: note: each undeclared identifier is reported only once for each function it appears in vim +753 drivers/gpu/drm/i915/selftests/i915_gem_context.c 706 707 static int 708 __sseu_prepare(struct drm_i915_private *i915, 709 const char *name, 710 unsigned int flags, 711 struct i915_gem_context *ctx, 712 struct intel_engine_cs *engine, 713 struct igt_spinner **spin_out) 714 { 715 int ret = 0; 716 717 if (flags & (TEST_BUSY | TEST_RESET)) { 718 struct igt_spinner *spin; 719 struct i915_request *rq; 720 721 spin = kzalloc(sizeof(*spin), GFP_KERNEL); 722 if (!spin) { 723 ret = -ENOMEM; 724 goto out; 725 } 726 727 ret = igt_spinner_init(spin, i915); 728 if (ret) 729 goto clean; 730 731 rq = igt_spinner_create_request(spin, ctx, engine, MI_NOOP); 732 if (IS_ERR(rq)) { 733 ret = PTR_ERR(rq); 734 igt_spinner_fini(spin); 735 goto clean; 736 } 737 738 i915_request_add(rq); 739 740 if (!igt_wait_for_spinner(spin, rq)) { 741 pr_err("%s: Spinner failed to start!\n", name); 742 igt_spinner_end(spin); 743 igt_spinner_fini(spin); 744 ret = -ETIMEDOUT; 745 goto clean; 746 } 747 748 *spin_out = spin; 749 goto out; 750 } 751 752 clean: > 753 kfree(spin); 754 out: 755 return ret; 756 } 757 --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_context.c b/drivers/gpu/drm/i915/selftests/i915_gem_context.c index d00d0bb07784..0d821a679f74 100644 --- a/drivers/gpu/drm/i915/selftests/i915_gem_context.c +++ b/drivers/gpu/drm/i915/selftests/i915_gem_context.c @@ -726,14 +726,13 @@ __sseu_prepare(struct drm_i915_private *i915, ret = igt_spinner_init(spin, i915); if (ret) - return ret; + goto clean; rq = igt_spinner_create_request(spin, ctx, engine, MI_NOOP); if (IS_ERR(rq)) { ret = PTR_ERR(rq); igt_spinner_fini(spin); - kfree(spin); - goto out; + goto clean; } i915_request_add(rq); @@ -742,14 +741,16 @@ __sseu_prepare(struct drm_i915_private *i915, pr_err("%s: Spinner failed to start!\n", name); igt_spinner_end(spin); igt_spinner_fini(spin); - kfree(spin); ret = -ETIMEDOUT; - goto out; + goto clean; } *spin_out = spin; + goto out; } +clean: + kfree(spin); out: return ret; }
Fix the resource leak reported by static code checker. Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Signed-off-by: Radhakrishna Sripada <radhakrishna.sripada@intel.com> --- drivers/gpu/drm/i915/selftests/i915_gem_context.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)