Nico Huber has submitted this change. ( https://review.coreboot.org/c/flashrom/+/55266 )
Change subject: treewide: Drop most cases of `sizeof(struct ...)` ......................................................................
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 --- M bitbang_spi.c M flashrom.c M fmap.c M hwaccess.c M ichspi.c M it85spi.c M it87spi.c M layout.c M libflashrom.c M lspcon_i2c_spi.c M pcidev.c M physmap.c M raiden_debug_spi.c M realtek_mst_i2c_spi.c M sb600spi.c M sfdp.c M usb_device.c M wbsio_spi.c 18 files changed, 21 insertions(+), 21 deletions(-)
Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, approved Edward O'Callaghan: Looks good to me, approved
diff --git a/bitbang_spi.c b/bitbang_spi.c index e941910..3d973c5 100644 --- a/bitbang_spi.c +++ b/bitbang_spi.c @@ -162,7 +162,7 @@ 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; if (spi_data) data->spi_data = spi_data; diff --git a/flashrom.c b/flashrom.c index f5a39b8..cd2e9a7 100644 --- a/flashrom.c +++ b/flashrom.c @@ -756,12 +756,12 @@ }
/* Start filling in the dynamic data. */ - flash->chip = calloc(1, sizeof(struct flashchip)); + flash->chip = calloc(1, sizeof(*flash->chip)); if (!flash->chip) { msg_gerr("Out of memory!\n"); exit(1); } - memcpy(flash->chip, chip, sizeof(struct flashchip)); + memcpy(flash->chip, chip, sizeof(*flash->chip)); flash->mst = mst;
if (map_flash(flash) != 0) diff --git a/fmap.c b/fmap.c index 2f34a5c..b18cbf7 100644 --- a/fmap.c +++ b/fmap.c @@ -195,7 +195,7 @@ if (prepare_flash_access(flashctx, true, false, false, false)) return 1;
- fmap = malloc(sizeof(struct fmap)); + fmap = malloc(sizeof(*fmap)); if (!fmap) { msg_gerr("Out of memory.\n"); goto _free_ret; diff --git a/hwaccess.c b/hwaccess.c index 48ccb34..3a9ca57 100644 --- a/hwaccess.c +++ b/hwaccess.c @@ -247,7 +247,7 @@ #define register_undo_mmio_write(a, c) \ { \ 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) { \ msg_gerr("Out of memory!\n"); \ exit(1); \ diff --git a/ichspi.c b/ichspi.c index 80fcff5..20dac1b 100644 --- a/ichspi.c +++ b/ichspi.c @@ -1731,7 +1731,7 @@ ich_generation = ich_gen; ich_spibar = spibar;
- memset(&desc, 0x00, sizeof(struct ich_descriptors)); + memset(&desc, 0x00, sizeof(desc));
/* Moving registers / bits */ switch (ich_gen) { diff --git a/it85spi.c b/it85spi.c index 810f062..9812fc7 100644 --- a/it85spi.c +++ b/it85spi.c @@ -341,7 +341,7 @@ (unsigned int)base); #endif
- data = calloc(1, sizeof(struct it85spi_data)); + data = calloc(1, sizeof(*data)); if (!data) { msg_perr("Unable to allocate space for extra SPI master data.\n"); return SPI_GENERIC_ERROR; diff --git a/it87spi.c b/it87spi.c index 92c95fa..cbf830b 100644 --- a/it87spi.c +++ b/it87spi.c @@ -411,7 +411,7 @@ free(param); 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) { msg_perr("Unable to allocate space for extra SPI master data.\n"); return SPI_GENERIC_ERROR; diff --git a/layout.c b/layout.c index 4d1dd56..cd6b458 100644 --- a/layout.c +++ b/layout.c @@ -135,7 +135,7 @@ } }
- tmp = malloc(sizeof(struct layout_include_args)); + tmp = malloc(sizeof(*tmp)); if (tmp == NULL) { msg_gerr("Could not allocate memory"); goto error; diff --git a/libflashrom.c b/libflashrom.c index 09a4e4d..d0296d0 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -182,7 +182,7 @@ ++boards_known_size;
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) { for (; i < boards_known_size; ++i) { diff --git a/lspcon_i2c_spi.c b/lspcon_i2c_spi.c index 7f5e3ef..9a66b31 100644 --- a/lspcon_i2c_spi.c +++ b/lspcon_i2c_spi.c @@ -446,7 +446,7 @@ 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) { msg_perr("Unable to allocate space for extra SPI master data.\n"); i2c_close(fd); diff --git a/pcidev.c b/pcidev.c index 892f7b1..9ffe05c 100644 --- a/pcidev.c +++ b/pcidev.c @@ -296,7 +296,7 @@ #define register_undo_pci_write(a, b, c) \ { \ 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) { \ msg_gerr("Out of memory!\n"); \ exit(1); \ diff --git a/physmap.c b/physmap.c index 72d5899..6c36814 100644 --- a/physmap.c +++ b/physmap.c @@ -292,7 +292,7 @@ }
if (autocleanup) { - struct undo_physmap_data *d = malloc(sizeof(struct undo_physmap_data)); + struct undo_physmap_data *d = malloc(sizeof(*d)); if (d == NULL) { msg_perr("%s: Out of memory!\n", __func__); physunmap_unaligned(virt_addr, len); diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c index f67bbe5..950b8af 100644 --- a/raiden_debug_spi.c +++ b/raiden_debug_spi.c @@ -1579,19 +1579,19 @@ (request_enable == RAIDEN_DEBUG_SPI_REQ_ENABLE_EC)) 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) { msg_perr("Unable to allocate space for SPI master.\n"); 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) { free(spi_config); msg_perr("Unable to allocate space for extra SPI master data.\n"); 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->in_ep = in_endpoint; diff --git a/realtek_mst_i2c_spi.c b/realtek_mst_i2c_spi.c index 95c017f..91c8aa5 100644 --- a/realtek_mst_i2c_spi.c +++ b/realtek_mst_i2c_spi.c @@ -504,7 +504,7 @@ 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) { msg_perr("Unable to allocate space for extra SPI master data.\n"); return SPI_GENERIC_ERROR; diff --git a/sb600spi.c b/sb600spi.c index c057947..c4b25e5 100644 --- a/sb600spi.c +++ b/sb600spi.c @@ -777,7 +777,7 @@ if (handle_imc(dev, amd_gen) != 0) return ERROR_FATAL;
- struct sb600spi_data *data = calloc(1, sizeof(struct sb600spi_data)); + struct sb600spi_data *data = calloc(1, sizeof(*data)); if (!data) { msg_perr("Unable to allocate space for extra SPI master data.\n"); return SPI_GENERIC_ERROR; diff --git a/sfdp.c b/sfdp.c index 97f5620..530588f 100644 --- a/sfdp.c +++ b/sfdp.c @@ -300,7 +300,7 @@
/* Fetch all parameter headers, even if we don't use them all (yet). */ 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 ) { msg_gerr("Out of memory!\n"); goto cleanup_hdrs; diff --git a/usb_device.c b/usb_device.c index 5a468dd..a4f6d12 100644 --- a/usb_device.c +++ b/usb_device.c @@ -99,7 +99,7 @@ static void add_device(struct usb_device *device, struct usb_device **devices) { - struct usb_device *copy = malloc(sizeof(struct usb_device)); + struct usb_device *copy = malloc(sizeof(*copy));
assert(copy != NULL);
diff --git a/wbsio_spi.c b/wbsio_spi.c index d17d49d..c3814aa 100644 --- a/wbsio_spi.c +++ b/wbsio_spi.c @@ -207,7 +207,7 @@ "1024 kB!\n", __func__); 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) { msg_perr("Unable to allocate space for extra SPI master data.\n"); return SPI_GENERIC_ERROR;