From patchwork Mon Dec 4 18:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Prarit Bhargava X-Patchwork-Id: 173491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2936448vqy; Mon, 4 Dec 2023 10:02:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7u2YwiIn6+wwM+n9+r/W1IU8BTcgdfX4aaRPI2qBkb12PnaiE47BUfX/YV4Gnx6/7aVwe X-Received: by 2002:a05:6a20:9145:b0:18b:e6c7:7c72 with SMTP id x5-20020a056a20914500b0018be6c77c72mr29006902pzc.57.1701712959986; Mon, 04 Dec 2023 10:02:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701712959; cv=none; d=google.com; s=arc-20160816; b=joMMg9PtrKkbmUQyeV6ZT2C+B+tA+N4OKUaSW733EqSaNGl+AuLlllvSl6dC79mUB4 0f7tj2EqC6mO8PmCvs6f0K92qkQ1mN28AsmPy4Gd05kTbfrtSuYj/qgSRPE6r99wfKr+ LcP/vtCF25AjBfpmamgrDs/CP9TVy3Vo5WzJc+b+XryYPFkzneQ7CBBcE8a9lGW6LSoM UThg8kRlhtf6M8iipu7dKyUdoTLuCE7zawBGofH30n0s4Q2m6P3aVfdaqee+gLu2QJuo GXVnc9azxRhYUzRxanBNTsmVUEp3cWkz1SkJV1yf9+VSNBuEyLVL/GO36svp2nxbHS3t 9zKw== 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 Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id x8-20020a63fe48000000b005c5ff4675d8si2214043pgj.734.2023.12.04.10.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 10:02:39 -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 E674D80AB1D0; Mon, 4 Dec 2023 10:02:38 -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 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) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784375368552433438 X-GMAIL-MSGID: 1784375368552433438 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)