mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 07:02:34 +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:
parent
14c916d380
commit
3bd47524c0
@ -162,7 +162,7 @@ int register_spi_bitbang_master(const struct bitbang_spi_master *master, void *s
|
||||
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;
|
||||
|
@ -756,12 +756,12 @@ int probe_flash(struct registered_master *mst, int startchip, struct flashctx *f
|
||||
}
|
||||
|
||||
/* 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)
|
||||
|
2
fmap.c
2
fmap.c
@ -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))
|
||||
return 1;
|
||||
|
||||
fmap = malloc(sizeof(struct fmap));
|
||||
fmap = malloc(sizeof(*fmap));
|
||||
if (!fmap) {
|
||||
msg_gerr("Out of memory.\n");
|
||||
goto _free_ret;
|
||||
|
@ -247,7 +247,7 @@ static int undo_mmio_write(void *p)
|
||||
#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); \
|
||||
|
2
ichspi.c
2
ichspi.c
@ -1731,7 +1731,7 @@ int ich_init_spi(void *spibar, enum ich_chipset ich_gen)
|
||||
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) {
|
||||
|
@ -341,7 +341,7 @@ int it85xx_spi_init(struct superio s)
|
||||
(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;
|
||||
|
@ -411,7 +411,7 @@ static uint16_t it87spi_probe(uint16_t port)
|
||||
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;
|
||||
|
2
layout.c
2
layout.c
@ -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) {
|
||||
msg_gerr("Could not allocate memory");
|
||||
goto error;
|
||||
|
@ -182,7 +182,7 @@ struct flashrom_board_info *flashrom_supported_boards(void)
|
||||
++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) {
|
||||
|
@ -446,7 +446,7 @@ int lspcon_i2c_spi_init(void)
|
||||
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);
|
||||
|
2
pcidev.c
2
pcidev.c
@ -296,7 +296,7 @@ static int undo_pci_write(void *p)
|
||||
#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); \
|
||||
|
@ -292,7 +292,7 @@ static void *physmap_common(const char *descr, uintptr_t phys_addr, size_t len,
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -1579,19 +1579,19 @@ loop_end:
|
||||
(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;
|
||||
|
@ -504,7 +504,7 @@ int realtek_mst_i2c_spi_init(void)
|
||||
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;
|
||||
|
@ -777,7 +777,7 @@ int sb600_probe_spi(struct pci_dev *dev)
|
||||
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;
|
||||
|
2
sfdp.c
2
sfdp.c
@ -300,7 +300,7 @@ int probe_spi_sfdp(struct flashctx *flash)
|
||||
|
||||
/* 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;
|
||||
|
@ -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,
|
||||
struct usb_device **devices)
|
||||
{
|
||||
struct usb_device *copy = malloc(sizeof(struct usb_device));
|
||||
struct usb_device *copy = malloc(sizeof(*copy));
|
||||
|
||||
assert(copy != NULL);
|
||||
|
||||
|
@ -207,7 +207,7 @@ int wbsio_check_for_spi(void)
|
||||
"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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user