Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2884587rdb; Mon, 4 Dec 2023 10:02:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGG4DvXLKMUXaBuAG8ArfOdHWzWtm2CWnhRYF9J9op5aDs4Q68SvCzcHo+wwd7YuJCpV4EW X-Received: by 2002:a17:902:a505:b0:1d0:8122:9007 with SMTP id s5-20020a170902a50500b001d081229007mr1640433plq.18.1701712961295; Mon, 04 Dec 2023 10:02:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701712961; cv=none; d=google.com; s=arc-20160816; b=xRqumhn9SJU75GR1s7y45cVLjC+u+Ce+kg/q/wz4oN5KtPA6A8kSjtd04AFOP0CtAF D4NQ/Oni7w9ATrpfKSb1LvKRWJdfa3qFDaBsirzD4wkdvA+0YnTGQ8Ng7wzq+OJ5GeYR ScHKvTSNA6djeixCFRIBiXq/HAQJHdEAqAL3KpOlm8GyeoGBAFW9bu94Kf5Vd1Vc3Cgw VPJSM3BtMiewEuGy5H/Umdd4IcmbcFUG6pAUOnNN2s4Q8dkyLkOwhV37wCivwtatoWPl V43HaNHXevoliBGs/96tyrxA1VVkyXZXM1Gxz9/jycFYfI6+tImgnfdTO91H0v69FKcC QNHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ugER1Flx8boWLZORMECd29fL9yUWjUsWmkZBQzd3BUk=; fh=PBa9547LGliUUWyVzsBrtK99PGfL99+aRdoyEIZaxI0=; b=ZienbRcKqfWu1qtqQ8xOuSuoIVWg7H0DtW1AbttMzIXIX1OePK6ZFKFs/iWnpE6p3d p4dNp5bDx4WikmlWCBudy388jNrqEowC1ZbByy720Oz6d+EU9/143yDXHEM7/oSBArV+ f7t3azEpZYZ98xLwynwjUzm+QEIiEdH7rVqZnKtDcoUQLdJIiJdFHKs2mo2oi9ynWBnw /eTV9dcHVJPur3XPL/WHasyu9oLCEB82gZSjuAVjZZa84BNvC8PoayMlE3ND2e0oTbOk 2++OFxiEAb68AtWjpDnHAMv/oL+rNF4MXIiuc0ZrQ+qJaFhaWMw8R0ASNaT7X9drpoih /cfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dTQXFXTa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l10-20020a170903244a00b001d06f365722si4469838pls.563.2023.12.04.10.02.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 10:02:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dTQXFXTa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9BA8A80AC599; Mon, 4 Dec 2023 10:02:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230437AbjLDSCa (ORCPT + 99 others); Mon, 4 Dec 2023 13:02:30 -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: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 10:02:39 -0800 (PST) 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 ‘ioapic_destroy_irqdomain’: arch/x86/kernel/apic/io_apic.c:2390:12: warning: check of ‘ioapics[idx].irqdomain’ for NULL after already dereferencing it [-Wanalyzer-deref-before-check] | | 2388 | struct fwnode_handle *fn = ioapics[idx].irqdomain->fwnode; | | ^~ | | | | | (1) pointer ‘ioapics[idx].irqdomain’ is dereferenced here | 2389 | | 2390 | if (ioapics[idx].irqdomain) { | | ~ | | | | | (2) pointer ‘ioapics[idx].irqdomain’ 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.html 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 = &ioapics[idx].irqdomain_cfg; - struct fwnode_handle *fn = ioapics[idx].irqdomain->fwnode; - if (ioapics[idx].irqdomain) { - irq_domain_remove(ioapics[idx].irqdomain); - if (!cfg->dev) - irq_domain_free_fwnode(fn); - ioapics[idx].irqdomain = 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 = NULL; } void __init setup_IO_APIC(void) -- 2.43.0