s390x: fix flat file load on 32 bit systems

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 <agraf@suse.de>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-id: 20131121133426.GA30827@redhat.com
Signed-off-by: Anthony Liguori <aliguori@amazon.com>
This commit is contained in:
Michael S. Tsirkin 2013-11-21 15:34:26 +02:00 committed by Anthony Liguori
parent b15654c21a
commit 376827d489
1 changed files with 9 additions and 8 deletions

View File

@ -62,10 +62,10 @@ typedef struct S390IPLState {
static int s390_ipl_init(SysBusDevice *dev) static int s390_ipl_init(SysBusDevice *dev)
{ {
S390IPLState *ipl = S390_IPL(dev); S390IPLState *ipl = S390_IPL(dev);
ram_addr_t kernel_size = 0; int kernel_size;
if (!ipl->kernel) { if (!ipl->kernel) {
ram_addr_t bios_size = 0; int bios_size;
char *bios_filename; char *bios_filename;
/* Load zipl bootloader */ /* 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, bios_size = load_elf(bios_filename, NULL, NULL, &ipl->start_addr, NULL,
NULL, 1, ELF_MACHINE, 0); NULL, 1, ELF_MACHINE, 0);
if (bios_size == -1UL) { if (bios_size == -1) {
bios_size = load_image_targphys(bios_filename, ZIPL_IMAGE_START, bios_size = load_image_targphys(bios_filename, ZIPL_IMAGE_START,
4096); 4096);
ipl->start_addr = ZIPL_IMAGE_START; ipl->start_addr = ZIPL_IMAGE_START;
@ -90,17 +90,17 @@ static int s390_ipl_init(SysBusDevice *dev)
} }
g_free(bios_filename); g_free(bios_filename);
if ((long)bios_size < 0) { if (bios_size == -1) {
hw_error("could not load bootloader '%s'\n", bios_name); hw_error("could not load bootloader '%s'\n", bios_name);
} }
return 0; return 0;
} else { } else {
kernel_size = load_elf(ipl->kernel, NULL, NULL, NULL, NULL, kernel_size = load_elf(ipl->kernel, NULL, NULL, NULL, NULL,
NULL, 1, ELF_MACHINE, 0); NULL, 1, ELF_MACHINE, 0);
if (kernel_size == -1UL) { if (kernel_size == -1) {
kernel_size = load_image_targphys(ipl->kernel, 0, ram_size); 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); fprintf(stderr, "could not load kernel '%s'\n", ipl->kernel);
return -1; return -1;
} }
@ -115,7 +115,8 @@ static int s390_ipl_init(SysBusDevice *dev)
ipl->start_addr = KERN_IMAGE_START; ipl->start_addr = KERN_IMAGE_START;
} }
if (ipl->initrd) { if (ipl->initrd) {
ram_addr_t initrd_offset, initrd_size; ram_addr_t initrd_offset;
int initrd_size;
initrd_offset = INITRD_START; initrd_offset = INITRD_START;
while (kernel_size + 0x100000 > initrd_offset) { 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, initrd_size = load_image_targphys(ipl->initrd, initrd_offset,
ram_size - 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); fprintf(stderr, "qemu: could not load initrd '%s'\n", ipl->initrd);
exit(1); exit(1);
} }