From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 787457C093; Wed, 21 Feb 2024 14:20:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708525201; cv=none; b=jylYlZ2ubyNZImhrLOxKUTPMmfME821EGOdPcTk+4VSZQaW8OLClWutEOrUPxnYQ7IafWb3nMbYXGMbHzkYopgtP7H/cf0IKV1+q2O22dLOrwuKy3WNbumlBEWbfAyQ3r4q2/adkaf3jppzo/BW1zY3YLjVhJmFx/qkfiNGr3UU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708525201; c=relaxed/simple; bh=6pXTjIiLZldG1VU68QDu98PbiuddL3okW3IxoAIHM4Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JQUlyC3hj27UIchhKncw+SC9C/MIT8XybGcyZlRGt2G7YsQhv7oNfwhvyIFNEFdLuD+Fxu5EWKH5SwY3m4ZlsSOGltxdkWFhlc7Xl0pqaRCeBby+pFCFBOe9rDfhd/q/ASDfzlq2BiQcz2p3n+LntGIuNl68ISSNSB+SkZGgHVs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sDqXylkG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="sDqXylkG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF420C433C7; Wed, 21 Feb 2024 14:20:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708525201; bh=6pXTjIiLZldG1VU68QDu98PbiuddL3okW3IxoAIHM4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sDqXylkG9pzcI6X+RaevZpMAWpWgsvVrZhSAJ7zi8jWABlhSIuu7Lq0/kk8XLqUQj UBxpWbSlgfn6ievNYzRy4w422MOVQQy8JldSfpHen5SFBCsZTIXYPzgWz1mika7/Kr /2lRZt+Rmck7mjkOtqa/skJXnTs0rY1+QSp6mlnY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Prarit Bhargava , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.4 072/267] ACPI: extlog: fix NULL pointer dereference check Date: Wed, 21 Feb 2024 14:06:53 +0100 Message-ID: <20240221125942.242104584@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125940.058369148@linuxfoundation.org> References: <20240221125940.058369148@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Prarit Bhargava [ Upstream commit 72d9b9747e78979510e9aafdd32eb99c7aa30dd1 ] 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 pointer dereference check in extlog_exit(). Link: https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Static-Analyzer-Options.html # [1] Signed-off-by: Prarit Bhargava Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- 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 4c05c3828c9e..5dc91aa0ed61 100644 --- a/drivers/acpi/acpi_extlog.c +++ b/drivers/acpi/acpi_extlog.c @@ -316,9 +316,10 @@ static void __exit extlog_exit(void) { edac_set_report_status(old_edac_report_status); 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); -- 2.43.0