From patchwork Thu Nov 21 13:34:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 293138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 85BA62C00B9 for ; Fri, 22 Nov 2013 00:32:09 +1100 (EST) Received: from localhost ([::1]:33200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjUMZ-0004lo-0f for incoming@patchwork.ozlabs.org; Thu, 21 Nov 2013 08:32:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjULv-0004Ew-Vv for qemu-devel@nongnu.org; Thu, 21 Nov 2013 08:31:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VjULr-0004Kc-2W for qemu-devel@nongnu.org; Thu, 21 Nov 2013 08:31:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58511) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjULq-0004K5-QY for qemu-devel@nongnu.org; Thu, 21 Nov 2013 08:31:22 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rALDVIGw017085 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 21 Nov 2013 08:31:18 -0500 Received: from redhat.com (vpn1-7-29.ams2.redhat.com [10.36.7.29]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id rALDVFGl001375; Thu, 21 Nov 2013 08:31:16 -0500 Date: Thu, 21 Nov 2013 15:34:26 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20131121133426.GA30827@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: "Michael S. Tsirkin" , Alexander Graf , Dominik Dingel , Christian Borntraeger , Andreas =?iso-8859-1?Q?F=E4rber?= , Richard Henderson Subject: [Qemu-devel] [PATCH v3 for-1.7] s390x: fix flat file load on 32 bit systems X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org pc-bios/s390-zipl.rom is a flat image so it's expected that loading it as elf will fail. It should fall back on loading a flat file, but doesn't on 32 bit systems, instead it fails printing: qemu: hardware error: could not load bootloader 's390-zipl.rom' The result is boot failure. The reason is that a 64 bit unsigned interger which is set to -1 on error is compared to -1UL which on a 32 bit system with gcc is a 32 bit unsigned interger. Since both are unsigned, no sign extension takes place and comparison evaluates to non-equal. There's no reason to do clever tricks: all functions we call actually return int so just use int. And then we can use == -1 everywhere, consistently. Reviewed-by: Alexander Graf Signed-off-by: Michael S. Tsirkin --- changes from v2: drop cleanups that aren't bugfixes, not needed for 1.7 changes from v1: fix more places hw/s390x/ipl.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index d69adb2..65d39da 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -62,10 +62,10 @@ typedef struct S390IPLState { static int s390_ipl_init(SysBusDevice *dev) { S390IPLState *ipl = S390_IPL(dev); - ram_addr_t kernel_size = 0; + int kernel_size; if (!ipl->kernel) { - ram_addr_t bios_size = 0; + int bios_size; char *bios_filename; /* Load zipl bootloader */ @@ -80,7 +80,7 @@ static int s390_ipl_init(SysBusDevice *dev) bios_size = load_elf(bios_filename, NULL, NULL, &ipl->start_addr, NULL, NULL, 1, ELF_MACHINE, 0); - if (bios_size == -1UL) { + if (bios_size == -1) { bios_size = load_image_targphys(bios_filename, ZIPL_IMAGE_START, 4096); ipl->start_addr = ZIPL_IMAGE_START; @@ -90,17 +90,17 @@ static int s390_ipl_init(SysBusDevice *dev) } g_free(bios_filename); - if ((long)bios_size < 0) { + if (bios_size == -1) { hw_error("could not load bootloader '%s'\n", bios_name); } return 0; } else { kernel_size = load_elf(ipl->kernel, NULL, NULL, NULL, NULL, NULL, 1, ELF_MACHINE, 0); - if (kernel_size == -1UL) { + if (kernel_size == -1) { kernel_size = load_image_targphys(ipl->kernel, 0, ram_size); } - if (kernel_size == -1UL) { + if (kernel_size == -1) { fprintf(stderr, "could not load kernel '%s'\n", ipl->kernel); return -1; } @@ -115,7 +115,8 @@ static int s390_ipl_init(SysBusDevice *dev) ipl->start_addr = KERN_IMAGE_START; } if (ipl->initrd) { - ram_addr_t initrd_offset, initrd_size; + ram_addr_t initrd_offset; + int initrd_size; initrd_offset = INITRD_START; while (kernel_size + 0x100000 > initrd_offset) { @@ -123,7 +124,7 @@ static int s390_ipl_init(SysBusDevice *dev) } initrd_size = load_image_targphys(ipl->initrd, initrd_offset, ram_size - initrd_offset); - if (initrd_size == -1UL) { + if (initrd_size == -1) { fprintf(stderr, "qemu: could not load initrd '%s'\n", ipl->initrd); exit(1); }