diff options
author | Tom Hughes <tomhughes@chromium.org> | 2021-04-30 16:24:50 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-09-08 21:39:34 +0000 |
commit | 0d042dc35803a7fbcddcbfc78c16ee253310cb9c (patch) | |
tree | 18fb555c6c841eff0fc88921ff0dfb17ab700871 | |
parent | 29a2e85a526e42606176fe04d369362b78a1db2a (diff) | |
download | chrome-ec-0d042dc35803a7fbcddcbfc78c16ee253310cb9c.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>
(cherry picked from commit e0a4e5ab99a45faa196b3894ade8c375061a7ab6)
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3128743
-rw-r--r-- | common/crc.c | 2 | ||||
-rw-r--r-- | util/comm-dev.c | 8 | ||||
-rw-r--r-- | util/comm-host.c | 2 | ||||
-rw-r--r-- | util/comm-lpc.c | 2 | ||||
-rw-r--r-- | util/comm-servo-spi.c | 11 | ||||
-rw-r--r-- | util/ec_flash.c | 2 | ||||
-rw-r--r-- | util/ectool.c | 37 | ||||
-rw-r--r-- | util/ectool_keyscan.c | 17 | ||||
-rw-r--r-- | util/stm32mon.c | 17 | ||||
-rw-r--r-- | util/uut/main.c | 4 | ||||
-rw-r--r-- | util/uut/opr.c | 2 |
11 files changed, 57 insertions, 47 deletions
diff --git a/common/crc.c b/common/crc.c index 79d405eb13..a715a6d366 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/util/comm-dev.c b/util/comm-dev.c index 33a69f9d6f..e85df349bb 100644 --- a/util/comm-dev.c +++ b/util/comm-dev.c @@ -68,7 +68,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) { @@ -102,7 +102,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; @@ -129,8 +129,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 e459bdfaa8..429befa333 100644 --- a/util/comm-host.c +++ b/util/comm-host.c @@ -57,7 +57,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-lpc.c b/util/comm-lpc.c index 54f16b3ffc..16269f388c 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 93705694e3..2fa6d5943d 100644 --- a/util/ec_flash.c +++ b/util/ec_flash.c @@ -36,7 +36,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 5b004d62dd..0fe73be7ec 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -1054,7 +1054,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, @@ -1073,7 +1073,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; @@ -1086,7 +1086,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; @@ -1121,7 +1121,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); @@ -1394,7 +1395,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); @@ -1579,7 +1580,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; @@ -1610,14 +1611,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; @@ -1628,7 +1630,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; @@ -6059,7 +6061,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)); for (i = 0; i < write_len; i++) { write_buf[i] = strtol(argv[i], &e, 0); if (e && *e) { @@ -6849,7 +6851,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; @@ -7532,8 +7534,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; @@ -7743,7 +7747,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; @@ -8102,8 +8107,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)); rv = ec_command(EC_CMD_TP_FRAME_INFO, 0, NULL, 0, r, ec_max_insize); if (rv < 0) { diff --git a/util/ectool_keyscan.c b/util/ectool_keyscan.c index 46ba221f6e..5822828942 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 665c4b28b2..c0807ce9d8 100644 --- a/util/stm32mon.c +++ b/util/stm32mon.c @@ -412,7 +412,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; @@ -434,7 +437,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, @@ -710,7 +713,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 -ENOMEM; load.data = (uint8_t *)pages; @@ -754,7 +757,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 -ENOMEM; load[1].data = (uint8_t *)pages; @@ -789,7 +792,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 -ENOMEM; load.data = (uint8_t *)pages; @@ -906,7 +909,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 -ENOMEM; @@ -939,7 +942,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 64a84e2725..6218e016f5 100644 --- a/util/uut/main.c +++ b/util/uut/main.c @@ -213,7 +213,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; @@ -341,7 +341,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 27f4c3463d..72eb485953 100644 --- a/util/uut/opr.c +++ b/util/uut/opr.c @@ -193,7 +193,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 */ |