[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b01224ee-c935-4b08-a76f-5dc49341182d@intel.com>
Date: Thu, 20 Mar 2025 17:15:19 -0700
From: Dave Hansen <dave.hansen@...el.com>
To: "Chang S. Bae" <chang.seok.bae@...el.com>, linux-kernel@...r.kernel.org
Cc: x86@...nel.org, tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
dave.hansen@...ux.intel.com, colinmitchell@...gle.com
Subject: Re: [PATCH v2 4/6] x86/microcode/intel: Implement staging handler
On 3/20/25 16:40, Chang S. Bae wrote:
> static void do_stage(u64 mmio_pa)
> {
> - pr_debug_once("Staging implementation is pending.\n");
> - staging.state = UCODE_ERROR;
> + staging.mmio_base = ioremap(mmio_pa, MBOX_REG_NUM * MBOX_REG_SIZE);
> + if (WARN_ON_ONCE(!staging.mmio_base)) {
> + staging.state = UCODE_ERROR;
> + return;
> + }
> +
> + reset_stage();
This is purely a style thing, but I really dislike using global
variables like this.
What is reset_stage() doing? What state is it resetting? What is locking
this? What is its scope?
Now, imagine you have a function variable. It can be on the stack or static:
static void do_stage(u64 mmio_pa)
{
struct staging_state staging = {};
Then you pass it around:
staging.mmio_base = ioremap(mmio_pa, MBOX_REG_NUM * ...
if (WARN_ON_ONCE(!staging.mmio_base)) {
staging.state = UCODE_ERROR;
return;
}
reset_stage(&staging);
Yeah, it means passing around _one_ function argument to a function
that's not currently taking an argument. But it makes it a heck of a lot
more clear what is going on. It also makes the lifetime and
initialization state of 'staging' *MUCH* more obvious.
It also makes it clear what state reset_stage() needs to do its job.
Powered by blists - more mailing lists