From nobody Sun Dec 28 22:53:12 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60F55C4167B for ; Mon, 4 Dec 2023 18:02:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231209AbjLDSCb (ORCPT ); Mon, 4 Dec 2023 13:02:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230426AbjLDSC3 (ORCPT ); Mon, 4 Dec 2023 13:02:29 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FCF79A for ; Mon, 4 Dec 2023 10:02:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701712954; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ugER1Flx8boWLZORMECd29fL9yUWjUsWmkZBQzd3BUk=; b=dTQXFXTay5P55GzsAtI+fLsevHkG5cj5+nP/5HEsH/gvd186Mdmopic1tUN+8CVjgSb95c xH8qsiwsHn3a8BPTpT5LAeKD7wGmpghWbzs5Vf5R+VHqf54+ybEujhiJqQ0nSnW6Qt4vTs PMAYfkUptsGMeLGo4XsS8iY+P50cPNM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-GFGpfNJZN5q5POYOLc7XrA-1; Mon, 04 Dec 2023 13:02:31 -0500 X-MC-Unique: GFGpfNJZN5q5POYOLc7XrA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 77667831523; Mon, 4 Dec 2023 18:02:30 +0000 (UTC) Received: from prarit.bos.redhat.com (prarit2023-praritguest.khw1.lab.eng.bos.redhat.com [10.16.200.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id E90BA2026D68; Mon, 4 Dec 2023 18:02:29 +0000 (UTC) From: Prarit Bhargava To: linux-kernel@vger.kernel.org Cc: Prarit Bhargava , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "Peter Zijlstra (Intel)" , Wei Liu , Saurabh Sengar , Johan Hovold , Michael Kelley , David Malcolm , David Arcari , Don Zickus Subject: [PATCH] x86/ioapic: io_apic fix null dereference check Date: Mon, 4 Dec 2023 13:02:26 -0500 Message-ID: <20231204180226.383745-1-prarit@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The gcc plugin -fanalyzer [1] tries to detect various patterns of incorrect behaviour. The tool reports arch/x86/kernel/apic/io_apic.c: In function =E2=80=98ioapic_destroy_irqdoma= in=E2=80=99: arch/x86/kernel/apic/io_apic.c:2390:12: warning: check of =E2=80=98ioapics[= idx].irqdomain=E2=80=99 for NULL after already dereferencing it [-Wanalyzer= -deref-before-check] | | 2388 | struct fwnode_handle *fn =3D ioapics[idx].irqdomain->f= wnode; | | ^~ | | | | | (1) pointer =E2=80=98ioapics[idx= ].irqdomain=E2=80=99 is dereferenced here | 2389 | | 2390 | if (ioapics[idx].irqdomain) { | | ~ | | | | | (2) pointer =E2=80=98ioapics[idx].irqdomain=E2=80= =99 is checked for NULL here but it was already dereferenced at (1) | Fix the null dereference check in ioapic_destroy_irqdomain(). [1] https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Static-Analyzer-Options.h= tml Signed-off-by: Prarit Bhargava CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: x86@kernel.org CC: "H. Peter Anvin" CC: "Peter Zijlstra (Intel)" CC: Wei Liu CC: Prarit Bhargava CC: Saurabh Sengar CC: Johan Hovold CC: Michael Kelley CC: David Malcolm CC: David Arcari CC: Don Zickus Signed-off-by: Prarit Bhargava --- arch/x86/kernel/apic/io_apic.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index 00da6cf6b07d..f6f19eee0339 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -2381,14 +2381,14 @@ static int mp_irqdomain_create(int ioapic) static void ioapic_destroy_irqdomain(int idx) { struct ioapic_domain_cfg *cfg =3D &ioapics[idx].irqdomain_cfg; - struct fwnode_handle *fn =3D ioapics[idx].irqdomain->fwnode; =20 - if (ioapics[idx].irqdomain) { - irq_domain_remove(ioapics[idx].irqdomain); - if (!cfg->dev) - irq_domain_free_fwnode(fn); - ioapics[idx].irqdomain =3D NULL; - } + if (!ioapics[idx].irqdomain) + return; + + irq_domain_remove(ioapics[idx].irqdomain); + if (!cfg->dev) + irq_domain_free_fwnode(ioapics[idx].irqdomain->fwnode); + ioapics[idx].irqdomain =3D NULL; } =20 void __init setup_IO_APIC(void) --=20 2.43.0