From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756101AbYHSAnV (ORCPT ); Mon, 18 Aug 2008 20:43:21 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754013AbYHSAnN (ORCPT ); Mon, 18 Aug 2008 20:43:13 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:51941 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752314AbYHSAnM (ORCPT ); Mon, 18 Aug 2008 20:43:12 -0400 Date: Mon, 18 Aug 2008 17:42:55 -0700 (PDT) From: Linus Torvalds To: Anthony Liguori cc: linux-kernel@vger.kernel.org, Rusty Russell , Avi Kivity , virtualization@lists.linux-foundation.org, Chris Wright Subject: Re: [PATCH] virtio_balloon: fix towards_target when deflating balloon In-Reply-To: <1219097731-1224-1-git-send-email-aliguori@us.ibm.com> Message-ID: References: <1219097731-1224-1-git-send-email-aliguori@us.ibm.com> User-Agent: Alpine 1.10 (LFD 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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