Re: [PATCH 2/3] kvm tools: check negative value of num_pages

Pekka Enberg
2011-08-11T13:36:37Z

On Thu, 11 Aug 2011, Liming Wang wrote:
> If num_pages is negative, balloon will make kernel crash with
> "out of memory". So we check this value to avoid it to be negative.
>
> Signed-off-by: Liming Wang <walimisdev@gmail.com>
> ---
> tools/kvm/virtio/balloon.c | 8 ++++++--
> 1 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c
> index 854d04b..941023e 100644
> --- a/tools/kvm/virtio/balloon.c
> +++ b/tools/kvm/virtio/balloon.c
> @@ -220,10 +220,14 @@ static struct ioport_operations virtio_bln_io_ops = {
>
> static void handle_sigmem(int sig)
> {
> - if (sig == SIGKVMADDMEM)
> + if (sig == SIGKVMADDMEM) {
> bdev.config.num_pages += 256;
> - else
> + } else {
> + if (bdev.config.num_pages < 256){

Space missing before opening brace.

> + return;
> + }

Please don't use braces for single line if statements.

I'll fix it up myself. You can use the scripts/checkpatch script to check
for this kind of trivial coding style issues before sending a patch out.

> bdev.config.num_pages -= 256;
> + }
>
> /* Notify that the configuration space has changed */
> bdev.isr = VIRTIO_PCI_ISR_CONFIG;
> --
> 1.7.0.4
>
>