summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAngel Pons <th3fanbus@gmail.com>2021-06-28 15:36:23 +0200
committerPatrick Georgi <pgeorgi@google.com>2021-07-01 07:35:02 +0000
commit35b99c64e62fd84866dd269a3641b66646f9557f (patch)
tree8a95363becb766da16e47fadbe87ebca9a5fe06e /src
parentc6dab80b1cd8fb35115e9876b79abefb6c4f2d91 (diff)
SMBIOS: Avoid `sizeof` on struct type
Where applicable, use the size of the associated variable. Change-Id: Ibbac2a82893232a6f87182a6a965b84a599d633e Signed-off-by: Angel Pons <th3fanbus@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/55904 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-by: Michał Żygowski <michal.zygowski@3mdeb.com>
Diffstat (limited to 'src')
-rw-r--r--src/arch/x86/smbios.c75
-rw-r--r--src/drivers/elog/elog.c2
-rw-r--r--src/drivers/wifi/generic/smbios.c4
-rw-r--r--src/mainboard/emulation/qemu-i440fx/northbridge.c8
-rw-r--r--src/mainboard/pcengines/apu1/mainboard.c6
-rw-r--r--src/mainboard/pcengines/apu2/mainboard.c6
-rw-r--r--src/mainboard/samsung/lumpy/mainboard.c4
7 files changed, 52 insertions, 53 deletions
diff --git a/src/arch/x86/smbios.c b/src/arch/x86/smbios.c
index b21cf67642..4637dc02fd 100644
--- a/src/arch/x86/smbios.c
+++ b/src/arch/x86/smbios.c
@@ -243,7 +243,7 @@ static int create_smbios_type17_for_dimm(struct dimm_info *dimm,
{
struct smbios_type17 *t = (struct smbios_type17 *)*current;
- memset(t, 0, sizeof(struct smbios_type17));
+ memset(t, 0, sizeof(*t));
t->memory_type = dimm->ddr_type;
if (dimm->configured_speed_mts != 0)
t->clock_speed = dimm->configured_speed_mts;
@@ -318,7 +318,7 @@ static int create_smbios_type17_for_dimm(struct dimm_info *dimm,
t->phys_memory_array_handle = type16_handle;
*handle += 1;
- t->length = sizeof(struct smbios_type17) - 2;
+ t->length = sizeof(*t) - 2;
return t->length + smbios_string_table_len(t->eos);
}
@@ -380,9 +380,9 @@ static const char *get_bios_version(void)
static int smbios_write_type0(unsigned long *current, int handle)
{
struct smbios_type0 *t = (struct smbios_type0 *)*current;
- int len = sizeof(struct smbios_type0);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type0));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_BIOS_INFORMATION;
t->handle = handle;
t->length = len - 2;
@@ -512,9 +512,9 @@ static size_t get_number_of_caches(struct cpuid_result res_deterministic_cache)
static int smbios_write_type1(unsigned long *current, int handle)
{
struct smbios_type1 *t = (struct smbios_type1 *)*current;
- int len = sizeof(struct smbios_type1);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type1));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_SYSTEM_INFORMATION;
t->handle = handle;
t->length = len - 2;
@@ -535,9 +535,9 @@ static int smbios_write_type1(unsigned long *current, int handle)
static int smbios_write_type2(unsigned long *current, int handle, const int chassis_handle)
{
struct smbios_type2 *t = (struct smbios_type2 *)*current;
- int len = sizeof(struct smbios_type2);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type2));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_BOARD_INFORMATION;
t->handle = handle;
t->length = len - 2;
@@ -559,9 +559,9 @@ static int smbios_write_type2(unsigned long *current, int handle, const int chas
static int smbios_write_type3(unsigned long *current, int handle)
{
struct smbios_type3 *t = (struct smbios_type3 *)*current;
- int len = sizeof(struct smbios_type3);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type3));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_SYSTEM_ENCLOSURE;
t->handle = handle;
t->length = len - 2;
@@ -585,7 +585,7 @@ static int smbios_write_type4(unsigned long *current, int handle)
unsigned int cpu_voltage;
struct cpuid_result res;
struct smbios_type4 *t = (struct smbios_type4 *)*current;
- int len = sizeof(struct smbios_type4);
+ int len = sizeof(*t);
uint16_t characteristics = 0;
static unsigned int cnt = 0;
char buf[8];
@@ -597,7 +597,7 @@ static int smbios_write_type4(unsigned long *current, int handle)
if (cpu_have_cpuid())
res = cpuid(1);
- memset(t, 0, sizeof(struct smbios_type4));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_PROCESSOR_INFORMATION;
t->handle = handle;
t->length = len - 2;
@@ -698,10 +698,10 @@ static int smbios_write_type7(unsigned long *current,
const size_t cache_size)
{
struct smbios_type7 *t = (struct smbios_type7 *)*current;
- int len = sizeof(struct smbios_type7);
+ int len = sizeof(*t);
char buf[8];
- memset(t, 0, sizeof(struct smbios_type7));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_CACHE_INFORMATION;
t->handle = handle;
t->length = len - 2;
@@ -906,10 +906,10 @@ int smbios_write_type8(unsigned long *current, int *handle,
for (i = 0; i < num_ports; i++, port++) {
struct smbios_type8 *t = (struct smbios_type8 *)*current;
- memset(t, 0, sizeof(struct smbios_type8));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_PORT_CONNECTOR_INFORMATION;
t->handle = *handle;
- t->length = sizeof(struct smbios_type8) - 2;
+ t->length = sizeof(*t) - 2;
t->internal_reference_designator =
smbios_add_string(t->eos, port->internal_reference_designator);
t->internal_connector_type = port->internal_connector_type;
@@ -932,9 +932,9 @@ int smbios_write_type9(unsigned long *current, int *handle,
const u16 id, u8 slot_char1, u8 slot_char2, u8 bus, u8 dev_func)
{
struct smbios_type9 *t = (struct smbios_type9 *)*current;
- int len = sizeof(struct smbios_type9);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type9));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_SYSTEM_SLOTS;
t->handle = *handle;
t->length = len - 2;
@@ -1075,10 +1075,10 @@ static int smbios_write_type19(unsigned long *current, int *handle, int type16)
if (meminfo == NULL)
return 0; /* can't find mem info in cbmem */
- memset(t, 0, sizeof(struct smbios_type19));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_MEMORY_ARRAY_MAPPED_ADDRESS;
- t->length = sizeof(struct smbios_type19) - 2;
+ t->length = sizeof(*t) - 2;
t->handle = *handle;
t->memory_array_handle = type16;
@@ -1118,9 +1118,9 @@ static int smbios_write_type19(unsigned long *current, int *handle, int type16)
static int smbios_write_type32(unsigned long *current, int handle)
{
struct smbios_type32 *t = (struct smbios_type32 *)*current;
- int len = sizeof(struct smbios_type32);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type32));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_SYSTEM_BOOT_INFORMATION;
t->handle = handle;
t->length = len - 2;
@@ -1135,9 +1135,9 @@ int smbios_write_type38(unsigned long *current, int *handle,
const u8 irq)
{
struct smbios_type38 *t = (struct smbios_type38 *)*current;
- int len = sizeof(struct smbios_type38);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type38));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_IPMI_DEVICE_INFORMATION;
t->handle = *handle;
t->length = len - 2;
@@ -1160,9 +1160,9 @@ int smbios_write_type41(unsigned long *current, int *handle,
u8 bus, u8 device, u8 function, u8 device_type)
{
struct smbios_type41 *t = (struct smbios_type41 *)*current;
- int len = sizeof(struct smbios_type41);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type41));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_ONBOARD_DEVICES_EXTENDED_INFORMATION;
t->handle = *handle;
t->length = len - 2;
@@ -1184,9 +1184,9 @@ int smbios_write_type41(unsigned long *current, int *handle,
static int smbios_write_type127(unsigned long *current, int handle)
{
struct smbios_type127 *t = (struct smbios_type127 *)*current;
- int len = sizeof(struct smbios_type127);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type127));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_END_OF_TABLE;
t->handle = handle;
t->length = len - 2;
@@ -1306,11 +1306,11 @@ unsigned long smbios_write_tables(unsigned long current)
printk(BIOS_DEBUG, "%s: %08lx\n", __func__, current);
se = (struct smbios_entry *)current;
- current += sizeof(struct smbios_entry);
+ current += sizeof(*se);
current = ALIGN_UP(current, 16);
se3 = (struct smbios_entry30 *)current;
- current += sizeof(struct smbios_entry30);
+ current += sizeof(*se3);
current = ALIGN_UP(current, 16);
tables = current;
@@ -1342,9 +1342,9 @@ unsigned long smbios_write_tables(unsigned long current)
update_max(len, max_struct_size, smbios_write_type127(&current, handle++));
/* Install SMBIOS 2.1 entry point */
- memset(se, 0, sizeof(struct smbios_entry));
+ memset(se, 0, sizeof(*se));
memcpy(se->anchor, "_SM_", 4);
- se->length = sizeof(struct smbios_entry);
+ se->length = sizeof(*se);
se->major_version = 3;
se->minor_version = 0;
se->max_struct_size = max_struct_size;
@@ -1354,21 +1354,20 @@ unsigned long smbios_write_tables(unsigned long current)
se->struct_table_address = (u32)tables;
se->struct_table_length = len;
- se->intermediate_checksum = smbios_checksum((u8 *)se + 0x10,
- sizeof(struct smbios_entry) - 0x10);
- se->checksum = smbios_checksum((u8 *)se, sizeof(struct smbios_entry));
+ se->intermediate_checksum = smbios_checksum((u8 *)se + 0x10, sizeof(*se) - 0x10);
+ se->checksum = smbios_checksum((u8 *)se, sizeof(*se));
/* Install SMBIOS 3.0 entry point */
- memset(se3, 0, sizeof(struct smbios_entry30));
+ memset(se3, 0, sizeof(*se3));
memcpy(se3->anchor, "_SM3_", 5);
- se3->length = sizeof(struct smbios_entry30);
+ se3->length = sizeof(*se3);
se3->major_version = 3;
se3->minor_version = 0;
se3->struct_table_address = (u64)tables;
se3->struct_table_length = len;
- se3->checksum = smbios_checksum((u8 *)se3, sizeof(struct smbios_entry30));
+ se3->checksum = smbios_checksum((u8 *)se3, sizeof(*se3));
return current;
}
diff --git a/src/drivers/elog/elog.c b/src/drivers/elog/elog.c
index 4769559ca0..6e31686fe5 100644
--- a/src/drivers/elog/elog.c
+++ b/src/drivers/elog/elog.c
@@ -594,7 +594,7 @@ static inline u8 *elog_flash_offset_to_address(void)
int elog_smbios_write_type15(unsigned long *current, int handle)
{
struct smbios_type15 *t = (struct smbios_type15 *)*current;
- int len = sizeof(struct smbios_type15);
+ int len = sizeof(*t);
uintptr_t log_address;
size_t elog_size = region_device_sz(&elog_state.nv_dev);
diff --git a/src/drivers/wifi/generic/smbios.c b/src/drivers/wifi/generic/smbios.c
index a1a8e4f204..b8191161bb 100644
--- a/src/drivers/wifi/generic/smbios.c
+++ b/src/drivers/wifi/generic/smbios.c
@@ -18,9 +18,9 @@ static int smbios_write_intel_wifi(struct device *dev, int *handle, unsigned lon
} __packed;
struct smbios_type_intel_wifi *t = (struct smbios_type_intel_wifi *)*current;
- int len = sizeof(struct smbios_type_intel_wifi);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type_intel_wifi));
+ memset(t, 0, sizeof(*t));
t->type = 0x85;
t->length = len - 2;
t->handle = *handle;
diff --git a/src/mainboard/emulation/qemu-i440fx/northbridge.c b/src/mainboard/emulation/qemu-i440fx/northbridge.c
index 8579b8f886..01d036a6a0 100644
--- a/src/mainboard/emulation/qemu-i440fx/northbridge.c
+++ b/src/mainboard/emulation/qemu-i440fx/northbridge.c
@@ -166,9 +166,9 @@ static void cpu_pci_domain_read_resources(struct device *dev)
static int qemu_get_smbios_data16(int handle, unsigned long *current)
{
struct smbios_type16 *t = (struct smbios_type16 *)*current;
- int len = sizeof(struct smbios_type16);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type16));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_PHYS_MEMORY_ARRAY;
t->handle = handle;
t->length = len - 2;
@@ -185,11 +185,11 @@ static int qemu_get_smbios_data17(int handle, int parent_handle, unsigned long *
struct smbios_type17 *t = (struct smbios_type17 *)*current;
int len;
- memset(t, 0, sizeof(struct smbios_type17));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_MEMORY_DEVICE;
t->handle = handle;
t->phys_memory_array_handle = parent_handle;
- t->length = sizeof(struct smbios_type17) - 2;
+ t->length = sizeof(*t) - 2;
t->size = qemu_get_memory_size() / 1024;
t->data_width = 64;
t->total_width = 64;
diff --git a/src/mainboard/pcengines/apu1/mainboard.c b/src/mainboard/pcengines/apu1/mainboard.c
index cb5d4fba8d..05c496dc57 100644
--- a/src/mainboard/pcengines/apu1/mainboard.c
+++ b/src/mainboard/pcengines/apu1/mainboard.c
@@ -173,7 +173,7 @@ static int mainboard_smbios_type16(DMI_INFO *agesa_dmi, int *handle, unsigned lo
int len;
t = (struct smbios_type16 *)*current;
- len = sizeof(struct smbios_type16);
+ len = sizeof(*t);
memset(t, 0, len);
max_capacity = get_spd_offset() ? 4 : 2; /* 4GB or 2GB variant */
@@ -199,10 +199,10 @@ static int mainboard_smbios_type17(DMI_INFO *agesa_dmi, int *handle, unsigned lo
int len;
t = (struct smbios_type17 *)*current;
- memset(t, 0, sizeof(struct smbios_type17));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_MEMORY_DEVICE;
- t->length = sizeof(struct smbios_type17) - 2;
+ t->length = sizeof(*t) - 2;
t->handle = *handle + 1;
t->phys_memory_array_handle = *handle;
t->memory_error_information_handle = 0xfffe;
diff --git a/src/mainboard/pcengines/apu2/mainboard.c b/src/mainboard/pcengines/apu2/mainboard.c
index 56976e53c5..bcf2536237 100644
--- a/src/mainboard/pcengines/apu2/mainboard.c
+++ b/src/mainboard/pcengines/apu2/mainboard.c
@@ -155,7 +155,7 @@ static int mainboard_smbios_type16(DMI_INFO *agesa_dmi, int *handle,
int len = 0;
t = (struct smbios_type16 *)*current;
- len = sizeof(struct smbios_type16);
+ len = sizeof(*t);
memset(t, 0, len);
max_capacity = get_spd_offset() ? 4 : 2; /* 4GB or 2GB variant */
@@ -182,10 +182,10 @@ static int mainboard_smbios_type17(DMI_INFO *agesa_dmi, int *handle,
int len;
t = (struct smbios_type17 *)*current;
- memset(t, 0, sizeof(struct smbios_type17));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_MEMORY_DEVICE;
- t->length = sizeof(struct smbios_type17) - 2;
+ t->length = sizeof(*t) - 2;
t->handle = *handle + 1;
t->phys_memory_array_handle = *handle;
t->memory_error_information_handle = 0xfffe;
diff --git a/src/mainboard/samsung/lumpy/mainboard.c b/src/mainboard/samsung/lumpy/mainboard.c
index cdeaf72de0..c2899b8e25 100644
--- a/src/mainboard/samsung/lumpy/mainboard.c
+++ b/src/mainboard/samsung/lumpy/mainboard.c
@@ -29,9 +29,9 @@ static int lumpy_smbios_type41_irq(int *handle, unsigned long *current,
const char *name, u8 irq, u8 addr)
{
struct smbios_type41 *t = (struct smbios_type41 *)*current;
- int len = sizeof(struct smbios_type41);
+ int len = sizeof(*t);
- memset(t, 0, sizeof(struct smbios_type41));
+ memset(t, 0, sizeof(*t));
t->type = SMBIOS_ONBOARD_DEVICES_EXTENDED_INFORMATION;
t->handle = *handle;
t->length = len - 2;