aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hv
diff options
context:
space:
mode:
authorDexuan Cui <decui@microsoft.com>2014-11-24 23:32:43 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-11-26 22:03:04 -0500
commitf6712238471a8afdbfcea482483fc121281292d8 (patch)
treed52d8af9b315837e838a582dc3ab540023c9decb /drivers/hv
parent4300f26492b2438c4c1930552dfe83cb09c0ab31 (diff)
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: Dexuan Cui <decui@microsoft.com> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Acked-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/hv')
-rw-r--r--drivers/hv/hv_balloon.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index 5e90c5d771a7..b958ded8ac7e 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -1087,10 +1087,12 @@ static void balloon_up(struct work_struct *dummy)
1087 struct dm_balloon_response *bl_resp; 1087 struct dm_balloon_response *bl_resp;
1088 int alloc_unit; 1088 int alloc_unit;
1089 int ret; 1089 int ret;
1090 bool alloc_error = false; 1090 bool alloc_error;
1091 bool done = false; 1091 bool done = false;
1092 int i; 1092 int i;
1093 1093
1094 /* The host balloons pages in 2M granularity. */
1095 WARN_ON_ONCE(num_pages % PAGES_IN_2M != 0);
1094 1096
1095 /* 1097 /*
1096 * We will attempt 2M allocations. However, if we fail to 1098 * We will attempt 2M allocations. However, if we fail to
@@ -1107,16 +1109,18 @@ static void balloon_up(struct work_struct *dummy)
1107 1109
1108 1110
1109 num_pages -= num_ballooned; 1111 num_pages -= num_ballooned;
1112 alloc_error = false;
1110 num_ballooned = alloc_balloon_pages(&dm_device, num_pages, 1113 num_ballooned = alloc_balloon_pages(&dm_device, num_pages,
1111 bl_resp, alloc_unit, 1114 bl_resp, alloc_unit,
1112 &alloc_error); 1115 &alloc_error);
1113 1116
1114 if ((alloc_error) && (alloc_unit != 1)) { 1117 if (alloc_unit != 1 && num_ballooned == 0) {
1115 alloc_unit = 1; 1118 alloc_unit = 1;
1116 continue; 1119 continue;
1117 } 1120 }
1118 1121
1119 if ((alloc_error) || (num_ballooned == num_pages)) { 1122 if ((alloc_unit == 1 && alloc_error) ||
1123 (num_ballooned == num_pages)) {
1120 bl_resp->more_pages = 0; 1124 bl_resp->more_pages = 0;
1121 done = true; 1125 done = true;
1122 dm_device.state = DM_INITIALIZED; 1126 dm_device.state = DM_INITIALIZED;