Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f6712238 authored by Dexuan Cui's avatar Dexuan Cui Committed by Greg Kroah-Hartman
Browse files

hv: hv_balloon: avoid memory leak on alloc_error of 2MB memory block



If num_ballooned is not 0, we shouldn't neglect the
already-partially-allocated 2MB memory block(s).

Signed-off-by: default avatarDexuan Cui <decui@microsoft.com>
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Acked-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4300f264
Loading
Loading
Loading
Loading
+7 −3
Original line number Original line Diff line number Diff line
@@ -1087,10 +1087,12 @@ static void balloon_up(struct work_struct *dummy)
	struct dm_balloon_response *bl_resp;
	struct dm_balloon_response *bl_resp;
	int alloc_unit;
	int alloc_unit;
	int ret;
	int ret;
	bool alloc_error = false;
	bool alloc_error;
	bool done = false;
	bool done = false;
	int i;
	int i;


	/* The host balloons pages in 2M granularity. */
	WARN_ON_ONCE(num_pages % PAGES_IN_2M != 0);


	/*
	/*
	 * We will attempt 2M allocations. However, if we fail to
	 * We will attempt 2M allocations. However, if we fail to
@@ -1107,16 +1109,18 @@ static void balloon_up(struct work_struct *dummy)




		num_pages -= num_ballooned;
		num_pages -= num_ballooned;
		alloc_error = false;
		num_ballooned = alloc_balloon_pages(&dm_device, num_pages,
		num_ballooned = alloc_balloon_pages(&dm_device, num_pages,
						bl_resp, alloc_unit,
						bl_resp, alloc_unit,
						 &alloc_error);
						 &alloc_error);


		if ((alloc_error) && (alloc_unit != 1)) {
		if (alloc_unit != 1 && num_ballooned == 0) {
			alloc_unit = 1;
			alloc_unit = 1;
			continue;
			continue;
		}
		}


		if ((alloc_error) || (num_ballooned == num_pages)) {
		if ((alloc_unit == 1 && alloc_error) ||
			(num_ballooned == num_pages)) {
			bl_resp->more_pages = 0;
			bl_resp->more_pages = 0;
			done = true;
			done = true;
			dm_device.state = DM_INITIALIZED;
			dm_device.state = DM_INITIALIZED;