From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8ugG-00027u-EC for qemu-devel@nongnu.org; Wed, 07 Jan 2015 12:46:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y8ugD-0006lL-6y for qemu-devel@nongnu.org; Wed, 07 Jan 2015 12:46:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50365) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8ugC-0006lF-Vk for qemu-devel@nongnu.org; Wed, 07 Jan 2015 12:46:01 -0500 Message-ID: <54AD70D2.7030608@redhat.com> Date: Wed, 07 Jan 2015 18:45:54 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1420652194-3224-1-git-send-email-ehabkost@redhat.com> <1420652194-3224-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1420652194-3224-2-git-send-email-ehabkost@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/2] smbios: Fix dimm size calculation when RAM is multiple of 16GB List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost , qemu-devel@nongnu.org Cc: "Gabriel L. Somlo" , Gerd Hoffmann On 07/01/2015 18:36, Eduardo Habkost wrote: > The Memory Device size calculation logic is broken when the RAM size is > a multiple of 16GB, making the size of the last entry be 0 instead of > 16GB. Fix the logic to handle that case correctly. > > Signed-off-by: Eduardo Habkost > --- > hw/i386/smbios.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c > index 024e594..ae7032a 100644 > --- a/hw/i386/smbios.c > +++ b/hw/i386/smbios.c > @@ -850,7 +850,8 @@ void smbios_get_tables(uint8_t **tables, size_t *tables_len, > } > > #define MAX_DIMM_SZ (16ll * ONE_GB) > -#define GET_DIMM_SZ ((i < dimm_cnt - 1) ? MAX_DIMM_SZ : ram_size % MAX_DIMM_SZ) > +#define GET_DIMM_SZ ((i < dimm_cnt - 1) ? MAX_DIMM_SZ \ > + : ((ram_size - 1) % MAX_DIMM_SZ) + 1) > > dimm_cnt = QEMU_ALIGN_UP(ram_size, MAX_DIMM_SZ) / MAX_DIMM_SZ; Using "dimm_size = MAX(ram_size, MAX_DIMM_SZ); ram_size -= dimm_size" would have been less weird, but the whole code here is interesting so your patch is just keeping with the style. We all do that. :) Reviewed-by: Paolo Bonzini