Re: [PATCH] virtio_balloon: fix towards_target when deflating balloon

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Mon, 18 Aug 2008, Anthony Liguori wrote: <
> 
> This handles the case where v < vb->num_pages and ensures we get a 
> small, negative, s64 as the result.

That's just horrible code.

Maybe the compiler notices that you're doing something stupid, but 
basically, please don't do this.

> -	return v - vb->num_pages;
> +	if (v < vb->num_pages)
> +		return -(s64)(vb->num_pages - v);
> +	else
> +		return v - vb->num_pages;

What's wrong with just doing

	return (s64)v - vb->num_pages;

instead?

Casting 'v' to s64 guarantees that the subtraction will eb done in 64 
bits, and the compiler can just generate the trivial non-conditional code.

		Linus
_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linux-foundation.org/mailman/listinfo/virtualization

[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux