Stefan Reinauer has submitted this change. ( https://review.coreboot.org/c/em100/+/37135 )
Change subject: Enable and fix compiler warnings ......................................................................
Enable and fix compiler warnings
Remove -Wno-sign-compare -Wno-discarded-qualifiers and fix all warnings in the code.
Signed-off-by: Stefan Reinauer stefan.reinauer@coreboot.org Change-Id: Idf8e6364a8ebba78b7c793f745048bffbc03e3ef Reviewed-on: https://review.coreboot.org/c/em100/+/37135 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Angel Pons th3fanbus@gmail.com --- M Makefile M chips.c M em100.c M em100.h M firmware.c M hexdump.c M spi.c M tar.c M trace.c 9 files changed, 37 insertions(+), 39 deletions(-)
Approvals: build bot (Jenkins): Verified Angel Pons: Looks good to me, approved
diff --git a/Makefile b/Makefile index 70736a0..6fd9d90 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,6 @@ CFLAGS += -Wwrite-strings -Wredundant-decls -Wstrict-aliasing -Wshadow -Wextra CFLAGS += -Wno-unused-but-set-variable CFLAGS += -DXZ_USE_CRC64 -DXZ_DEC_ANY_CHECK -Ixz -# Remove after fixing -CFLAGS += -Wno-sign-compare -Wno-discarded-qualifiers
LDFLAGS ?= LDFLAGS += $(shell $(PKG_CONFIG) --libs libusb-1.0) diff --git a/chips.c b/chips.c index acd90e1..7a776cc 100644 --- a/chips.c +++ b/chips.c @@ -189,7 +189,7 @@ return entries; }
-static int parse_and_output_sfdp(chipdesc *chip, void **ptr, int *length, int entries) +static int parse_and_output_sfdp(chipdesc *chip, void **ptr, size_t *length, int entries) { int i, len = 0; unsigned char *sfdp_buffer = (unsigned char *)*ptr; @@ -220,7 +220,7 @@ return len; }
-static int parse_and_output_srst(chipdesc *chip, void **ptr, int *length, int entries) +static int parse_and_output_srst(chipdesc *chip, void **ptr, size_t *length, int entries) { int i, len = 0; uint32_t magic; @@ -279,7 +279,7 @@ uint32_t magic;
void *ptr = (void *)dcfg->address; - int length = dcfg->length; + size_t length = dcfg->length;
if (length < sizeof(cfg_buffer)) { /* Not a config file */ diff --git a/em100.c b/em100.c index 530e9d2..f4f1152 100644 --- a/em100.c +++ b/em100.c @@ -72,7 +72,7 @@ printf("EM100Pro state unknown\n"); }
-static char * get_pin_string(int pin) { +static const char *get_pin_string(int pin) { switch (pin) { case 0: return ("low"); @@ -352,7 +352,7 @@ }
static int em100_attach(struct em100 *em100, int bus, int device, - int serial_number) + uint32_t serial_number) { libusb_device_handle *dev = NULL; libusb_context *ctx = NULL; @@ -731,7 +731,7 @@ return directory; }
-char *get_em100_file(char *name) +char *get_em100_file(const char *name) { char file[FILENAME_BUFFER_SIZE]; strncpy(file, get_em100_home(), FILENAME_BUFFER_SIZE); @@ -805,7 +805,7 @@ int firmware_is_dpfw = 0; unsigned int serial_number = 0; unsigned long address_offset = 0; - unsigned long spi_start_address = 0; + unsigned int spi_start_address = 0; const char *voltage = NULL;
while ((opt = getopt_long(argc, argv, "c:d:a:u:rsvtO:F:f:g:S:V:p:Dx:lhT", @@ -819,8 +819,8 @@ /* TODO: check that file exists */ break; case 'a': - sscanf(optarg, "%lx", &spi_start_address); - printf("Spi address: 0x%08lx\n", spi_start_address); + sscanf(optarg, "%x", &spi_start_address); + printf("SPI address: 0x%08x\n", spi_start_address); break; case 'u': read_filename = optarg; @@ -1026,7 +1026,7 @@ }
if (filename) { - int maxlen = desiredchip ? chip->size : 0x4000000; /* largest size - 64MB */ + unsigned int maxlen = desiredchip ? chip->size : 0x4000000; /* largest size - 64MB */ void *data = malloc(maxlen); int done; void *readback = NULL; @@ -1042,7 +1042,7 @@ return 1; }
- int length = 0; + unsigned int length = 0; while ((!feof(fdata)) && (length < maxlen)) { int blocksize = 65536; length += blocksize * fread(data+length, blocksize, 1, diff --git a/em100.h b/em100.h index f126b7d..e436fbb 100644 --- a/em100.h +++ b/em100.h @@ -82,15 +82,15 @@ uint32_t get_spi_flash_id(struct em100 *em100); int erase_spi_flash(struct em100 *em100); int poll_spi_flash_status(struct em100 *em100); -int read_spi_flash_page(struct em100 *em100, int addr, unsigned char *blk); +int read_spi_flash_page(struct em100 *em100, int address, unsigned char *blk); int write_spi_flash_page(struct em100 *em100, int address, unsigned char *data); int unlock_spi_flash(struct em100 *em100); int erase_spi_flash_sector(struct em100 *em100, unsigned int sector); int read_ht_register(struct em100 *em100, int reg, uint8_t *val); int write_ht_register(struct em100 *em100, int reg, uint8_t val); -int write_dfifo(struct em100 *em100, unsigned int length, unsigned int timeout, +int write_dfifo(struct em100 *em100, size_t length, unsigned int timeout, unsigned char *blk); -int read_ufifo(struct em100 *em100, unsigned int length, unsigned int timeout, +int read_ufifo(struct em100 *em100, size_t length, unsigned int timeout, unsigned char *blk);
/* system.c */ @@ -181,7 +181,7 @@ size_t length; int alloc; } TFILE; -TFILE *tar_find(TFILE *tfile, char *name, int casesensitive); +TFILE *tar_find(TFILE *tfile, const char *name, int casesensitive); TFILE *tar_load_compressed(char *filename); int tar_for_each(TFILE *tfile, int (*run)(char *, TFILE *, void *, int), void *data); int tar_close(TFILE *tfile); @@ -192,7 +192,7 @@
#define MB * 1024 * 1024 #define FILENAME_BUFFER_SIZE 1024 -char *get_em100_file(char *name); +char *get_em100_file(const char *name);
/* Chips */ int parse_dcfg(chipdesc *chip, TFILE *dcfg); diff --git a/firmware.c b/firmware.c index b468dc1..8712d62 100644 --- a/firmware.c +++ b/firmware.c @@ -90,8 +90,8 @@ int firmware_is_dpfw) { unsigned char *data; - int i; - uint32_t id, rom_size = 0; + size_t i, rom_size = 0; + uint32_t id; FILE *fw;
id = get_spi_flash_id(em100); @@ -117,7 +117,7 @@ if (!read_spi_flash_page(em100, i, data+i)) { if (!read_spi_flash_page(em100, i, data+i)) if (!read_spi_flash_page(em100, i, data+i)) - printf("\nERROR: Couldn't read @%08x\n", + printf("\nERROR: Couldn't read @%08zx\n", i); } } diff --git a/hexdump.c b/hexdump.c index c0dd3dc..501a6bb 100644 --- a/hexdump.c +++ b/hexdump.c @@ -24,7 +24,7 @@
void hexdump(const void *memory, size_t length) { - int i; + size_t i; uint8_t *m; int all_zero = 0; int all_one = 0; @@ -32,7 +32,7 @@ m = (uint8_t *) memory;
for (i = 0; i < length; i += 16) { - int j; + size_t j;
all_zero++; all_one++; @@ -49,7 +49,7 @@ } } if (all_zero < 2 && all_one < 2) { - printf( "%08x:", i); + printf( "%08zx:", i); for (j = 0; j < 16; j++) printf( " %02x", m[i + j]); printf(" "); diff --git a/spi.c b/spi.c index cc1d706..1be25b7 100644 --- a/spi.c +++ b/spi.c @@ -76,18 +76,18 @@ * read_spi_flash_page: fetch SPI flash page * @param em100: initialized em100 device structure * - * out(16 bytes): 0x33 addr addr addr .. 0 + * out(16 bytes): 0x33 address address address .. 0 * in(len + 255 bytes): 0xff ?? serno_lo serno_hi ?? ?? .. ?? */ -int read_spi_flash_page(struct em100 *em100, int addr, unsigned char *blk) +int read_spi_flash_page(struct em100 *em100, int address, unsigned char *blk) { unsigned char cmd[16]; unsigned char data[256]; memset(cmd, 0, 16); cmd[0] = 0x33; /* read SPI flash page */ - cmd[1] = (addr >> 16) & 0xff; - cmd[2] = (addr >> 8) & 0xff; - cmd[3] = addr & 0xff; + cmd[1] = (address >> 16) & 0xff; + cmd[2] = (address >> 8) & 0xff; + cmd[3] = address & 0xff; if (!send_cmd(em100->dev, cmd)) { return 0; } @@ -104,7 +104,7 @@ { int length = 256; int actual; - int bytes_sent=0; + int bytes_sent = 0; int bytes_left; unsigned char cmd[16]; memset(cmd, 0, 16); @@ -244,11 +244,11 @@ return 1; }
-int write_dfifo(struct em100 *em100, unsigned int length, unsigned int timeout, +int write_dfifo(struct em100 *em100, size_t length, unsigned int timeout, unsigned char *blk) { int actual; - int bytes_sent=0; + size_t bytes_sent = 0; int bytes_left; unsigned char cmd[16]; unsigned char data[512]; @@ -287,12 +287,12 @@ break; }
- printf("Sent %d bytes of %d\n", bytes_sent, length); + printf("Sent %zd bytes of %zd\n", bytes_sent, length); }
printf ("Transfer %s\n",bytes_sent == length ? "Succeeded" : "Failed"); if (bytes_sent == length) - printf("Warning: Sent %d bytes, expected %d\n", + printf("Warning: Sent %zd bytes, expected %zd\n", bytes_sent, length);
int len = get_response(em100->dev, data, 512); @@ -303,7 +303,7 @@ return 0; }
-int read_ufifo(struct em100 *em100, unsigned int length, unsigned int timeout, +int read_ufifo(struct em100 *em100, size_t length, unsigned int timeout, unsigned char *blk) { unsigned char cmd[16]; @@ -324,7 +324,7 @@ if (!send_cmd(em100->dev, cmd)) { return 0; } - int len = get_response(em100->dev, data, 512); + size_t len = get_response(em100->dev, data, 512);
/* get second response from read ufifo command */ get_response(em100->dev, data2, 2); diff --git a/tar.c b/tar.c index e8d3664..219efd4 100644 --- a/tar.c +++ b/tar.c @@ -48,7 +48,7 @@
static unsigned int checksum(tar_header_t *file) { - int i, chk_off = offsetof(tar_header_t, checksum); + size_t i, chk_off = offsetof(tar_header_t, checksum); unsigned char *raw = (unsigned char *)file; unsigned int chksum = 256;
@@ -104,7 +104,7 @@ return 0; }
-TFILE *tar_find(TFILE *tfile, char *name, int casesensitive) +TFILE *tar_find(TFILE *tfile, const char *name, int casesensitive) { size_t i = 0; TFILE *ret; diff --git a/trace.c b/trace.c index 50c2fc6..d7616b3 100644 --- a/trace.c +++ b/trace.c @@ -107,7 +107,7 @@ }
struct spi_cmd_values { - char *cmd_name; + const char *cmd_name; uint8_t cmd; uint8_t uses_address; uint8_t pad_bytes;