summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2021-04-30 16:24:50 -0700
committerCommit Bot <commit-bot@chromium.org>2021-05-06 17:29:59 +0000
commite0a4e5ab99a45faa196b3894ade8c375061a7ab6 (patch)
treeb20a581a87a8c8513068280cad1c496d7f472137
parent1f4c9670318eca8c6b7bdc674fa2a4930e21a5c4 (diff)
downloadchrome-ec-e0a4e5ab99a45faa196b3894ade8c375061a7ab6.tar.gz
util: Add explicit casts
When compiling with C++, the implicit casting that is performed in C is disallowed. Add casts in preparation for C++ compatibility. BRANCH=none BUG=b:144959033 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I5c25440819428db65225c772c1c5115a735db58a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2864519 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--common/crc.c2
-rw-r--r--include/usb_pd_tcpm.h2
-rw-r--r--util/comm-dev.c8
-rw-r--r--util/comm-host.c2
-rw-r--r--util/comm-i2c.c4
-rw-r--r--util/comm-lpc.c2
-rw-r--r--util/comm-servo-spi.c11
-rw-r--r--util/ec_flash.c2
-rw-r--r--util/ectool.c61
-rw-r--r--util/ectool_keyscan.c17
-rw-r--r--util/stm32mon.c21
-rw-r--r--util/uut/main.c4
-rw-r--r--util/uut/opr.c2
13 files changed, 77 insertions, 61 deletions
diff --git a/common/crc.c b/common/crc.c
index 04847cf095..8b45150b67 100644
--- a/common/crc.c
+++ b/common/crc.c
@@ -60,7 +60,7 @@ static uint32_t _crc32_hash(uint32_t crc, const void *buf, int size)
{
const uint8_t *p;
- p = buf;
+ p = (const uint8_t *)buf;
while (size--) {
crc ^= *p++;
diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h
index fddcb04c3a..700b1d0fcd 100644
--- a/include/usb_pd_tcpm.h
+++ b/include/usb_pd_tcpm.h
@@ -61,7 +61,7 @@ static inline enum tcpc_cc_polarity polarity_rm_dts(
enum tcpc_cc_polarity polarity)
{
BUILD_ASSERT(POLARITY_COUNT == 4);
- return polarity & BIT(0);
+ return (enum tcpc_cc_polarity)(polarity & BIT(0));
}
enum tcpm_transmit_type {
diff --git a/util/comm-dev.c b/util/comm-dev.c
index 679f15225f..e73538b323 100644
--- a/util/comm-dev.c
+++ b/util/comm-dev.c
@@ -73,7 +73,7 @@ static int ec_command_dev(int command, int version,
s_cmd.outsize = outsize;
s_cmd.outdata = (uint8_t *)outdata;
s_cmd.insize = insize;
- s_cmd.indata = indata;
+ s_cmd.indata = (uint8_t *)(indata);
r = ioctl(fd, CROS_EC_DEV_IOCXCMD, &s_cmd);
if (r < 0) {
@@ -107,7 +107,7 @@ static int ec_readmem_dev(int offset, int bytes, void *dest)
if (!fake_it) {
s_mem.offset = offset;
s_mem.bytes = bytes;
- s_mem.buffer = dest;
+ s_mem.buffer = (char *)(dest);
r = ioctl(fd, CROS_EC_DEV_IOCRDMEM, &s_mem);
if (r < 0 && errno == ENOTTY)
fake_it = 1;
@@ -134,8 +134,8 @@ static int ec_command_dev_v2(int command, int version,
assert(outsize == 0 || outdata != NULL);
assert(insize == 0 || indata != NULL);
- s_cmd = malloc(sizeof(struct cros_ec_command_v2) +
- MAX(outsize, insize));
+ s_cmd = (struct cros_ec_command_v2 *)(malloc(
+ sizeof(struct cros_ec_command_v2) + MAX(outsize, insize)));
if (s_cmd == NULL)
return -EC_RES_ERROR;
diff --git a/util/comm-host.c b/util/comm-host.c
index dd42df1aa8..45d6f85a02 100644
--- a/util/comm-host.c
+++ b/util/comm-host.c
@@ -58,7 +58,7 @@ static int fake_readmem(int offset, int bytes, void *dest)
if (c < 0)
return c;
- buf = dest;
+ buf = (char *)(dest);
for (c = 0; c < EC_MEMMAP_TEXT_MAX; c++) {
if (buf[c] == 0)
return c;
diff --git a/util/comm-i2c.c b/util/comm-i2c.c
index 23b2b22f9f..83e0b1dcf7 100644
--- a/util/comm-i2c.c
+++ b/util/comm-i2c.c
@@ -87,7 +87,7 @@ static int ec_command_i2c_3(int command, int version,
}
req_len = I2C_REQUEST_HEADER_SIZE + sizeof(struct ec_host_request)
+ outsize;
- req_buf = calloc(1, req_len);
+ req_buf = (uint8_t *)(calloc(1, req_len));
if (!req_buf)
goto done;
@@ -115,7 +115,7 @@ static int ec_command_i2c_3(int command, int version,
resp_len = I2C_RESPONSE_HEADER_SIZE + sizeof(struct ec_host_response)
+ insize;
- resp_buf = calloc(1, resp_len);
+ resp_buf = (uint8_t *)(calloc(1, resp_len));
if (!resp_buf)
goto done;
memset(resp_buf, 0, resp_len);
diff --git a/util/comm-lpc.c b/util/comm-lpc.c
index a3a8f64ff7..d1ce761fc2 100644
--- a/util/comm-lpc.c
+++ b/util/comm-lpc.c
@@ -225,7 +225,7 @@ static int ec_command_lpc_3(int command, int version,
static int ec_readmem_lpc(int offset, int bytes, void *dest)
{
int i = offset;
- char *s = dest;
+ char *s = (char *)(dest);
int cnt = 0;
if (offset >= EC_MEMMAP_SIZE - bytes)
diff --git a/util/comm-servo-spi.c b/util/comm-servo-spi.c
index 4010d2ec64..ef6dc7880b 100644
--- a/util/comm-servo-spi.c
+++ b/util/comm-servo-spi.c
@@ -114,7 +114,7 @@ static int send_request(int cmd, int version,
size_t block_size = sizeof(struct ec_host_request) + outsize;
size_t total_len = MPSSE_CMD_SIZE + block_size;
- txbuf = calloc(1, total_len);
+ txbuf = (uint8_t *)(calloc(1, total_len));
if (!txbuf)
return -ENOMEM;
@@ -168,7 +168,7 @@ free_request:
return ret;
}
-static int spi_read(void *buf, size_t size)
+static int spi_read(uint8_t *buf, size_t size)
{
uint8_t cmd[MPSSE_CMD_SIZE];
@@ -206,7 +206,7 @@ static int get_response(uint8_t *bodydest, size_t bodylen)
}
/* Now read the response header */
- if (spi_read(&hdr, sizeof(hdr)))
+ if (spi_read((uint8_t *)(&hdr), sizeof(hdr)))
goto read_error;
/* Check the header */
@@ -256,8 +256,9 @@ static int ec_command_servo_spi(int cmd, int version,
return -EC_RES_ERROR;
}
- if (send_request(cmd, version, outdata, outsize) == 0)
- ret = get_response(indata, insize);
+ if (send_request(cmd, version, (const uint8_t *)(outdata), outsize) ==
+ 0)
+ ret = get_response((uint8_t *)(indata), insize);
if (mpsse_set_pins(CS_L) != 0) {
fprintf(stderr, "Stop failed: %s\n",
diff --git a/util/ec_flash.c b/util/ec_flash.c
index 3bae077200..ffa4eca4b7 100644
--- a/util/ec_flash.c
+++ b/util/ec_flash.c
@@ -41,7 +41,7 @@ int ec_flash_read(uint8_t *buf, int offset, int size)
int ec_flash_verify(const uint8_t *buf, int offset, int size)
{
- uint8_t *rbuf = malloc(size);
+ uint8_t *rbuf = (uint8_t *)(malloc(size));
int rv;
int i;
diff --git a/util/ectool.c b/util/ectool.c
index 91469284d4..fad8e27a7c 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -1353,7 +1353,7 @@ int cmd_rand(int argc, char *argv[])
return -1;
}
- r = ec_inbuf;
+ r = (struct ec_response_rand_num *)(ec_inbuf);
for (i = 0; i < num_bytes; i += ec_max_insize) {
p.num_rand_bytes = ec_max_insize;
@@ -1411,7 +1411,7 @@ int cmd_flash_read(int argc, char *argv[])
int offset, size;
int rv;
char *e;
- char *buf;
+ uint8_t *buf;
if (argc < 4) {
fprintf(stderr,
@@ -1430,7 +1430,7 @@ int cmd_flash_read(int argc, char *argv[])
}
printf("Reading %d bytes at offset %d...\n", size, offset);
- buf = (char *)malloc(size);
+ buf = (uint8_t *)malloc(size);
if (!buf) {
fprintf(stderr, "Unable to allocate buffer.\n");
return -1;
@@ -1443,7 +1443,7 @@ int cmd_flash_read(int argc, char *argv[])
return rv;
}
- rv = write_file(argv[3], buf, size);
+ rv = write_file(argv[3], (const char *)(buf), size);
free(buf);
if (rv)
return rv;
@@ -1478,7 +1478,8 @@ int cmd_flash_write(int argc, char *argv[])
printf("Writing to offset %d...\n", offset);
/* Write data in chunks */
- rv = ec_flash_write(buf, offset, size);
+ rv = ec_flash_write((const uint8_t *)(buf), offset,
+ size);
free(buf);
@@ -1987,7 +1988,7 @@ static void *fp_download_frame(struct ec_response_fp_info *info, int index)
return NULL;
}
- ptr = buffer;
+ ptr = (uint8_t *)(buffer);
p.offset = index << FP_FRAME_INDEX_SHIFT;
while (size) {
stride = MIN(ec_max_insize, size);
@@ -2259,7 +2260,7 @@ int cmd_fp_frame(int argc, char *argv[])
struct ec_response_fp_info r;
int idx = (argc == 2 && !strcasecmp(argv[1], "raw")) ?
FP_FRAME_INDEX_RAW_IMAGE : FP_FRAME_INDEX_SIMPLE_IMAGE;
- void *buffer = fp_download_frame(&r, idx);
+ uint8_t *buffer = (uint8_t *)(fp_download_frame(&r, idx));
uint8_t *ptr = buffer;
int x, y;
@@ -2290,14 +2291,15 @@ frame_done:
int cmd_fp_template(int argc, char *argv[])
{
struct ec_response_fp_info r;
- struct ec_params_fp_template *p = ec_outbuf;
+ struct ec_params_fp_template *p =
+ (struct ec_params_fp_template *)(ec_outbuf);
/* TODO(b/78544921): removing 32 bits is a workaround for the MCU bug */
int max_chunk = ec_max_outsize
- offsetof(struct ec_params_fp_template, data) - 4;
int idx = -1;
char *e;
int size;
- void *buffer = NULL;
+ char *buffer = NULL;
uint32_t offset = 0;
int rv = 0;
@@ -2308,7 +2310,7 @@ int cmd_fp_template(int argc, char *argv[])
idx = strtol(argv[1], &e, 0);
if (!(e && *e)) {
- buffer = fp_download_frame(&r, idx + 1);
+ buffer = (char *)(fp_download_frame(&r, idx + 1));
if (!buffer) {
fprintf(stderr, "Failed to get FP template %d\n", idx);
return -1;
@@ -2753,8 +2755,10 @@ static void cmd_smart_discharge_usage(const char *command)
int cmd_smart_discharge(int argc, char *argv[])
{
- struct ec_params_smart_discharge *p = ec_outbuf;
- struct ec_response_smart_discharge *r = ec_inbuf;
+ struct ec_params_smart_discharge *p =
+ (struct ec_params_smart_discharge *)(ec_outbuf);
+ struct ec_response_smart_discharge *r =
+ (struct ec_response_smart_discharge *)(ec_inbuf);
uint32_t cap;
char *e;
int rv;
@@ -6486,7 +6490,7 @@ int cmd_panic_info(int argc, char *argv[])
return 0;
}
- return parse_panic_info(ec_inbuf, rv);
+ return parse_panic_info((char *)(ec_inbuf), rv);
}
@@ -7288,7 +7292,7 @@ int cmd_i2c_xfer(int argc, char *argv[])
write_len = argc;
if (write_len) {
- write_buf = malloc(write_len);
+ write_buf = (uint8_t *)(malloc(write_len));
if (write_buf == NULL)
return -1;
for (i = 0; i < write_len; i++) {
@@ -8166,7 +8170,7 @@ static int cmd_cbi(int argc, char *argv[])
}
/* Tag */
- tag = strtol(argv[2], &e, 0);
+ tag = (enum cbi_data_tag)(strtol(argv[2], &e, 0));
if (e && *e) {
fprintf(stderr, "Bad tag\n");
return -1;
@@ -8197,7 +8201,8 @@ static int cmd_cbi(int argc, char *argv[])
if (cmd_cbi_is_string_field(tag)) {
printf("%.*s", rv, (const char *)ec_inbuf);
} else {
- const uint8_t * const buffer = ec_inbuf;
+ const uint8_t * const buffer =
+ (const uint8_t *const)(ec_inbuf);
uint64_t int_value = 0;
for(i = 0; i < rv; i++)
int_value |= (uint64_t)buffer[i] << (i * 8);
@@ -8231,7 +8236,7 @@ static int cmd_cbi(int argc, char *argv[])
if (cmd_cbi_is_string_field(tag)) {
val_ptr = argv[3];
- size = strlen(val_ptr) + 1;
+ size = strlen((char *)(val_ptr)) + 1;
} else {
val = strtoul(argv[3], &e, 0);
/* strtoul sets an errno for invalid input. If the value
@@ -9044,8 +9049,10 @@ static int cmd_tmp006cal_v0(int idx, int argc, char *argv[])
static int cmd_tmp006cal_v1(int idx, int argc, char *argv[])
{
struct ec_params_tmp006_get_calibration pg;
- struct ec_response_tmp006_get_calibration_v1 *rg = ec_inbuf;
- struct ec_params_tmp006_set_calibration_v1 *ps = ec_outbuf;
+ struct ec_response_tmp006_get_calibration_v1 *rg =
+ (struct ec_response_tmp006_get_calibration_v1 *)(ec_inbuf);
+ struct ec_params_tmp006_set_calibration_v1 *ps =
+ (struct ec_params_tmp006_set_calibration_v1 *)(ec_outbuf);
float val;
char *e;
int i, rv, cmdsize;
@@ -9255,7 +9262,8 @@ int cmd_port80_read(int argc, char *argv[])
writes = rsp.get_info.writes;
history_size = rsp.get_info.history_size;
- history = malloc(history_size*sizeof(uint16_t));
+ history = (uint16_t *)(
+ malloc(history_size * sizeof(uint16_t)));
if (!history) {
fprintf(stderr, "Unable to allocate buffer.\n");
return -1;
@@ -9429,8 +9437,10 @@ static int cmd_pchg_wait_event(int port, uint32_t expected)
static int cmd_pchg_update(int port, uint32_t address, uint32_t version,
const char *filename)
{
- struct ec_params_pchg_update *p = ec_outbuf;
- struct ec_response_pchg_update *r = ec_inbuf;
+ struct ec_params_pchg_update *p =
+ (struct ec_params_pchg_update *)(ec_outbuf);
+ struct ec_response_pchg_update *r =
+ (struct ec_response_pchg_update *)(ec_inbuf);
FILE *fp;
size_t len, total;
int progress = 0;
@@ -9571,7 +9581,8 @@ static int cmd_pchg(int argc, char *argv[])
return cmd_pchg_info(&r);
} else if (argc == 3 && !strcmp(argv[2], "reset")) {
/* Usage.3 */
- struct ec_params_pchg_update *u = ec_outbuf;
+ struct ec_params_pchg_update *u =
+ (struct ec_params_pchg_update *)(ec_outbuf);
u->cmd = EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL;
rv = ec_command(EC_CMD_PCHG_UPDATE, 0, u, sizeof(*u), NULL, 0);
@@ -10184,8 +10195,8 @@ int cmd_tp_frame_get(int argc, char* argv[])
struct ec_response_tp_frame_info* r;
struct ec_params_tp_frame_get p;
- data = malloc(ec_max_insize);
- r = malloc(ec_max_insize);
+ data = (uint8_t *)(malloc(ec_max_insize));
+ r = (struct ec_response_tp_frame_info *)(malloc(ec_max_insize));
if (data == NULL || r == NULL) {
fprintf(stderr, "Couldn't allocate memory.\n");
diff --git a/util/ectool_keyscan.c b/util/ectool_keyscan.c
index 3de28cac11..4f5393157d 100644
--- a/util/ectool_keyscan.c
+++ b/util/ectool_keyscan.c
@@ -78,8 +78,8 @@ static int keyscan_read_fdt_matrix(struct keyscan_info *keyscan,
return -1;
}
keyscan->matrix_count = buf.st_size / 4;
- keyscan->matrix = calloc(keyscan->matrix_count,
- sizeof(*keyscan->matrix));
+ keyscan->matrix = (struct matrix_entry *)(calloc(
+ keyscan->matrix_count, sizeof(*keyscan->matrix)));
if (!keyscan->matrix) {
fprintf(stderr, "Out of memory for key matrix\n");
return -1;
@@ -205,7 +205,7 @@ static int keyscan_add_to_scan(struct keyscan_info *keyscan, char **keysp,
/* Convert keycode to key if needed */
if (keycode == -1) {
- pos = strchr(kbd_plain_xlate, key);
+ pos = (uint8_t *)(strchr((char *)kbd_plain_xlate, key));
if (!pos) {
fprintf(stderr, "Key '%c' not found in xlate table\n",
key);
@@ -267,8 +267,9 @@ static int keyscan_process_keys(struct keyscan_info *keyscan, int linenum,
size = test->item_alloced * sizeof(struct keyscan_test_item);
new_size = size + KEYSCAN_ALLOC_STEP *
- sizeof(struct keyscan_test_item);
- test->items = realloc(test->items, new_size);
+ sizeof(struct keyscan_test_item);
+ test->items = (struct keyscan_test_item *)(realloc(test->items,
+ new_size));
if (!test->items) {
fprintf(stderr, "Out of memory realloc()\n");
return -1;
@@ -335,10 +336,10 @@ static enum keyscan_cmd keyscan_read_cmd(const char *str, int len)
for (i = 0; i < KEYSCAN_CMD_COUNT; i++) {
if (!strncmp(keyscan_cmd_name[i], str, len))
- return i;
+ return (enum keyscan_cmd)(i);
}
- return -1;
+ return (enum keyscan_cmd)(-1);
}
/**
@@ -584,7 +585,7 @@ static int run_test(struct keyscan_info *keyscan, struct keyscan_test *test)
/* Ask EC for results */
size = sizeof(*resp) + test->item_count;
- resp = malloc(size);
+ resp = (struct ec_result_keyscan_seq_ctrl *)(malloc(size));
if (!resp) {
fprintf(stderr, "Out of memory for results\n");
return -1;
diff --git a/util/stm32mon.c b/util/stm32mon.c
index 0e05cf3639..ff72e2f75e 100644
--- a/util/stm32mon.c
+++ b/util/stm32mon.c
@@ -68,7 +68,7 @@
#define CMD_LOOKUP_ENTRY(COMMAND) {CMD_##COMMAND, #COMMAND}
const struct {
- const char cmd;
+ const uint8_t cmd;
const char *name;
} cmd_lookup_table[] = {
CMD_LOOKUP_ENTRY(INIT),
@@ -658,7 +658,10 @@ int send_command(int fd, uint8_t cmd, payload_t *loads, int cnt,
int res, i, c;
payload_t *p;
int readcnt = 0;
- uint8_t cmd_frame[] = { SOF, cmd, 0xff ^ cmd }; /* XOR checksum */
+
+ uint8_t cmd_frame[] = { SOF, cmd,
+ /* XOR checksum */
+ (uint8_t)(0xff ^ cmd) };
/* only the SPI mode needs the Start Of Frame byte */
int cmd_off = mode == MODE_SPI ? 0 : 1;
int count_damaged_ack = 0;
@@ -688,7 +691,7 @@ int send_command(int fd, uint8_t cmd, payload_t *loads, int cnt,
for (p = loads, c = 0; c < cnt; c++, p++) {
uint8_t crc = 0;
int size = p->size;
- uint8_t *data = malloc(size + 1), *data_ptr;
+ uint8_t *data = (uint8_t *)(malloc(size + 1)), *data_ptr;
if (data == NULL) {
fprintf(stderr,
@@ -1017,7 +1020,7 @@ int command_ext_erase(int fd, uint16_t count, uint16_t start)
int i;
/* not a special value : build a list of pages */
load.size = 2 * (count + 1);
- pages = malloc(load.size);
+ pages = (uint16_t *)(malloc(load.size));
if (!pages)
return STM32_ENOMEM;
load.data = (uint8_t *)pages;
@@ -1058,7 +1061,7 @@ int command_erase_i2c(int fd, uint16_t count, uint16_t start)
*/
load_cnt = 2;
load[1].size = 2 * count;
- pages = malloc(load[1].size);
+ pages = (uint16_t *)(malloc(load[1].size));
if (!pages)
return STM32_ENOMEM;
load[1].data = (uint8_t *)pages;
@@ -1092,7 +1095,7 @@ int command_erase(int fd, uint16_t count, uint16_t start)
int i;
/* not a special value : build a list of pages */
load.size = count + 1;
- pages = malloc(load.size);
+ pages = (uint8_t *)(malloc(load.size));
if (!pages)
return STM32_ENOMEM;
load.data = (uint8_t *)pages;
@@ -1258,7 +1261,7 @@ int read_device_signature_register(int fd, const struct stm32_def *chip,
return STM32_EINVAL;
}
- buffer = malloc(read_size_bytes);
+ buffer = (uint8_t *)(malloc(read_size_bytes));
if (!buffer) {
fprintf(stderr, "Cannot allocate %" PRIu32 " bytes\n",
read_size_bytes);
@@ -1365,7 +1368,7 @@ int read_flash(int fd, struct stm32_def *chip, const char *filename,
if (!size)
size = chip->flash_size;
- buffer = malloc(size);
+ buffer = (uint8_t *)(malloc(size));
if (!buffer) {
fprintf(stderr, "Cannot allocate %d bytes\n", size);
return STM32_ENOMEM;
@@ -1398,7 +1401,7 @@ int write_flash(int fd, struct stm32_def *chip, const char *filename,
int res, written;
FILE *hnd;
int size = chip->flash_size;
- uint8_t *buffer = malloc(size);
+ uint8_t *buffer = (uint8_t *)(malloc(size));
if (!buffer) {
fprintf(stderr, "Cannot allocate %d bytes\n", size);
diff --git a/util/uut/main.c b/util/uut/main.c
index e1f9720d9b..146ddc0275 100644
--- a/util/uut/main.c
+++ b/util/uut/main.c
@@ -308,7 +308,7 @@ static uint8_t *read_input_file(uint32_t size, const char *file_name)
uint8_t *buffer;
FILE *input_fp;
- buffer = malloc(size);
+ buffer = (uint8_t *)(malloc(size));
if (!buffer) {
fprintf(stderr, "Cannot allocate %d bytes\n", size);
return NULL;
@@ -454,7 +454,7 @@ int main(int argc, char *argv[])
/* Ensure non-zero size */
if (size == 0)
exit_uart_app(EC_FILE_ERR);
- opr_write_mem(aux_buf, addr, size);
+ opr_write_mem((uint8_t *)(aux_buf), addr, size);
} else {
size = param_get_file_size(file_name);
if (size == 0)
diff --git a/util/uut/opr.c b/util/uut/opr.c
index fc1101c011..2b53cafd54 100644
--- a/util/uut/opr.c
+++ b/util/uut/opr.c
@@ -228,7 +228,7 @@ void opr_write_mem(uint8_t *buffer, uint32_t addr, uint32_t size)
/* Read first token from string */
if (console)
- token = strtok(buffer, seps);
+ token = strtok((char *)(buffer), seps);
size_remain = size;
/* Main write loop */