Skip to content

Commit 0395be3

Browse files
anadavgregkh
authored andcommitted
vmw_balloon: simplify vmballoon_send_get_target()
As we want to leave as little as possible on the global balloon structure, to avoid possible future races, we want to get rid sysinfo. We can actually get the total_ram directly, and simplify the logic of vmballoon_send_get_target() a little. While we are doing that, let's return int and avoid mistakes due to bool/int conversions. Reviewed-by: Xavier Deguillard <[email protected]> Signed-off-by: Nadav Amit <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8b079cd commit 0395be3

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

drivers/misc/vmw_balloon.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ struct vmballoon {
223223
struct dentry *dbg_entry;
224224
#endif
225225

226-
struct sysinfo sysinfo;
227-
228226
struct delayed_work dwork;
229227

230228
struct vmci_handle vmci_doorbell;
@@ -353,34 +351,29 @@ static u16 vmballoon_page_size(bool is_2m_page)
353351
return 1;
354352
}
355353

356-
/*
357-
* Retrieve desired balloon size from the host.
354+
/**
355+
* vmballoon_send_get_target() - Retrieve desired balloon size from the host.
356+
*
357+
* @b: pointer to the balloon.
358+
*
359+
* Return: zero on success, EINVAL if limit does not fit in 32-bit, as required
360+
* by the host-guest protocol and EIO if an error occurred in communicating with
361+
* the host.
358362
*/
359-
static bool vmballoon_send_get_target(struct vmballoon *b)
363+
static int vmballoon_send_get_target(struct vmballoon *b)
360364
{
361365
unsigned long status;
362366
unsigned long limit;
363-
u32 limit32;
364367

365-
/*
366-
* si_meminfo() is cheap. Moreover, we want to provide dynamic
367-
* max balloon size later. So let us call si_meminfo() every
368-
* iteration.
369-
*/
370-
si_meminfo(&b->sysinfo);
371-
limit = b->sysinfo.totalram;
368+
limit = totalram_pages;
372369

373370
/* Ensure limit fits in 32-bits */
374-
limit32 = (u32)limit;
375-
if (limit != limit32)
376-
return false;
371+
if (limit != (u32)limit)
372+
return -EINVAL;
377373

378374
status = vmballoon_cmd(b, VMW_BALLOON_CMD_GET_TARGET, limit, 0);
379375

380-
if (status == VMW_BALLOON_SUCCESS)
381-
return true;
382-
383-
return false;
376+
return status == VMW_BALLOON_SUCCESS ? 0 : -EIO;
384377
}
385378

386379
static struct page *vmballoon_alloc_page(bool is_2m_page)
@@ -962,7 +955,7 @@ static void vmballoon_work(struct work_struct *work)
962955
if (b->reset_required)
963956
vmballoon_reset(b);
964957

965-
if (vmballoon_send_get_target(b))
958+
if (!vmballoon_send_get_target(b))
966959
change = vmballoon_change(b);
967960

968961
if (change != 0) {

0 commit comments

Comments
 (0)