[5/8] drm/i915/gvt: Fix check error on possible memory leak

Submitted by Wang, Zhi A on Feb. 28, 2018, 11:51 a.m.

Details

Message ID F3B0350DF4CB6849A642218320DE483D7D6DC1B8@SHSMSX104.ccr.corp.intel.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Intel GVT devel

Not browsing as part of any series.

Commit Message

Wang, Zhi A Feb. 28, 2018, 11:51 a.m.
Reviewed-by: Zhi Wang <zhi.a.wang@intel.com>


-----Original Message-----
From: intel-gvt-dev [mailto:intel-gvt-dev-bounces@lists.freedesktop.org] On Behalf Of Zhenyu Wang

Sent: Thursday, February 22, 2018 3:16 PM
To: intel-gvt-dev@lists.freedesktop.org
Subject: [PATCH 5/8] drm/i915/gvt: Fix check error on possible memory leak

Fix below check error by always remember to free.

  CHECK   drivers/gpu/drm/i915//gvt/kvmgt.c
drivers/gpu/drm/i915//gvt/kvmgt.c:1166 intel_vgpu_ioctl() warn: possible memory leak of 'sparse'
drivers/gpu/drm/i915//gvt/kvmgt.c:1181 intel_vgpu_ioctl() warn: possible memory leak of 'sparse'
drivers/gpu/drm/i915//gvt/kvmgt.c:1189 intel_vgpu_ioctl() warn: possible memory leak of 'sparse'

Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>

---
 drivers/gpu/drm/i915/gvt/kvmgt.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

-- 
2.16.1

_______________________________________________
intel-gvt-dev mailing list
intel-gvt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index 21c711b10515..c9e9452c534e 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -1047,7 +1047,7 @@  static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
 	} else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
 		struct vfio_region_info info;
 		struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
-		int i, ret;
+		int i, ret = 0;
 		struct vfio_region_info_cap_sparse_mmap *sparse = NULL;
 		size_t size;
 		int nr_areas = 1;
@@ -1158,14 +1158,14 @@  static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
 					&sparse->header, sizeof(*sparse) +
 					(sparse->nr_areas *
 						sizeof(*sparse->areas)));
-				kfree(sparse);
-				if (ret)
-					return ret;
 				break;
 			default:
-				return -EINVAL;
+				ret = -EINVAL;
 			}
 		}
+		kfree(sparse);
+		if (ret)
+			return ret;
 
 		if (caps.size) {
 			info.flags |= VFIO_REGION_INFO_FLAG_CAPS;