public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Denis Benato <denis.benato@linux.dev>
To: linux-kernel@vger.kernel.org
Cc: platform-driver-x86@vger.kernel.org,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Limonciello, Mario" <mario.limonciello@amd.com>,
	"Luke D . Jones" <luke@ljones.dev>,
	"Alok Tiwari" <alok.a.tiwari@oracle.com>,
	"Derek John Clark" <derekjohn.clark@gmail.com>,
	"Mateusz Schyboll" <dragonn@op.pl>,
	porfet828@gmail.com, "Denis Benato" <benato.denis96@gmail.com>,
	"Denis Benato" <denis.benato@linux.dev>
Subject: [PATCH] platform/x86: asus-armoury: do not abort probe on unexpected CPU cores count
Date: Fri, 14 Nov 2025 19:53:37 +0100	[thread overview]
Message-ID: <20251114185337.578959-1-denis.benato@linux.dev> (raw)

Until now the CPU cores count was only available for
Intel hardware, however a few weeks ago an AMD hardware
that provides aforementioned interface appeared on the
market and data read from the interface doesn't
follow the expected format and the driver fails to probe.

Avoid failing on invalid cores count and print out debug information.

Signed-off-by: Denis Benato <denis.benato@linux.dev>
---
 drivers/platform/x86/asus-armoury.c | 34 ++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/asus-armoury.c b/drivers/platform/x86/asus-armoury.c
index 9f67218ecd14..6355ec3e253f 100644
--- a/drivers/platform/x86/asus-armoury.c
+++ b/drivers/platform/x86/asus-armoury.c
@@ -818,10 +818,23 @@ static struct cpu_cores *init_cpu_cores_ctrl(void)
 	cores_p->min_power_cores = CPU_POWR_CORE_COUNT_MIN;
 	cores_p->min_perf_cores = CPU_PERF_CORE_COUNT_MIN;
 
+	if (cores_p->min_perf_cores > cores_p->max_perf_cores) {
+		pr_err("Invalid CPU performance cores count detected: min: %u, max: %u, current: %u\n",
+		       cores_p->min_perf_cores,
+		       cores_p->max_perf_cores,
+		       cores_p->cur_perf_cores
+		);
+		return ERR_PTR(-EINVAL);
+	}
+
 	if ((cores_p->min_perf_cores > cores_p->max_perf_cores) ||
 	    (cores_p->min_power_cores > cores_p->max_power_cores)
 	) {
-		pr_err("Invalid CPU cores count detected: interface is not safe to be used.\n");
+		pr_err("Invalid CPU efficiency cores count detected: min: %u, max: %u, current: %u\n",
+		       cores_p->min_power_cores,
+		       cores_p->max_power_cores,
+		       cores_p->cur_power_cores
+		);
 		return ERR_PTR(-EINVAL);
 	}
 
@@ -841,6 +854,11 @@ static ssize_t cores_value_show(struct kobject *kobj, struct kobj_attribute *att
 {
 	u32 cpu_core_value;
 
+	if (asus_armoury.cpu_cores == NULL) {
+		pr_err("CPU core control interface was not initialized.\n");
+		return -ENODEV;
+	}
+
 	switch (core_value) {
 	case CPU_CORE_DEFAULT:
 	case CPU_CORE_MAX:
@@ -875,6 +893,11 @@ static ssize_t cores_current_value_store(struct kobject *kobj, struct kobj_attri
 	if (result)
 		return result;
 
+	if (asus_armoury.cpu_cores == NULL) {
+		pr_err("CPU core control interface was not initialized.\n");
+		return -ENODEV;
+	}
+
 	scoped_guard(mutex, &asus_armoury.cpu_core_mutex) {
 		if (!asus_armoury.cpu_cores_changeable) {
 			pr_warn("CPU core count change not allowed until reboot\n");
@@ -1389,16 +1412,17 @@ static int __init asus_fw_init(void)
 		return -ENODEV;
 
 	asus_armoury.cpu_cores_changeable = false;
+	asus_armoury.cpu_cores = NULL;
 	if (armoury_has_devstate(ASUS_WMI_DEVID_CORES_MAX)) {
 		cpu_cores_ctrl = init_cpu_cores_ctrl();
 		if (IS_ERR(cpu_cores_ctrl)) {
 			err = PTR_ERR(cpu_cores_ctrl);
 			pr_err("Could not initialise CPU core control: %d\n", err);
-			return err;
+		} else {
+			pr_debug("CPU cores control available.\n");
+			asus_armoury.cpu_cores = cpu_cores_ctrl;
+			asus_armoury.cpu_cores_changeable = true;
 		}
-
-		asus_armoury.cpu_cores = cpu_cores_ctrl;
-		asus_armoury.cpu_cores_changeable = true;
 	}
 
 	init_rog_tunables();
-- 
2.51.2


             reply	other threads:[~2025-11-14 18:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-14 18:53 Denis Benato [this message]
2025-11-14 20:35 ` [PATCH] platform/x86: asus-armoury: do not abort probe on unexpected CPU cores count Mario Limonciello
2025-11-15 13:38   ` Denis Benato
2025-11-17  4:24     ` luke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251114185337.578959-1-denis.benato@linux.dev \
    --to=denis.benato@linux.dev \
    --cc=alok.a.tiwari@oracle.com \
    --cc=benato.denis96@gmail.com \
    --cc=derekjohn.clark@gmail.com \
    --cc=dragonn@op.pl \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luke@ljones.dev \
    --cc=mario.limonciello@amd.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=porfet828@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox