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

Zhenyu Wang zhenyuw at linux.intel.com
Thu Feb 22 07:16:15 UTC 2018


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 at linux.intel.com>
---
 drivers/gpu/drm/i915/gvt/kvmgt.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

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;
-- 
2.16.1



More information about the intel-gvt-dev mailing list