Message ID | 20231204180037.383583-1-prarit@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2935021vqy; Mon, 4 Dec 2023 10:00:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwaLXsp3LgPw9BLUFZB+VH+BnvZvZMwRbTE04qjCVpOVqHlvTTyVj2TPVpJBOJHEapRTHg X-Received: by 2002:a17:902:d50c:b0:1d0:45c6:1cc1 with SMTP id b12-20020a170902d50c00b001d045c61cc1mr191350plg.27.1701712858535; Mon, 04 Dec 2023 10:00:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701712858; cv=none; d=google.com; s=arc-20160816; b=g9yqZWv50E61IpAL6BmspjWJYd9agtZhZPc+Gc74k/rCCl4zMTsEXVn+rmBf3HXoTZ S/zp08NS9/9TUJAzQAQqv0WmqRDS8Ag3ce7mUmLhiCcvMFJMNjp3OD1mnPEeJJMKdsog malbyKuFwcQWGJTvsbI+HcfyPWgjzyBgO10WLApHzYaL88UPpSjhAYUKFtdzrSYCAqmI sCMg4jNGN5R0XTkbmB9GYPr11ZifeHVWDcdtdTKGzv4rqhM+CYGdRc0Fejx777m0Bzov 0qujFi2QQPAUc9b6aMlN05WX2gX4leFtMyKXzEbPKx2Pxxhtql0JMHX9Jv/IDqnR1nAW dIbg== 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=S9ftojeH8GGZxU2oVCZDZDYHm92xZtIBjJ5gEF2G+Rc=; fh=EuOa1FFvYpQtDCNaMFfozOduRY/AaXGeCTl8m1mhJa8=; b=xdBH8t9iTlpEsBf0Gii+TM0OrwA2pMdWrvUzKcW/IIRqdlwzr0gnladF8v+59Vu+p4 FEmW5JiiPsg7SvtZ4jmhXD9D1XFPbzG0CBvE5dYPnjVf4W1WzShxZLRuohfHNoKkvL3y oHPKN9KoHkgUHZKV59fiKnslAMVGcIskaf/V2cKtDnrDuJexzhD69zwqu4niGFYwdrV5 bFHA0qr6mMpMkeP3fpXYFtlpl/tkkT3x5+UmdpUMhmRMEYk0Cw7+06xTavSOrhw8jJoH 68V72TArxnHo2d7YN6DjYxjcuoyoxBaVZ7Loqi6rfP0GRbVBv9ZLRkCmbkwOlje0+bsF fpNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hAYblu4w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id g4-20020a170902868400b001d0050e2452si7890768plo.45.2023.12.04.10.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 10:00:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hAYblu4w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 421C38057E2B; Mon, 4 Dec 2023 10:00:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231396AbjLDSAo (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Mon, 4 Dec 2023 13:00:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229659AbjLDSAn (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 4 Dec 2023 13:00:43 -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 BF5A99A for <linux-kernel@vger.kernel.org>; Mon, 4 Dec 2023 10:00:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701712848; 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=S9ftojeH8GGZxU2oVCZDZDYHm92xZtIBjJ5gEF2G+Rc=; b=hAYblu4wmkWdUhCFppM5TquJqOH3E7Cyq/5JtgIy+O7J3EovIJkFWRNTNUAqojaHks6dPk 3SnbQBMncx0LUXoomQo8jGkcRnieejIaJ9ZpUd8GtsJdhtFpWD/iHQS10vhVkzXPxxvJZQ 8MAtNZZKXTcDhjOi0m7QICXs9jB5P44= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-97-NcIh8DP8O3qx75jVIOIb1g-1; Mon, 04 Dec 2023 13:00:44 -0500 X-MC-Unique: NcIh8DP8O3qx75jVIOIb1g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 6D0A138116E1; Mon, 4 Dec 2023 18:00:43 +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 3B2C1C1596F; Mon, 4 Dec 2023 18:00:43 +0000 (UTC) From: Prarit Bhargava <prarit@redhat.com> To: linux-kernel@vger.kernel.org Cc: Prarit Bhargava <prarit@redhat.com>, "Rafael J. Wysocki" <rafael@kernel.org>, Len Brown <lenb@kernel.org>, linux-acpi@vger.kernel.org Subject: [PATCH] ACPI: extlog fix null dereference check Date: Mon, 4 Dec 2023 13:00:37 -0500 Message-ID: <20231204180037.383583-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.8 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 10:00:53 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784375262201335354 X-GMAIL-MSGID: 1784375262201335354 |
Series |
ACPI: extlog fix null dereference check
|
|
Commit Message
Prarit Bhargava
Dec. 4, 2023, 6 p.m. UTC
The gcc plugin -fanalyzer [1] tries to detect various
patterns of incorrect behaviour. The tool reports
drivers/acpi/acpi_extlog.c: In function ‘extlog_exit’:
drivers/acpi/acpi_extlog.c:307:12: warning: check of ‘extlog_l1_addr’ for NULL after already dereferencing it [-Wanalyzer-deref-before-check]
|
| 306 | ((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN;
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
| | |
| | (1) pointer ‘extlog_l1_addr’ is dereferenced here
| 307 | if (extlog_l1_addr)
| | ~
| | |
| | (2) pointer ‘extlog_l1_addr’ is checked for NULL here but it was already dereferenced at (1)
|
Fix the null dereference check in extlog_exit().
[1] https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Static-Analyzer-Options.html
CC: "Rafael J. Wysocki" <rafael@kernel.org>
CC: Len Brown <lenb@kernel.org>
CC: linux-acpi@vger.kernel.org
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
---
drivers/acpi/acpi_extlog.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
Top posting and just adding a few interested parties ... On 12/4/23 13:00, Prarit Bhargava wrote: > The gcc plugin -fanalyzer [1] tries to detect various > patterns of incorrect behaviour. The tool reports > > drivers/acpi/acpi_extlog.c: In function ‘extlog_exit’: > drivers/acpi/acpi_extlog.c:307:12: warning: check of ‘extlog_l1_addr’ for NULL after already dereferencing it [-Wanalyzer-deref-before-check] > | > | 306 | ((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN; > | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ > | | | > | | (1) pointer ‘extlog_l1_addr’ is dereferenced here > | 307 | if (extlog_l1_addr) > | | ~ > | | | > | | (2) pointer ‘extlog_l1_addr’ is checked for NULL here but it was already dereferenced at (1) > | > > Fix the null dereference check in extlog_exit(). > > [1] https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Static-Analyzer-Options.html > > CC: "Rafael J. Wysocki" <rafael@kernel.org> > CC: Len Brown <lenb@kernel.org> > CC: linux-acpi@vger.kernel.org > Signed-off-by: Prarit Bhargava <prarit@redhat.com> > --- > drivers/acpi/acpi_extlog.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/acpi/acpi_extlog.c b/drivers/acpi/acpi_extlog.c > index e120a96e1eae..193147769146 100644 > --- a/drivers/acpi/acpi_extlog.c > +++ b/drivers/acpi/acpi_extlog.c > @@ -303,9 +303,10 @@ static int __init extlog_init(void) > static void __exit extlog_exit(void) > { > mce_unregister_decode_chain(&extlog_mce_dec); > - ((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN; > - if (extlog_l1_addr) > + if (extlog_l1_addr) { > + ((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN; > acpi_os_unmap_iomem(extlog_l1_addr, l1_size); > + } > if (elog_addr) > acpi_os_unmap_iomem(elog_addr, elog_size); > release_mem_region(elog_base, elog_size);
On Mon, Dec 4, 2023 at 7:00 PM Prarit Bhargava <prarit@redhat.com> wrote: > > The gcc plugin -fanalyzer [1] tries to detect various > patterns of incorrect behaviour. The tool reports > > drivers/acpi/acpi_extlog.c: In function ‘extlog_exit’: > drivers/acpi/acpi_extlog.c:307:12: warning: check of ‘extlog_l1_addr’ for NULL after already dereferencing it [-Wanalyzer-deref-before-check] > | > | 306 | ((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN; > | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ > | | | > | | (1) pointer ‘extlog_l1_addr’ is dereferenced here > | 307 | if (extlog_l1_addr) > | | ~ > | | | > | | (2) pointer ‘extlog_l1_addr’ is checked for NULL here but it was already dereferenced at (1) > | > > Fix the null dereference check in extlog_exit(). > > [1] https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Static-Analyzer-Options.html > > CC: "Rafael J. Wysocki" <rafael@kernel.org> > CC: Len Brown <lenb@kernel.org> > CC: linux-acpi@vger.kernel.org > Signed-off-by: Prarit Bhargava <prarit@redhat.com> > --- > drivers/acpi/acpi_extlog.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/acpi/acpi_extlog.c b/drivers/acpi/acpi_extlog.c > index e120a96e1eae..193147769146 100644 > --- a/drivers/acpi/acpi_extlog.c > +++ b/drivers/acpi/acpi_extlog.c > @@ -303,9 +303,10 @@ static int __init extlog_init(void) > static void __exit extlog_exit(void) > { > mce_unregister_decode_chain(&extlog_mce_dec); > - ((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN; > - if (extlog_l1_addr) > + if (extlog_l1_addr) { > + ((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN; > acpi_os_unmap_iomem(extlog_l1_addr, l1_size); > + } > if (elog_addr) > acpi_os_unmap_iomem(elog_addr, elog_size); > release_mem_region(elog_base, elog_size); > -- Applied as 6.8 material with minor edits in the subject and changelog, thanks!
diff --git a/drivers/acpi/acpi_extlog.c b/drivers/acpi/acpi_extlog.c index e120a96e1eae..193147769146 100644 --- a/drivers/acpi/acpi_extlog.c +++ b/drivers/acpi/acpi_extlog.c @@ -303,9 +303,10 @@ static int __init extlog_init(void) static void __exit extlog_exit(void) { mce_unregister_decode_chain(&extlog_mce_dec); - ((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN; - if (extlog_l1_addr) + if (extlog_l1_addr) { + ((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN; acpi_os_unmap_iomem(extlog_l1_addr, l1_size); + } if (elog_addr) acpi_os_unmap_iomem(elog_addr, elog_size); release_mem_region(elog_base, elog_size);