Skip to content

Commit

Permalink
fix GCC's -Wcalloc-transposed-args warning
Browse files Browse the repository at this point in the history
GCC 14.1.0 warns about calls to `calloc()` with element size as the
first argument.
Link: https://gcc.gnu.org/onlinedocs/gcc-14.1.0/gcc/Warning-Options.html#index-Wcalloc-transposed-args

Change-Id: I7d44a74a003ee6ec49d165f91727972478214587
Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8301
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
  • Loading branch information
en-sc authored and borneoa committed Jun 15, 2024
1 parent e4c0904 commit 400cf21
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/flash/nor/ambiqmicro.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ FLASH_BANK_COMMAND_HANDLER(ambiqmicro_flash_bank_command)
if (CMD_ARGC < 6)
return ERROR_COMMAND_SYNTAX_ERROR;

ambiqmicro_info = calloc(sizeof(struct ambiqmicro_flash_bank), 1);
ambiqmicro_info = calloc(1, sizeof(struct ambiqmicro_flash_bank));

bank->driver_priv = ambiqmicro_info;

Expand Down
4 changes: 2 additions & 2 deletions src/flash/nor/at91sam7.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ static int at91sam7_read_part_info(struct flash_bank *bank)
if (bnk > 0) {
if (!t_bank->next) {
/* create a new flash bank element */
struct flash_bank *fb = calloc(sizeof(struct flash_bank), 1);
struct flash_bank *fb = calloc(1, sizeof(struct flash_bank));
if (!fb) {
LOG_ERROR("No memory for flash bank");
return ERROR_FAIL;
Expand Down Expand Up @@ -748,7 +748,7 @@ FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command)
if (bnk > 0) {
if (!t_bank->next) {
/* create a new bank element */
struct flash_bank *fb = calloc(sizeof(struct flash_bank), 1);
struct flash_bank *fb = calloc(1, sizeof(struct flash_bank));
if (!fb) {
LOG_ERROR("No memory for flash bank");
return ERROR_FAIL;
Expand Down
4 changes: 2 additions & 2 deletions src/flash/nor/kinetis.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
k_chip = kinetis_get_chip(target);

if (!k_chip) {
k_chip = calloc(sizeof(struct kinetis_chip), 1);
k_chip = calloc(1, sizeof(struct kinetis_chip));
if (!k_chip) {
LOG_ERROR("No memory");
return ERROR_FAIL;
Expand Down Expand Up @@ -1031,7 +1031,7 @@ static int kinetis_create_missing_banks(struct kinetis_chip *k_chip)
bank_idx - k_chip->num_pflash_blocks);
}

bank = calloc(sizeof(struct flash_bank), 1);
bank = calloc(1, sizeof(struct flash_bank));
if (!bank)
return ERROR_FAIL;

Expand Down
2 changes: 1 addition & 1 deletion src/flash/nor/max32xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ FLASH_BANK_COMMAND_HANDLER(max32xxx_flash_bank_command)
return ERROR_FLASH_BANK_INVALID;
}

info = calloc(sizeof(struct max32xxx_flash_bank), 1);
info = calloc(1, sizeof(struct max32xxx_flash_bank));
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[2], info->flash_size);
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[6], info->flc_base);
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[7], info->sector_size);
Expand Down
2 changes: 1 addition & 1 deletion src/flash/nor/msp432.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ static int msp432_probe(struct flash_bank *bank)

if (is_main && MSP432P4 == msp432_bank->family_type) {
/* Create the info flash bank needed by MSP432P4 variants */
struct flash_bank *info = calloc(sizeof(struct flash_bank), 1);
struct flash_bank *info = calloc(1, sizeof(struct flash_bank));
if (!info)
return ERROR_FAIL;

Expand Down
2 changes: 1 addition & 1 deletion src/flash/nor/stellaris.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ FLASH_BANK_COMMAND_HANDLER(stellaris_flash_bank_command)
if (CMD_ARGC < 6)
return ERROR_COMMAND_SYNTAX_ERROR;

stellaris_info = calloc(sizeof(struct stellaris_flash_bank), 1);
stellaris_info = calloc(1, sizeof(struct stellaris_flash_bank));
bank->base = 0x0;
bank->driver_priv = stellaris_info;

Expand Down
2 changes: 1 addition & 1 deletion src/flash/nor/stm32f2x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ static int stm32x_probe(struct flash_bank *bank)
assert(num_sectors > 0);

bank->num_sectors = num_sectors;
bank->sectors = calloc(sizeof(struct flash_sector), num_sectors);
bank->sectors = calloc(num_sectors, sizeof(struct flash_sector));

if (stm32x_otp_is_f7(bank))
bank->size = STM32F7_OTP_SIZE;
Expand Down
2 changes: 1 addition & 1 deletion src/jtag/drivers/angie.c
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ static int angie_queue_scan(struct angie *device, struct jtag_command *cmd)

/* Allocate TDO buffer if required */
if (type == SCAN_IN || type == SCAN_IO) {
tdo_buffer_start = calloc(sizeof(uint8_t), scan_size_bytes);
tdo_buffer_start = calloc(scan_size_bytes, sizeof(uint8_t));

if (!tdo_buffer_start)
return ERROR_FAIL;
Expand Down
2 changes: 1 addition & 1 deletion src/jtag/drivers/ulink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ static int ulink_queue_scan(struct ulink *device, struct jtag_command *cmd)

/* Allocate TDO buffer if required */
if ((type == SCAN_IN) || (type == SCAN_IO)) {
tdo_buffer_start = calloc(sizeof(uint8_t), scan_size_bytes);
tdo_buffer_start = calloc(scan_size_bytes, sizeof(uint8_t));

if (!tdo_buffer_start)
return ERROR_FAIL;
Expand Down
4 changes: 2 additions & 2 deletions src/target/arc_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ static int arc_jtag_read_registers(struct arc_jtag *jtag_info, uint32_t type,
ARC_JTAG_READ_FROM_CORE_REG : ARC_JTAG_READ_FROM_AUX_REG);
arc_jtag_enque_set_transaction(jtag_info, transaction, TAP_DRPAUSE);

uint8_t *data_buf = calloc(sizeof(uint8_t), count * 4);
uint8_t *data_buf = calloc(count * 4, sizeof(uint8_t));

arc_jtag_enque_register_rw(jtag_info, addr, data_buf, NULL, count);

Expand Down Expand Up @@ -498,7 +498,7 @@ int arc_jtag_read_memory(struct arc_jtag *jtag_info, uint32_t addr,
if (!count)
return ERROR_OK;

data_buf = calloc(sizeof(uint8_t), count * 4);
data_buf = calloc(count * 4, sizeof(uint8_t));
arc_jtag_enque_reset_transaction(jtag_info);

/* We are reading from memory. */
Expand Down

0 comments on commit 400cf21

Please sign in to comment.