arch/x86/acpi_bert_storage.c: Fix array size calculation

The naming of the parameters was quite confusing which caused them to be
used incorrectly. For example the cper_ia32x64_ctx_sz_bytype function
was given the register size in bytes, but it sill multiplied it by 8,
thinking that it got the number of registers instead.

Fix the parameter names to make it more obvious what is the number of
register array entries and what is the actual size in bytes of the
array.

Change-Id: I17a0fadba57ee8ede996eead4cdfb20f1ab3031e
Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/90477
Reviewed-by: Matt DeVillier <matt.devillier@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Maximilian Brune 2025-08-27 20:23:10 +02:00 committed by Matt DeVillier
commit a3236ef110
3 changed files with 13 additions and 10 deletions

View file

@ -324,14 +324,14 @@ acpi_hest_generic_data_v300_t *bert_append_genproc(
* CPER_IA32X64_CTX_32BIT_DBG
* CPER_IA32X64_CTX_64BIT_DBG
* CPER_IA32X64_CTX_MEMMAPPED
* num is the number of bytes eventually used to fill the context's register
* array_size_bytes is the size (in bytes) eventually used to fill the context's register
* array, e.g. 4 MSRs * sizeof(msr_t)
*
* status and entry data_length values are updated.
*/
cper_ia32x64_context_t *new_cper_ia32x64_ctx(
acpi_generic_error_status_t *status,
cper_ia32x64_proc_error_section_t *x86err, int type, int num)
cper_ia32x64_proc_error_section_t *x86err, int type, int array_size_bytes)
{
size_t size;
cper_ia32x64_context_t *ctx;
@ -355,7 +355,7 @@ cper_ia32x64_context_t *new_cper_ia32x64_ctx(
return NULL;
}
size = cper_ia32x64_ctx_sz_bytype(type, num);
size = cper_ia32x64_ctx_sz_bytype(type, array_size_bytes);
ctx = bert_allocate_storage(size);
if (!ctx) {
printk(BIOS_ERR, "New IA32X64 %s context entry would exceed available region\n",
@ -366,7 +366,7 @@ cper_ia32x64_context_t *new_cper_ia32x64_ctx(
revise_error_sizes(status, size);
ctx->type = type;
ctx->array_size = num;
ctx->array_size = array_size_bytes;
cper_bump_ia32x64_ctx_count(x86err);
return ctx;
@ -553,13 +553,16 @@ cper_ia32x64_context_t *cper_new_ia32x64_context_msr(
int i;
msr_t *dest;
ctx = new_cper_ia32x64_ctx(status, x86err, CPER_IA32X64_CTX_MSR, num);
ctx = new_cper_ia32x64_ctx(status, x86err, CPER_IA32X64_CTX_MSR, num * sizeof(msr_t));
if (!ctx)
return NULL;
/* already filled ctx->type = CPER_IA32X64_CTX_MSR; */
/*
* already filled:
* - ctx->type = CPER_IA32X64_CTX_MSR
* - ctx->array_size = num * sizeof(msr_t)
*/
ctx->msr_addr = addr;
ctx->array_size = num * sizeof(msr_t);
dest = (msr_t *)((u8 *)(ctx + 1)); /* point to the Register Array */

View file

@ -91,7 +91,7 @@ static inline acpi_hest_generic_data_v300_t *acpi_hest_generic_data3(
/* Add a context to an existing IA32/X64-type error entry */
cper_ia32x64_context_t *new_cper_ia32x64_ctx(
acpi_generic_error_status_t *status,
cper_ia32x64_proc_error_section_t *x86err, int type, int num);
cper_ia32x64_proc_error_section_t *x86err, int type, int array_size);
/* Helper to add an MSR context to an existing IA32/X64-type error entry */
cper_ia32x64_context_t *cper_new_ia32x64_context_msr(

View file

@ -459,7 +459,7 @@ static inline cper_timestamp_t cper_timestamp(int precise)
* CPER_IA32X64_CTX_MEMMAPPED
* num is the number of items in the context's register array
*/
static inline size_t cper_ia32x64_ctx_sz_bytype(int type, int arr_num)
static inline size_t cper_ia32x64_ctx_sz_bytype(int type, int array_size)
{
size_t sz = sizeof(cper_ia32x64_context_t);
@ -476,7 +476,7 @@ static inline size_t cper_ia32x64_ctx_sz_bytype(int type, int arr_num)
case CPER_IA32X64_CTX_MEMMAPPED:
default:
/* Table N.13: "size ... is determined by (Array Size / 8)" */
return ALIGN_UP(sz + arr_num * 8, 16);
return ALIGN_UP(sz + array_size, 16);
}
}