mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bramwel Barack <bramwelbarack89@gmail.com>
To: peterz@infradead.org, mingo@redhat.com
Cc: acme@kernel.org, namhyung@kernel.org,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bramwel Barack <bramwelbarack89@gmail.com>
Subject: [PATCH] perf/x86: Fix missing error code in init_hw_perf_events()
Date: Sun, 20 Sep 2026 09:55:10 +0300	[thread overview]
Message-ID: <20260920065510.15362-1-bramwelbarack89@gmail.com> (raw)

In init_hw_perf_events(), a fallback block intentionally clears the
'err' variable to 0 when a vendor PMU driver is missing, allowing the
kernel to fall back to software events safely.

However, further down the initialization path, a second hardware safety
validation check is performed via check_hw_exists(). If this hardware check
fails, the execution control paths jump straight to the 'out_bad_pmu'
cleanup label. Because 'err' was cleared or initialized to 0 earlier, the
function erroneously returns 0 (Success) to the initialization manager,
despite wiping out the PMU configuration structures via memset.

Fix this by explicitly assigning -ENODEV to 'err' before jumping to the
cleanup sequence when check_hw_exists() fails.

Signed-off-by: Bramwel Barack  <bramwelbarack89@gmail.com>
---
 arch/x86/events/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index d1af33d96d0a..81873eda5b17 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2164,9 +2164,10 @@ static int __init init_hw_perf_events(void)
 	pmu_check_apic();
 
 	/* sanity check that the hardware exists or is emulated */
-	if (!check_hw_exists(&pmu, x86_pmu.cntr_mask, x86_pmu.fixed_cntr_mask))
+	if (!check_hw_exists(&pmu, x86_pmu.cntr_mask, x86_pmu.fixed_cntr_mask)) {
+		err = -ENODEV;
 		goto out_bad_pmu;
-
+	}
 	pr_cont("%s PMU driver.\n", x86_pmu.name);
 
 	/* enable userspace RDPMC usage by default */
-- 
2.55.0


                 reply	other threads:[~2026-09-20  6:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260920065510.15362-1-bramwelbarack89@gmail.com \
    --to=bramwelbarack89@gmail.com \
    --cc=acme@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /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

all inboxes | Powered by JetHome®