1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00

treewide: Drop most cases of sizeof(struct ...)

Spelling out the struct type name hurts readability and introduces
opportunities for bugs to happen when the pointer variable type is
changed but the corresponding sizeof is (are) not.

TEST=`make CONFIG_EVERYTHING=yes CONFIG_JLINK_SPI=no VERSION=none -j`
with and without this patch; the flashrom executable does not change.

Change-Id: Icc0b60ca6ef9f5ece6ed2a0e03600bb6ccd7dcc6
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/55266
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
This commit is contained in:
Angel Pons 2021-06-07 12:33:53 +02:00 committed by Nico Huber
parent 14c916d380
commit 3bd47524c0
18 changed files with 21 additions and 21 deletions

View File

@ -162,7 +162,7 @@ int register_spi_bitbang_master(const struct bitbang_spi_master *master, void *s
return ERROR_FLASHROM_BUG; return ERROR_FLASHROM_BUG;
} }
struct bitbang_spi_master_data *data = calloc(1, sizeof(struct bitbang_spi_master_data)); struct bitbang_spi_master_data *data = calloc(1, sizeof(*data));
data->master = master; data->master = master;
if (spi_data) if (spi_data)
data->spi_data = spi_data; data->spi_data = spi_data;

View File

@ -756,12 +756,12 @@ int probe_flash(struct registered_master *mst, int startchip, struct flashctx *f
} }
/* Start filling in the dynamic data. */ /* Start filling in the dynamic data. */
flash->chip = calloc(1, sizeof(struct flashchip)); flash->chip = calloc(1, sizeof(*flash->chip));
if (!flash->chip) { if (!flash->chip) {
msg_gerr("Out of memory!\n"); msg_gerr("Out of memory!\n");
exit(1); exit(1);
} }
memcpy(flash->chip, chip, sizeof(struct flashchip)); memcpy(flash->chip, chip, sizeof(*flash->chip));
flash->mst = mst; flash->mst = mst;
if (map_flash(flash) != 0) if (map_flash(flash) != 0)

2
fmap.c
View File

@ -195,7 +195,7 @@ static int fmap_bsearch_rom(struct fmap **fmap_out, struct flashctx *const flash
if (prepare_flash_access(flashctx, true, false, false, false)) if (prepare_flash_access(flashctx, true, false, false, false))
return 1; return 1;
fmap = malloc(sizeof(struct fmap)); fmap = malloc(sizeof(*fmap));
if (!fmap) { if (!fmap) {
msg_gerr("Out of memory.\n"); msg_gerr("Out of memory.\n");
goto _free_ret; goto _free_ret;

View File

@ -247,7 +247,7 @@ static int undo_mmio_write(void *p)
#define register_undo_mmio_write(a, c) \ #define register_undo_mmio_write(a, c) \
{ \ { \
struct undo_mmio_write_data *undo_mmio_write_data; \ struct undo_mmio_write_data *undo_mmio_write_data; \
undo_mmio_write_data = malloc(sizeof(struct undo_mmio_write_data)); \ undo_mmio_write_data = malloc(sizeof(*undo_mmio_write_data)); \
if (!undo_mmio_write_data) { \ if (!undo_mmio_write_data) { \
msg_gerr("Out of memory!\n"); \ msg_gerr("Out of memory!\n"); \
exit(1); \ exit(1); \

View File

@ -1731,7 +1731,7 @@ int ich_init_spi(void *spibar, enum ich_chipset ich_gen)
ich_generation = ich_gen; ich_generation = ich_gen;
ich_spibar = spibar; ich_spibar = spibar;
memset(&desc, 0x00, sizeof(struct ich_descriptors)); memset(&desc, 0x00, sizeof(desc));
/* Moving registers / bits */ /* Moving registers / bits */
switch (ich_gen) { switch (ich_gen) {

View File

@ -341,7 +341,7 @@ int it85xx_spi_init(struct superio s)
(unsigned int)base); (unsigned int)base);
#endif #endif
data = calloc(1, sizeof(struct it85spi_data)); data = calloc(1, sizeof(*data));
if (!data) { if (!data) {
msg_perr("Unable to allocate space for extra SPI master data.\n"); msg_perr("Unable to allocate space for extra SPI master data.\n");
return SPI_GENERIC_ERROR; return SPI_GENERIC_ERROR;

View File

@ -411,7 +411,7 @@ static uint16_t it87spi_probe(uint16_t port)
free(param); free(param);
exit_conf_mode_ite(port); exit_conf_mode_ite(port);
struct it8716f_spi_data *data = calloc(1, sizeof(struct it8716f_spi_data)); struct it8716f_spi_data *data = calloc(1, sizeof(*data));
if (!data) { if (!data) {
msg_perr("Unable to allocate space for extra SPI master data.\n"); msg_perr("Unable to allocate space for extra SPI master data.\n");
return SPI_GENERIC_ERROR; return SPI_GENERIC_ERROR;

View File

@ -135,7 +135,7 @@ int register_include_arg(struct layout_include_args **args, const char *arg)
} }
} }
tmp = malloc(sizeof(struct layout_include_args)); tmp = malloc(sizeof(*tmp));
if (tmp == NULL) { if (tmp == NULL) {
msg_gerr("Could not allocate memory"); msg_gerr("Could not allocate memory");
goto error; goto error;

View File

@ -182,7 +182,7 @@ struct flashrom_board_info *flashrom_supported_boards(void)
++boards_known_size; ++boards_known_size;
struct flashrom_board_info *supported_boards = struct flashrom_board_info *supported_boards =
malloc(boards_known_size * sizeof(struct flashrom_board_info)); malloc(boards_known_size * sizeof(*supported_boards));
if (supported_boards != NULL) { if (supported_boards != NULL) {
for (; i < boards_known_size; ++i) { for (; i < boards_known_size; ++i) {

View File

@ -446,7 +446,7 @@ int lspcon_i2c_spi_init(void)
return ret; return ret;
} }
struct lspcon_i2c_spi_data *data = calloc(1, sizeof(struct lspcon_i2c_spi_data)); struct lspcon_i2c_spi_data *data = calloc(1, sizeof(*data));
if (!data) { if (!data) {
msg_perr("Unable to allocate space for extra SPI master data.\n"); msg_perr("Unable to allocate space for extra SPI master data.\n");
i2c_close(fd); i2c_close(fd);

View File

@ -296,7 +296,7 @@ static int undo_pci_write(void *p)
#define register_undo_pci_write(a, b, c) \ #define register_undo_pci_write(a, b, c) \
{ \ { \
struct undo_pci_write_data *undo_pci_write_data; \ struct undo_pci_write_data *undo_pci_write_data; \
undo_pci_write_data = malloc(sizeof(struct undo_pci_write_data)); \ undo_pci_write_data = malloc(sizeof(*undo_pci_write_data)); \
if (!undo_pci_write_data) { \ if (!undo_pci_write_data) { \
msg_gerr("Out of memory!\n"); \ msg_gerr("Out of memory!\n"); \
exit(1); \ exit(1); \

View File

@ -292,7 +292,7 @@ static void *physmap_common(const char *descr, uintptr_t phys_addr, size_t len,
} }
if (autocleanup) { if (autocleanup) {
struct undo_physmap_data *d = malloc(sizeof(struct undo_physmap_data)); struct undo_physmap_data *d = malloc(sizeof(*d));
if (d == NULL) { if (d == NULL) {
msg_perr("%s: Out of memory!\n", __func__); msg_perr("%s: Out of memory!\n", __func__);
physunmap_unaligned(virt_addr, len); physunmap_unaligned(virt_addr, len);

View File

@ -1579,19 +1579,19 @@ loop_end:
(request_enable == RAIDEN_DEBUG_SPI_REQ_ENABLE_EC)) (request_enable == RAIDEN_DEBUG_SPI_REQ_ENABLE_EC))
usleep(50 * 1000); usleep(50 * 1000);
struct spi_master *spi_config = calloc(1, sizeof(struct spi_master)); struct spi_master *spi_config = calloc(1, sizeof(*spi_config));
if (!spi_config) { if (!spi_config) {
msg_perr("Unable to allocate space for SPI master.\n"); msg_perr("Unable to allocate space for SPI master.\n");
return SPI_GENERIC_ERROR; return SPI_GENERIC_ERROR;
} }
struct raiden_debug_spi_data *data = calloc(1, sizeof(struct raiden_debug_spi_data)); struct raiden_debug_spi_data *data = calloc(1, sizeof(*data));
if (!data) { if (!data) {
free(spi_config); free(spi_config);
msg_perr("Unable to allocate space for extra SPI master data.\n"); msg_perr("Unable to allocate space for extra SPI master data.\n");
return SPI_GENERIC_ERROR; return SPI_GENERIC_ERROR;
} }
memcpy(spi_config, &spi_master_raiden_debug, sizeof(struct spi_master)); memcpy(spi_config, &spi_master_raiden_debug, sizeof(*spi_config));
data->dev = device; data->dev = device;
data->in_ep = in_endpoint; data->in_ep = in_endpoint;

View File

@ -504,7 +504,7 @@ int realtek_mst_i2c_spi_init(void)
return ret; return ret;
} }
struct realtek_mst_i2c_spi_data *data = calloc(1, sizeof(struct realtek_mst_i2c_spi_data)); struct realtek_mst_i2c_spi_data *data = calloc(1, sizeof(*data));
if (!data) { if (!data) {
msg_perr("Unable to allocate space for extra SPI master data.\n"); msg_perr("Unable to allocate space for extra SPI master data.\n");
return SPI_GENERIC_ERROR; return SPI_GENERIC_ERROR;

View File

@ -777,7 +777,7 @@ int sb600_probe_spi(struct pci_dev *dev)
if (handle_imc(dev, amd_gen) != 0) if (handle_imc(dev, amd_gen) != 0)
return ERROR_FATAL; return ERROR_FATAL;
struct sb600spi_data *data = calloc(1, sizeof(struct sb600spi_data)); struct sb600spi_data *data = calloc(1, sizeof(*data));
if (!data) { if (!data) {
msg_perr("Unable to allocate space for extra SPI master data.\n"); msg_perr("Unable to allocate space for extra SPI master data.\n");
return SPI_GENERIC_ERROR; return SPI_GENERIC_ERROR;

2
sfdp.c
View File

@ -300,7 +300,7 @@ int probe_spi_sfdp(struct flashctx *flash)
/* Fetch all parameter headers, even if we don't use them all (yet). */ /* Fetch all parameter headers, even if we don't use them all (yet). */
hbuf = malloc((nph + 1) * 8); hbuf = malloc((nph + 1) * 8);
hdrs = malloc((nph + 1) * sizeof(struct sfdp_tbl_hdr)); hdrs = malloc((nph + 1) * sizeof(*hdrs));
if (hbuf == NULL || hdrs == NULL ) { if (hbuf == NULL || hdrs == NULL ) {
msg_gerr("Out of memory!\n"); msg_gerr("Out of memory!\n");
goto cleanup_hdrs; goto cleanup_hdrs;

View File

@ -99,7 +99,7 @@ static int check_match(struct usb_match_value const *match_value, int value)
static void add_device(struct usb_device *device, static void add_device(struct usb_device *device,
struct usb_device **devices) struct usb_device **devices)
{ {
struct usb_device *copy = malloc(sizeof(struct usb_device)); struct usb_device *copy = malloc(sizeof(*copy));
assert(copy != NULL); assert(copy != NULL);

View File

@ -207,7 +207,7 @@ int wbsio_check_for_spi(void)
"1024 kB!\n", __func__); "1024 kB!\n", __func__);
max_rom_decode.spi = 1024 * 1024; max_rom_decode.spi = 1024 * 1024;
struct wbsio_spi_data * data = calloc(1, sizeof(struct wbsio_spi_data)); struct wbsio_spi_data *data = calloc(1, sizeof(*data));
if (!data) { if (!data) {
msg_perr("Unable to allocate space for extra SPI master data.\n"); msg_perr("Unable to allocate space for extra SPI master data.\n");
return SPI_GENERIC_ERROR; return SPI_GENERIC_ERROR;