Re: [RFC PATCH v2 32/35] ACPI: add support to register CPUs based on the _STA enabled bit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 14, 2023 at 05:13:41PM +0100, Jonathan Cameron wrote:
> On Wed, 13 Sep 2023 16:38:20 +0000
> James Morse <james.morse@xxxxxxx> wrote:
> > +static int acpi_processor_make_enabled(struct acpi_processor *pr)
> > +{
> > +	unsigned long long sta;
> > +	acpi_status status;
> > +	bool present, enabled;
> > +
> > +	if (!acpi_has_method(pr->handle, "_STA"))
> > +		return arch_register_cpu(pr->id);
> > +
> > +	status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta);
> > +	if (ACPI_FAILURE(status))
> > +		return -ENODEV;
> > +
> > +	present = sta & ACPI_STA_DEVICE_PRESENT;
> > +	enabled = sta & ACPI_STA_DEVICE_ENABLED;
> > +
> > +	if (cpu_online(pr->id) && (!present || !enabled)) {
> > +		pr_err_once(FW_BUG "CPU %u is online, but described as not present or disabled!\n", pr->id);
> 
> Why once?  If this for some reason happened on multiple CPUs I think we'd want to know.
> 
> > +		add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
> > +	} else if (!present || !enabled) {
> > +		return -ENODEV;
> > +	}
> 
> I guess you didn't do a nested if here to avoid even longer lines.
> Could flip things around though I don't like this much either as it makes
> the normal good path exit mid way down.
> 
> 	if (present && enabled)
> 		return arch_register_cpu(pr->id);
> 
> 	if (!cpu_online(pr->id))
> 		return -ENODEV;
> 
> 	pr_err...
> 	add_taint(...
> 
> 	return arch_register_cpu(pr->id);
> 
> Ah well. Some code just has to be less than pretty.

How about:

static int acpi_processor_should_register_cpu(struct acpi_processor *pr)
{
	unsigned long long sta;
	acpi_status status;

	if (!acpi_has_method(pr->handle, "_STA"))
		return 0;

	status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta);
	if (ACPI_FAILURE(status))
		return -ENODEV;

	if (sta & ACPI_STA_DEVICE_PRESENT && sta & ACPI_STA_DEVICE_ENABLED)
		return 0;

	if (cpu_online(pr->id)) {
		pr_err_once(FW_BUG
			    "CPU %u is online, but described as not present or disabled!\n",
			    pr->id);

		/* Register the CPU anyway */
		return 0;
	}

	return -ENODEV;
}

static int acpi_processor_make_enabled(struct acpi_processor *pr)
{
	int ret = acpi_processor_should_register_cpu(pr);

	if (ret)
		return ret;

	return arch_register_cpu(pr->id);
}

I would keep the "cpu online but !present and !disabled" as a sub-block
because it makes better reading flow, but instead break the message as
I've indicated above.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!



[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux