Nico Huber has uploaded this change for review.

View Change

Fix -Wsign-compare trouble

Mostly by changing to `unsigned` types where applicable, sometimes
`signed` types, and casting as a last resort.

Change-Id: I08895543ffb7a48058bcf91ef6500ca113f2d305
Signed-off-by: Nico Huber <nico.h@gmx.de>
---
M 82802ab.c
M at45db.c
M bitbang_spi.c
M board_enable.c
M buspirate_spi.c
M cbtable.c
M cli_classic.c
M dediprog.c
M dmi.c
M dummyflasher.c
M en29lv640b.c
M flash.h
M flashrom.c
M fmap.c
M helpers.c
M ich_descriptors.c
M ichspi.c
M it85spi.c
M it87spi.c
M jedec.c
M layout.c
M pickit2_spi.c
M print.c
M programmer.h
M sb600spi.c
M serial.c
M serprog.c
M sst28sf040.c
M sst_fwhub.c
M usbblaster_spi.c
M wbsio_spi.c
31 files changed, 113 insertions(+), 107 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/09/30409/1
diff --git a/82802ab.c b/82802ab.c
index 1046da4..281b66e 100644
--- a/82802ab.c
+++ b/82802ab.c
@@ -126,7 +126,7 @@
/* chunksize is 1 */
int write_82802ab(struct flashctx *flash, const uint8_t *src, unsigned int start, unsigned int len)
{
- int i;
+ unsigned int i;
chipaddr dst = flash->virtual_memory + start;

for (i = 0; i < len; i++) {
@@ -144,7 +144,7 @@
{
chipaddr bios = flash->virtual_memory;
uint8_t mcfg, bcfg, need_unlock = 0, can_unlock = 0;
- int i;
+ unsigned int i;

/* Clear status register */
chip_writeb(flash, 0x50, bios);
@@ -197,7 +197,7 @@
chipaddr bios = flash->virtual_memory;
uint8_t mcfg, bcfg;
uint8_t need_unlock = 0, can_unlock = 0;
- int i;
+ unsigned int i;

/* Wait if chip is busy */
wait_82802ab(flash);
diff --git a/at45db.c b/at45db.c
index 619d41c..85ce046 100644
--- a/at45db.c
+++ b/at45db.c
@@ -463,7 +463,7 @@
}

/* Create a suitable buffer to store opcode, address and data chunks for buffer1. */
- const int max_data_write = flash->mst->spi.max_data_write - 4;
+ const unsigned int max_data_write = flash->mst->spi.max_data_write - 4;
const unsigned int max_chunk = (max_data_write > 0 && max_data_write <= page_size) ?
max_data_write : page_size;
uint8_t buf[4 + max_chunk];
diff --git a/bitbang_spi.c b/bitbang_spi.c
index 4b39164..11794b0 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -154,7 +154,7 @@
const unsigned char *writearr,
unsigned char *readarr)
{
- int i;
+ unsigned int i;
const struct bitbang_spi_master *master = flash->mst->spi.data;

/* FIXME: Run bitbang_spi_request_bus here or in programmer init?
diff --git a/board_enable.c b/board_enable.c
index 00809f7..9c31310 100644
--- a/board_enable.c
+++ b/board_enable.c
@@ -373,7 +373,8 @@

static const struct winbond_chip *winbond_superio_chipdef(void)
{
- int i, j;
+ int i;
+ unsigned int j;

for (i = 0; i < superio_count; i++) {
if (superios[i].vendor != SUPERIO_VENDOR_WINBOND)
diff --git a/buspirate_spi.c b/buspirate_spi.c
index 09f10c3..d64f7d7 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -76,7 +76,8 @@
static int buspirate_sendrecv(unsigned char *buf, unsigned int writecnt,
unsigned int readcnt)
{
- int i, ret = 0;
+ unsigned int i;
+ int ret = 0;

msg_pspew("%s: write %i, read %i ", __func__, writecnt, readcnt);
if (!writecnt && !readcnt) {
@@ -663,4 +664,4 @@
memcpy(readarr, bp_commbuf + 1, readcnt);

return ret;
-}
\ No newline at end of file
+}
diff --git a/cbtable.c b/cbtable.c
index fe0c368..bdf53ce 100644
--- a/cbtable.c
+++ b/cbtable.c
@@ -34,7 +34,7 @@
* -1 if IDs in the image do not match the IDs embedded in the current firmware,
* 0 if the IDs could not be found in the image or if they match correctly.
*/
-int cb_check_image(const uint8_t *image, int size)
+int cb_check_image(const uint8_t *image, unsigned int size)
{
const unsigned int *walk;
unsigned int mb_part_offset, mb_vendor_offset;
@@ -138,10 +138,10 @@
((((char *)rec) + rec->size) <= (((char *)head) + sizeof(*head) + head->table_bytes)); \
rec = (struct lb_record *)(((char *)rec) + rec->size))

-static int count_lb_records(struct lb_header *head)
+static unsigned int count_lb_records(struct lb_header *head)
{
struct lb_record *rec;
- int count;
+ unsigned int count;

count = 0;
for_each_lbrec(head, rec) {
diff --git a/cli_classic.c b/cli_classic.c
index ced08c6..31dd5ef 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -505,7 +505,7 @@

for (j = 0; j < registered_master_count; j++) {
startchip = 0;
- while (chipcount < ARRAY_SIZE(flashes)) {
+ while (chipcount < (int)ARRAY_SIZE(flashes)) {
startchip = probe_flash(&registered_masters[j], startchip, &flashes[chipcount], 0);
if (startchip == -1)
break;
diff --git a/dediprog.c b/dediprog.c
index 72818ea..9d0dd2e 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -441,7 +441,7 @@
fill_rw_cmd_payload(data_packet, count, READ_MODE_STD, &value, &idx, start, 1);

int ret = dediprog_write(CMD_READ, value, idx, data_packet, sizeof(data_packet));
- if (ret != sizeof(data_packet)) {
+ if (ret != (int)sizeof(data_packet)) {
msg_perr("Command Read SPI Bulk failed, %i %s!\n", ret, libusb_error_name(ret));
return 1;
}
@@ -454,7 +454,7 @@

/* Allocate bulk transfers. */
unsigned int i;
- for (i = 0; i < min(DEDIPROG_ASYNC_TRANSFERS, count); ++i) {
+ for (i = 0; i < MIN(DEDIPROG_ASYNC_TRANSFERS, count); ++i) {
transfers[i] = libusb_alloc_transfer(0);
if (!transfers[i]) {
msg_perr("Allocating libusb transfer %i failed: %s!\n", i, libusb_error_name(ret));
@@ -596,7 +596,7 @@
unsigned int value, idx;
fill_rw_cmd_payload(data_packet, count, dedi_spi_cmd, &value, &idx, start, 0);
int ret = dediprog_write(CMD_WRITE, value, idx, data_packet, sizeof(data_packet));
- if (ret != sizeof(data_packet)) {
+ if (ret != (int)sizeof(data_packet)) {
msg_perr("Command Write SPI Bulk failed, %s!\n", libusb_error_name(ret));
return 1;
}
@@ -709,7 +709,7 @@
value = 0;
}
ret = dediprog_write(CMD_TRANSCEIVE, value, idx, writearr, writecnt);
- if (ret != writecnt) {
+ if (ret != (int)writecnt) {
msg_perr("Send SPI failed, expected %i, got %i %s!\n",
writecnt, ret, libusb_error_name(ret));
return 1;
@@ -736,7 +736,7 @@
ret = dediprog_read(CMD_TRANSCEIVE, value, idx, readarr, readcnt);
*/
ret = dediprog_read(CMD_TRANSCEIVE, 0, 0, readarr, readcnt);
- if (ret != readcnt) {
+ if (ret != (int)readcnt) {
msg_perr("Receive SPI failed, expected %i, got %i %s!\n", readcnt, ret, libusb_error_name(ret));
return 1;
}
@@ -770,7 +770,7 @@
int sfnum;
int fw[3];
if (sscanf(buf, "SF%d V:%d.%d.%d ", &sfnum, &fw[0], &fw[1], &fw[2]) != 4 ||
- sfnum != dediprog_devicetype) {
+ sfnum != (int)dediprog_devicetype) {
msg_perr("Unexpected firmware version string '%s'\n", buf);
return 1;
}
diff --git a/dmi.c b/dmi.c
index 79321ce..5bd0e16 100644
--- a/dmi.c
+++ b/dmi.c
@@ -147,7 +147,7 @@

static void dmi_chassis_type(uint8_t code)
{
- int i;
+ unsigned int i;
code &= 0x7f; /* bits 6:0 are chassis type, 7th bit is the lock bit */
is_laptop = 2;
for (i = 0; i < ARRAY_SIZE(dmi_chassis_types); i++) {
@@ -161,7 +161,7 @@

static void dmi_table(uint32_t base, uint16_t len, uint16_t num)
{
- int i = 0, j = 0;
+ unsigned int i = 0, j = 0;

uint8_t *dmi_table_mem = physmap_ro("DMI Table", base, len);
if (dmi_table_mem == NULL) {
@@ -347,7 +347,7 @@

int dmi_fill(void)
{
- int i;
+ unsigned int i;
char *chassis_type;

msg_pdbg("Using External DMI decoder.\n");
@@ -377,7 +377,7 @@

static int dmi_shutdown(void *data)
{
- int i;
+ unsigned int i;
for (i = 0; i < ARRAY_SIZE(dmi_strings); i++) {
free(dmi_strings[i].value);
dmi_strings[i].value = NULL;
@@ -407,7 +407,7 @@
}

has_dmi_support = 1;
- int i;
+ unsigned int i;
for (i = 0; i < ARRAY_SIZE(dmi_strings); i++) {
msg_pdbg("DMI string %s: \"%s\"\n", dmi_strings[i].keyword,
(dmi_strings[i].value == NULL) ? "" : dmi_strings[i].value);
@@ -464,7 +464,7 @@

int dmi_match(const char *pattern)
{
- int i;
+ unsigned int i;

if (!has_dmi_support)
return 0;
diff --git a/dummyflasher.c b/dummyflasher.c
index 2929686..fdb632d 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -57,8 +57,8 @@
static unsigned int emu_jedec_ce_c7_size = 0;
unsigned char spi_blacklist[256];
unsigned char spi_ignorelist[256];
-int spi_blacklist_size = 0;
-int spi_ignorelist_size = 0;
+unsigned int spi_blacklist_size = 0;
+unsigned int spi_ignorelist_size = 0;
static uint8_t emu_status = 0;

/* A legit complete SFDP table based on the MX25L6436E (rev. 1.8) datasheet. */
@@ -151,7 +151,7 @@
{
char *bustext = NULL;
char *tmp = NULL;
- int i;
+ unsigned int i;
#if EMULATE_SPI_CHIP
char *status = NULL;
#endif
@@ -790,7 +790,7 @@
const unsigned char *writearr,
unsigned char *readarr)
{
- int i;
+ unsigned int i;

msg_pspew("%s:", __func__);

diff --git a/en29lv640b.c b/en29lv640b.c
index 550642d..5b01904 100644
--- a/en29lv640b.c
+++ b/en29lv640b.c
@@ -29,7 +29,7 @@
/* chunksize is 1 */
int write_en29lv640b(struct flashctx *flash, const uint8_t *src, unsigned int start, unsigned int len)
{
- int i;
+ unsigned int i;
chipaddr bios = flash->virtual_memory;
chipaddr dst = flash->virtual_memory + start;

diff --git a/flash.h b/flash.h
index 911214c..254ac54 100644
--- a/flash.h
+++ b/flash.h
@@ -295,7 +295,9 @@

/* helpers.c */
uint32_t address_to_bits(uint32_t addr);
-int bitcount(unsigned long a);
+unsigned int bitcount(unsigned long a);
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
int max(int a, int b);
int min(int a, int b);
char *strcat_realloc(char *dest, const char *src);
diff --git a/flashrom.c b/flashrom.c
index 55293dd..9c628be 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1015,7 +1015,7 @@
*/
int generate_testpattern(uint8_t *buf, uint32_t size, int variant)
{
- int i;
+ uint32_t i;

if (!buf) {
msg_gerr("Invalid buffer!\n");
@@ -1374,7 +1374,7 @@
ret = 1;
goto out;
}
- if (image_stat.st_size != size) {
+ if (image_stat.st_size != (intmax_t)size) {
msg_gerr("Error: Image size (%jd B) doesn't match the flash chip's size (%lu B)!\n",
(intmax_t)image_stat.st_size, size);
ret = 1;
diff --git a/fmap.c b/fmap.c
index 84b3b54..5a63570 100644
--- a/fmap.c
+++ b/fmap.c
@@ -96,7 +96,7 @@
off_t offset;
bool fmap_found = 0;

- for (offset = 0; offset <= len - sizeof(struct fmap); offset++) {
+ for (offset = 0; offset <= (off_t)(len - sizeof(struct fmap)); offset++) {
if (is_valid_fmap((struct fmap *)&buf[offset])) {
fmap_found = 1;
break;
@@ -179,7 +179,7 @@
}

static int fmap_bsearch_rom(struct fmap **fmap_out, struct flashctx *const flashctx,
- size_t rom_offset, size_t len, int min_stride)
+ size_t rom_offset, size_t len, size_t min_stride)
{
size_t stride, fmap_len = 0;
int ret = 1, fmap_found = 0, check_offset_0 = 1;
diff --git a/helpers.c b/helpers.c
index a714908..cfa9812 100644
--- a/helpers.c
+++ b/helpers.c
@@ -30,9 +30,9 @@
return 32 - lzb;
}

-int bitcount(unsigned long a)
+unsigned int bitcount(unsigned long a)
{
- int i = 0;
+ unsigned int i = 0;
for (; a != 0; a >>= 1)
if (a & 1)
i++;
diff --git a/ich_descriptors.c b/ich_descriptors.c
index 02f4547..1622d41 100644
--- a/ich_descriptors.c
+++ b/ich_descriptors.c
@@ -35,10 +35,6 @@
#include "flash.h" /* for msg_* */
#include "programmer.h"

-#ifndef min
-#define min(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-
ssize_t ich_number_of_regions(const enum ich_chipset cs, const struct ich_desc_content *const cont)
{
switch (cs) {
@@ -338,7 +334,7 @@

void prettyprint_ich_descriptor_region(const enum ich_chipset cs, const struct ich_descriptors *const desc)
{
- size_t i;
+ ssize_t i;
const ssize_t nr = ich_number_of_regions(cs, &desc->content);
msg_pdbg2("=== Region Section ===\n");
if (nr < 0) {
@@ -347,18 +343,18 @@
return;
}
for (i = 0; i < nr; i++)
- msg_pdbg2("FLREG%zu 0x%08x\n", i, desc->region.FLREGs[i]);
+ msg_pdbg2("FLREG%zd 0x%08x\n", i, desc->region.FLREGs[i]);
msg_pdbg2("\n");

msg_pdbg2("--- Details ---\n");
for (i = 0; i < nr; i++)
- pprint_freg(&desc->region, i);
+ pprint_freg(&desc->region, (uint32_t)i);
msg_pdbg2("\n");
}

void prettyprint_ich_descriptor_master(const enum ich_chipset cs, const struct ich_descriptors *const desc)
{
- size_t i;
+ ssize_t i;
const ssize_t nm = ich_number_of_masters(cs, &desc->content);
msg_pdbg2("=== Master Section ===\n");
if (nm < 0) {
@@ -367,7 +363,7 @@
return;
}
for (i = 0; i < nm; i++)
- msg_pdbg2("FLMSTR%zu 0x%08x\n", i + 1, desc->master.FLMSTRs[i]);
+ msg_pdbg2("FLMSTR%zd 0x%08x\n", i + 1, desc->master.FLMSTRs[i]);
msg_pdbg2("\n");

msg_pdbg2("--- Details ---\n");
@@ -375,7 +371,7 @@
const char *const master_names[] = {
"BIOS", "ME", "GbE", "unknown", "EC",
};
- if (nm >= ARRAY_SIZE(master_names)) {
+ if (nm >= (ssize_t)ARRAY_SIZE(master_names)) {
msg_pdbg2("%s: number of masters too high (%d).\n", __func__,
desc->content.NM + 1);
return;
@@ -396,7 +392,7 @@
"BIOS", "ME", "GbE", "DE", "BMC", "IE",
};
/* NM starts at 1 instead of 0 for LBG */
- if (nm > ARRAY_SIZE(master_names)) {
+ if (nm > (ssize_t)ARRAY_SIZE(master_names)) {
msg_pdbg2("%s: number of masters too high (%d).\n", __func__,
desc->content.NM);
return;
@@ -755,7 +751,7 @@
unsigned int i, max_count;
msg_pdbg2("=== Softstraps ===\n");

- max_count = min(ARRAY_SIZE(desc->north.STRPs), desc->content.MSL);
+ max_count = MIN(ARRAY_SIZE(desc->north.STRPs), desc->content.MSL);
if (max_count < desc->content.MSL) {
msg_pdbg2("MSL (%u) is greater than the current maximum of %u entries.\n",
desc->content.MSL, max_count);
@@ -767,7 +763,7 @@
msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]);
msg_pdbg2("\n");

- max_count = min(ARRAY_SIZE(desc->south.STRPs), desc->content.ISL);
+ max_count = MIN(ARRAY_SIZE(desc->south.STRPs), desc->content.ISL);
if (max_count < desc->content.ISL) {
msg_pdbg2("ISL (%u) is greater than the current maximum of %u entries.\n",
desc->content.ISL, max_count);
@@ -914,8 +910,8 @@
int read_ich_descriptors_from_dump(const uint32_t *const dump, const size_t len,
enum ich_chipset *const cs, struct ich_descriptors *const desc)
{
- size_t i, max_count;
- uint8_t pch_bug_offset = 0;
+ ssize_t i, max_count;
+ size_t pch_bug_offset = 0;

if (dump == NULL || desc == NULL)
return ICH_RET_PARAM;
@@ -949,14 +945,14 @@

/* region */
const ssize_t nr = ich_number_of_regions(*cs, &desc->content);
- if (nr < 0 || len < getFRBA(&desc->content) + nr * 4)
+ if (nr < 0 || len < getFRBA(&desc->content) + (size_t)nr * 4)
return ICH_RET_OOB;
for (i = 0; i < nr; i++)
desc->region.FLREGs[i] = dump[(getFRBA(&desc->content) >> 2) + i];

/* master */
const ssize_t nm = ich_number_of_masters(*cs, &desc->content);
- if (nm < 0 || len < getFMBA(&desc->content) + nm * 4)
+ if (nm < 0 || len < getFMBA(&desc->content) + (size_t)nm * 4)
return ICH_RET_OOB;
for (i = 0; i < nm; i++)
desc->master.FLMSTRs[i] = dump[(getFMBA(&desc->content) >> 2) + i];
@@ -983,7 +979,7 @@
return ICH_RET_OOB;

/* limit the range to be written */
- max_count = min(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
+ max_count = MIN(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
for (i = 0; i < max_count; i++)
desc->north.STRPs[i] = dump[(getFMSBA(&desc->content) >> 2) + i];

@@ -992,7 +988,7 @@
return ICH_RET_OOB;

/* limit the range to be written */
- max_count = min(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
+ max_count = MIN(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
for (i = 0; i < max_count; i++)
desc->south.STRPs[i] = dump[(getFISBA(&desc->content) >> 2) + i];

@@ -1079,7 +1075,7 @@

int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_descriptors *desc)
{
- size_t i;
+ ssize_t i;
struct ich_desc_region *r = &desc->region;

/* Test if bit-fields are working as expected.
@@ -1170,7 +1166,8 @@
memset(layout, 0x00, sizeof(*layout));

ssize_t i, j;
- for (i = 0, j = 0; i < min(ich_number_of_regions(cs, &desc.content), ARRAY_SIZE(regions)); ++i) {
+ const ssize_t nr = MIN(ich_number_of_regions(cs, &desc.content), (ssize_t)ARRAY_SIZE(regions));
+ for (i = 0, j = 0; i < nr; ++i) {
const chipoff_t base = ICH_FREG_BASE(desc.region.FLREGs[i]);
const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]);
if (limit <= base)
diff --git a/ichspi.c b/ichspi.c
index ba7d56b..01fa4ae 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -467,7 +467,7 @@

static uint8_t lookup_spi_type(uint8_t opcode)
{
- int a;
+ unsigned int a;

for (a = 0; a < ARRAY_SIZE(POSSIBLE_OPCODES); a++) {
if (POSSIBLE_OPCODES[a].opcode == opcode)
@@ -1561,7 +1561,7 @@
"locked", "read-only", "write-only", "read-write"
};

-static enum ich_access_protection ich9_handle_frap(uint32_t frap, int i)
+static enum ich_access_protection ich9_handle_frap(uint32_t frap, unsigned int i)
{
const int rwperms_unknown = ARRAY_SIZE(access_names);
static const char *const region_names[5] = {
@@ -1590,23 +1590,23 @@
limit = ICH_FREG_LIMIT(freg);
if (base > limit || (freg == 0 && i > 0)) {
/* this FREG is disabled */
- msg_pdbg2("0x%02X: 0x%08x FREG%i: %s region is unused.\n",
+ msg_pdbg2("0x%02X: 0x%08x FREG%u: %s region is unused.\n",
offset, freg, i, region_name);
return NO_PROT;
}
msg_pdbg("0x%02X: 0x%08x ", offset, freg);
if (rwperms == 0x3) {
- msg_pdbg("FREG%i: %s region (0x%08x-0x%08x) is %s.\n", i,
+ msg_pdbg("FREG%u: %s region (0x%08x-0x%08x) is %s.\n", i,
region_name, base, limit, access_names[rwperms]);
return NO_PROT;
}
if (rwperms == rwperms_unknown) {
- msg_pdbg("FREG%i: %s region (0x%08x-0x%08x) has unknown permissions.\n",
+ msg_pdbg("FREG%u: %s region (0x%08x-0x%08x) has unknown permissions.\n",
i, region_name, base, limit);
return NO_PROT;
}

- msg_pinfo("FREG%i: %s region (0x%08x-0x%08x) is %s.\n", i,
+ msg_pinfo("FREG%u: %s region (0x%08x-0x%08x) is %s.\n", i,
region_name, base, limit, access_names[rwperms]);
return access_perms_to_protection[rwperms];
}
@@ -1620,7 +1620,7 @@
#define ICH_PR_PERMS(pr) (((~((pr) >> PR_RP_OFF) & 1) << 0) | \
((~((pr) >> PR_WP_OFF) & 1) << 1))

-static enum ich_access_protection ich9_handle_pr(const size_t reg_pr0, int i)
+static enum ich_access_protection ich9_handle_pr(const size_t reg_pr0, unsigned int i)
{
uint8_t off = reg_pr0 + (i * 4);
uint32_t pr = mmio_readl(ich_spibar + off);
@@ -1698,7 +1698,7 @@

int ich_init_spi(void *spibar, enum ich_chipset ich_gen)
{
- int i;
+ unsigned int i;
uint16_t tmp2;
uint32_t tmp;
char *arg;
@@ -1775,7 +1775,7 @@
for (i = 0; i < 3; i++) {
int offs;
offs = 0x60 + (i * 4);
- msg_pdbg("0x%02x: 0x%08x (PBR%d)\n", offs,
+ msg_pdbg("0x%02x: 0x%08x (PBR%u)\n", offs,
mmio_readl(ich_spibar + offs), i);
}
if (mmio_readw(ich_spibar) & (1 << 15)) {
diff --git a/it85spi.c b/it85spi.c
index e47cabb..5a6502b 100644
--- a/it85spi.c
+++ b/it85spi.c
@@ -328,7 +328,7 @@
const unsigned char *writearr,
unsigned char *readarr)
{
- int i;
+ unsigned int i;

it85xx_enter_scratch_rom();
/* Exit scratch ROM ONLY when programmer shuts down. Otherwise, the
diff --git a/it87spi.c b/it87spi.c
index efc2e02..78c2b68 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -282,7 +282,6 @@
unsigned char *readarr)
{
uint8_t busy, writeenc;
- int i;

do {
busy = INB(it8716f_flashport) & 0x80;
@@ -331,6 +330,8 @@
| ((readcnt & 0x3) << 2) | (writeenc), it8716f_flashport);

if (readcnt > 0) {
+ unsigned int i;
+
do {
busy = INB(it8716f_flashport) & 0x80;
} while (busy);
diff --git a/jedec.c b/jedec.c
index 54b7da7..ef48206 100644
--- a/jedec.c
+++ b/jedec.c
@@ -408,7 +408,8 @@
int write_jedec_1(struct flashctx *flash, const uint8_t *src, unsigned int start,
unsigned int len)
{
- int i, failed = 0;
+ unsigned int i;
+ int failed = 0;
chipaddr dst = flash->virtual_memory + start;
chipaddr olddst;
unsigned int mask;
@@ -430,7 +431,8 @@
static int write_page_write_jedec_common(struct flashctx *flash, const uint8_t *src,
unsigned int start, unsigned int page_size)
{
- int i, tried = 0, failed;
+ unsigned int i;
+ int tried = 0, failed;
const uint8_t *s = src;
chipaddr bios = flash->virtual_memory;
chipaddr dst = bios + start;
diff --git a/layout.c b/layout.c
index fa66238..2d35fa9 100644
--- a/layout.c
+++ b/layout.c
@@ -29,7 +29,7 @@
/* include_args holds the arguments specified at the command line with -i. They must be processed at some point
* so that desired regions are marked as "included" in the layout. */
static char *include_args[MAX_ROMLAYOUT];
-static int num_include_args = 0; /* the number of valid include_args. */
+static unsigned int num_include_args = 0; /* the number of valid include_args. */

struct flashrom_layout *get_global_layout(void)
{
@@ -49,7 +49,7 @@
{
FILE *romlayout;
char tempstr[256];
- int i;
+ unsigned int i;

romlayout = fopen(name, "r");

@@ -116,7 +116,7 @@
int register_include_arg(char *name)
{
if (num_include_args >= MAX_ROMLAYOUT) {
- msg_gerr("Too many regions included (%i).\n", num_include_args);
+ msg_gerr("Too many regions included (%u).\n", num_include_args);
return 1;
}

@@ -138,7 +138,7 @@
/* returns the index of the entry (or a negative value if it is not found) */
static int find_romentry(struct flashrom_layout *const l, char *name)
{
- int i;
+ unsigned int i;

if (l->num_entries == 0)
return -1;
@@ -148,7 +148,7 @@
if (!strcmp(l->entries[i].name, name)) {
l->entries[i].included = 1;
msg_gspew("found.\n");
- return i;
+ return (int)i;
}
}
msg_gspew("not found.\n");
@@ -160,7 +160,7 @@
*/
int process_include_args(struct flashrom_layout *const l)
{
- int i;
+ unsigned int i;
unsigned int found = 0;

if (num_include_args == 0)
@@ -193,7 +193,7 @@

void layout_cleanup(void)
{
- int i;
+ unsigned int i;
for (i = 0; i < num_include_args; i++) {
free(include_args[i]);
include_args[i] = NULL;
@@ -212,7 +212,7 @@
chipsize_t total_size = flash->chip->total_size * 1024;
int ret = 0;

- int i;
+ unsigned int i;
for (i = 0; i < layout.num_entries; i++) {
if (layout.entries[i].start >= total_size || layout.entries[i].end >= total_size) {
msg_gwarn("Warning: Address range of region \"%s\" exceeds the current chip's "
diff --git a/pickit2_spi.c b/pickit2_spi.c
index a7c90a5..fe638a1 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -225,7 +225,7 @@
}

uint8_t buf[CMD_LENGTH] = {CMD_DOWNLOAD_DATA, writecnt};
- int i = 2;
+ unsigned int i = 2;
for (; i < writecnt + 2; i++) {
buf[i] = writearr[i - 2];
}
@@ -240,7 +240,7 @@
buf[i++] = 10;
else
buf[i++] = 13;
-
+
/* Assert CS# */
buf[i++] = SCR_VPP_OFF;
buf[i++] = SCR_MCLR_GND_ON;
@@ -291,7 +291,7 @@
readcnt, ret);
return 1;
}
-
+
/* Actual data starts at byte number two */
memcpy(readarr, &buf[1], readcnt);
}
diff --git a/print.c b/print.c
index 30f06c8..8c90490 100644
--- a/print.c
+++ b/print.c
@@ -19,6 +19,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <stddef.h>
#include "flash.h"
#include "programmer.h"

@@ -314,15 +315,15 @@
#if CONFIG_INTERNAL == 1
static void print_supported_chipsets(void)
{
- int i, chipsetcount = 0;
+ unsigned int i, chipsetcount = 0;
const struct penable *c = chipset_enables;
- int maxvendorlen = strlen("Vendor") + 1;
- int maxchipsetlen = strlen("Chipset") + 1;
+ size_t maxvendorlen = strlen("Vendor") + 1;
+ size_t maxchipsetlen = strlen("Chipset") + 1;

for (c = chipset_enables; c->vendor_name != NULL; c++) {
chipsetcount++;
- maxvendorlen = max(maxvendorlen, strlen(c->vendor_name));
- maxchipsetlen = max(maxchipsetlen, strlen(c->device_name));
+ maxvendorlen = MAX(maxvendorlen, strlen(c->vendor_name));
+ maxchipsetlen = MAX(maxchipsetlen, strlen(c->device_name));
}
maxvendorlen++;
maxchipsetlen++;
@@ -354,12 +355,12 @@
static void print_supported_boards_helper(const struct board_info *boards,
const char *devicetype)
{
- int i;
+ unsigned int i;
unsigned int boardcount_good = 0, boardcount_bad = 0, boardcount_nt = 0;
const struct board_match *e = board_matches;
const struct board_info *b = boards;
- int maxvendorlen = strlen("Vendor") + 1;
- int maxboardlen = strlen("Board") + 1;
+ size_t maxvendorlen = strlen("Vendor") + 1;
+ size_t maxboardlen = strlen("Board") + 1;

for (b = boards; b->vendor != NULL; b++) {
maxvendorlen = max(maxvendorlen, strlen(b->vendor));
diff --git a/programmer.h b/programmer.h
index 311992a..d571748 100644
--- a/programmer.h
+++ b/programmer.h
@@ -326,7 +326,7 @@

/* cbtable.c */
int cb_parse_table(const char **vendor, const char **model);
-int cb_check_image(const uint8_t *bios, int size);
+int cb_check_image(const uint8_t *bios, unsigned int size);

/* dmi.c */
#if defined(__i386__) || defined(__x86_64__)
diff --git a/sb600spi.c b/sb600spi.c
index 1efb2ce..63a72f1 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -249,7 +249,7 @@

reset_internal_fifo_pointer();
msg_pspew("Filling FIFO: ");
- int count;
+ unsigned int count;
for (count = 0; count < writecnt; count++) {
msg_pspew("[%02x]", writearr[count]);
mmio_writeb(writearr[count], sb600_spibar + 0xC);
@@ -328,7 +328,7 @@
mmio_writeb(readcnt, sb600_spibar + 0x4b);

msg_pspew("Filling buffer: ");
- int count;
+ unsigned int count;
for (count = 0; count < writecnt; count++) {
msg_pspew("[%02x]", writearr[count]);
mmio_writeb(writearr[count], sb600_spibar + 0x80 + count);
diff --git a/serial.c b/serial.c
index e61df74..3a99dbf 100644
--- a/serial.c
+++ b/serial.c
@@ -480,10 +480,10 @@
}
#endif

- int i;
- int rd_bytes = 0;
+ unsigned int i;
+ unsigned int rd_bytes = 0;
for (i = 0; i < timeout; i++) {
- msg_pspew("readcnt %d rd_bytes %d\n", readcnt, rd_bytes);
+ msg_pspew("readcnt %u rd_bytes %u\n", readcnt, rd_bytes);
#if IS_WINDOWS
ReadFile(sp_fd, c + rd_bytes, readcnt - rd_bytes, &rv, NULL);
msg_pspew("read %lu bytes\n", rv);
@@ -560,10 +560,10 @@
}
#endif

- int i;
- int wr_bytes = 0;
+ unsigned int i;
+ unsigned int wr_bytes = 0;
for (i = 0; i < timeout; i++) {
- msg_pspew("writecnt %d wr_bytes %d\n", writecnt, wr_bytes);
+ msg_pspew("writecnt %u wr_bytes %u\n", writecnt, wr_bytes);
#if IS_WINDOWS
WriteFile(sp_fd, buf + wr_bytes, writecnt - wr_bytes, &rv, NULL);
msg_pspew("wrote %lu bytes\n", rv);
diff --git a/serprog.c b/serprog.c
index c3d48a4..bef514a 100644
--- a/serprog.c
+++ b/serprog.c
@@ -71,8 +71,8 @@
static uint32_t sp_write_n_bytes = 0;

/* sp_streamed_* used for flow control checking */
-static int sp_streamed_transmit_ops = 0;
-static int sp_streamed_transmit_bytes = 0;
+static unsigned int sp_streamed_transmit_ops = 0;
+static unsigned int sp_streamed_transmit_bytes = 0;

/* sp_opbuf_usage used for counting the amount of
on-device operation buffer used */
diff --git a/sst28sf040.c b/sst28sf040.c
index 9df27b9..3da25f1 100644
--- a/sst28sf040.c
+++ b/sst28sf040.c
@@ -75,7 +75,7 @@
/* chunksize is 1 */
int write_28sf040(struct flashctx *flash, const uint8_t *src, unsigned int start, unsigned int len)
{
- int i;
+ unsigned int i;
chipaddr bios = flash->virtual_memory;
chipaddr dst = flash->virtual_memory + start;

diff --git a/sst_fwhub.c b/sst_fwhub.c
index 398b01b..fc8fe3a 100644
--- a/sst_fwhub.c
+++ b/sst_fwhub.c
@@ -20,7 +20,7 @@

#include "flash.h"

-static int check_sst_fwhub_block_lock(struct flashctx *flash, int offset)
+static int check_sst_fwhub_block_lock(struct flashctx *flash, unsigned int offset)
{
chipaddr registers = flash->virtual_registers;
uint8_t blockstatus;
@@ -46,7 +46,7 @@
return blockstatus & 0x1;
}

-static int clear_sst_fwhub_block_lock(struct flashctx *flash, int offset)
+static int clear_sst_fwhub_block_lock(struct flashctx *flash, unsigned int offset)
{
chipaddr registers = flash->virtual_registers;
uint8_t blockstatus;
@@ -66,7 +66,7 @@

int printlock_sst_fwhub(struct flashctx *flash)
{
- int i;
+ unsigned int i;

for (i = 0; i < flash->chip->total_size * 1024; i += flash->chip->page_size)
check_sst_fwhub_block_lock(flash, i);
@@ -76,7 +76,8 @@

int unlock_sst_fwhub(struct flashctx *flash)
{
- int i, ret=0;
+ unsigned int i;
+ int ret = 0;

for (i = 0; i < flash->chip->total_size * 1024; i += flash->chip->page_size)
{
diff --git a/usbblaster_spi.c b/usbblaster_spi.c
index fa984e5..e5f66ce 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -119,11 +119,11 @@

static int send_write(unsigned int writecnt, const unsigned char *writearr)
{
- int i;
uint8_t buf[BUF_SIZE];

memset(buf, 0, sizeof(buf));
while (writecnt) {
+ unsigned int i;
unsigned int n_write = min(writecnt, BUF_SIZE - 1);
msg_pspew("writing %d-byte packet\n", n_write);

diff --git a/wbsio_spi.c b/wbsio_spi.c
index ccd227b..aed80b5 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -116,7 +116,7 @@
const unsigned char *writearr,
unsigned char *readarr)
{
- int i;
+ unsigned int i;
uint8_t mode = 0;

msg_pspew("%s:", __func__);

To view, visit change 30409. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I08895543ffb7a48058bcf91ef6500ca113f2d305
Gerrit-Change-Number: 30409
Gerrit-PatchSet: 1
Gerrit-Owner: Nico Huber <nico.h@gmx.de>
Gerrit-MessageType: newchange