dell-flash-unlock: fix errno handling

and remove pedantic flags in makefile

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-04-22 03:38:30 +01:00
parent a64cdaa300
commit 9b01115c5a
2 changed files with 12 additions and 8 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2023 Nicholas Chin # SPDX-FileCopyrightText: 2023 Nicholas Chin
CC=cc CC=cc
CFLAGS=-Wall -Wextra -Werror -O2 -pedantic CFLAGS=-Wall -Wextra -O2
SRCS=dell_flash_unlock.c accessors.c SRCS=dell_flash_unlock.c accessors.c
all: $(SRCS) accessors.h all: $(SRCS) accessors.h
+11 -7
View File
@@ -47,9 +47,9 @@ main(int argc, char *argv[])
(void)argv; (void)argv;
if (sys_iopl(3) == -1) if (sys_iopl(3) == -1)
err(errno, "Could not access IO ports"); err(EXIT_FAILURE, "Could not access IO ports");
if ((devmemfd = open("/dev/mem", O_RDONLY)) == -1) if ((devmemfd = open("/dev/mem", O_RDONLY)) == -1)
err(errno, "/dev/mem"); err(EXIT_FAILURE, "/dev/mem");
/* Read RCBA and PMBASE from the LPC config registers */ /* Read RCBA and PMBASE from the LPC config registers */
long int rcba = pci_read_32(LPC_DEV, 0xf0) & 0xffffc000; long int rcba = pci_read_32(LPC_DEV, 0xf0) & 0xffffc000;
@@ -59,11 +59,11 @@ main(int argc, char *argv[])
rcba_mmio = mmap(0, RCBA_MMIO_LEN, PROT_READ, MAP_SHARED, devmemfd, rcba_mmio = mmap(0, RCBA_MMIO_LEN, PROT_READ, MAP_SHARED, devmemfd,
rcba); rcba);
if (rcba_mmio == MAP_FAILED) if (rcba_mmio == MAP_FAILED)
err(errno, "Could not map RCBA"); err(EXIT_FAILURE, "Could not map RCBA");
if (get_fdo_status() == 1) { /* Descriptor not overridden */ if (get_fdo_status() == 1) { /* Descriptor not overridden */
if (check_lpc_decode() == -1) if (check_lpc_decode() == -1)
err(errno = ECANCELED, "Can't forward I/O to LPC"); err(EXIT_FAILURE, "Can't forward I/O to LPC");
printf("Sending FDO override command to EC:\n"); printf("Sending FDO override command to EC:\n");
ec_set_fdo(); ec_set_fdo();
@@ -80,7 +80,8 @@ main(int argc, char *argv[])
"to enable SMIs.\n (shutdown is buggy when " "to enable SMIs.\n (shutdown is buggy when "
"SMIs are disabled)\n"); "SMIs are disabled)\n");
} else { } else {
err(errno = ECANCELED, "Could not disable SMIs!"); errno = EIO;
err(EXIT_FAILURE, "Could not disable SMIs!");
} }
} else { /* SMI locks not in place or bypassed */ } else { /* SMI locks not in place or bypassed */
if (get_gbl_smi_en()) { if (get_gbl_smi_en()) {
@@ -97,7 +98,7 @@ main(int argc, char *argv[])
} }
} }
sys_iopl(0); sys_iopl(0);
return errno; return EXIT_SUCCESS;
} }
int int
@@ -137,6 +138,7 @@ check_lpc_decode(void)
pci_write_32(LPC_DEV, 0x84 + 4 * gen_dec_free, 0x911); pci_write_32(LPC_DEV, 0x84 + 4 * gen_dec_free, 0x911);
return 0; return 0;
} else { } else {
errno = EIO;
return -1; return -1;
} }
} }
@@ -165,7 +167,7 @@ send_ec_cmd(uint8_t cmd)
sys_outb(EC_INDEX, 0); sys_outb(EC_INDEX, 0);
sys_outb(EC_DATA, cmd); sys_outb(EC_DATA, cmd);
if (wait_ec() == -1) if (wait_ec() == -1)
err(errno = ECANCELED, "Timeout while waiting for EC!"); err(EXIT_FAILURE, "Timeout while waiting for EC!");
} }
int int
@@ -179,6 +181,8 @@ wait_ec(void)
timeout--; timeout--;
usleep(1000); usleep(1000);
} while (busy && timeout > 0); } while (busy && timeout > 0);
if (timeout <= 0)
errno = EIO;
return timeout > 0 ? 0 : -1; return timeout > 0 ? 0 : -1;
} }