public inbox for linux-edac@vger.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-edac@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Borislav Petkov <bp@alien8.de>, James Morse <james.morse@arm.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Robert Richter <rric@kernel.org>, Tony Luck <tony.luck@intel.com>,
	Yazen Ghannam <yazen.ghannam@amd.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	cocci@inria.fr, Muralidhara M K <muralidhara.mk@amd.com>
Subject: [PATCH 1/7] EDAC/amd64: Improve error handling in amd64_edac_init()
Date: Mon, 25 Dec 2023 18:34:29 +0100	[thread overview]
Message-ID: <4bc19468-2d48-44cd-aaad-610e720c5449@web.de> (raw)
In-Reply-To: <8c9e2c01-9ed0-4392-af40-4e8eb393cb67@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 25 Dec 2023 16:21:34 +0100

The kfree() function was called in one case by the
amd64_edac_init() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

1. Return directly after a call of the function “kcalloc” failed.

2. Move an error code assignment into an if branch.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/edac/amd64_edac.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 537b9987a431..f912cbadefa4 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -4414,14 +4414,15 @@ static int __init amd64_edac_init(void)

 	opstate_init();

-	err = -ENOMEM;
 	ecc_stngs = kcalloc(amd_nb_num(), sizeof(ecc_stngs[0]), GFP_KERNEL);
 	if (!ecc_stngs)
-		goto err_free;
+		return -ENOMEM;

 	msrs = msrs_alloc();
-	if (!msrs)
+	if (!msrs) {
+		err = -ENOMEM;
 		goto err_free;
+	}

 	for (i = 0; i < amd_nb_num(); i++) {
 		err = probe_one_instance(i);
--
2.43.0


  reply	other threads:[~2023-12-25 17:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-25 17:32 [PATCH 0/7] EDAC/amd64: Adjustments for two function implementations Markus Elfring
2023-12-25 17:34 ` Markus Elfring [this message]
2023-12-25 17:36 ` [PATCH 2/7] EDAC/amd64: Delete an unnecessary variable initialisation in amd64_edac_init() Markus Elfring
2023-12-25 17:38 ` [PATCH 3/7] EDAC/amd64: Merge two if statements into one " Markus Elfring
2023-12-25 17:40 ` [PATCH 4/7] EDAC/amd64: Adjust error handling in probe_one_instance() Markus Elfring
2023-12-25 17:42 ` [PATCH 5/7] EDAC/amd64: Improve two size determinations " Markus Elfring
2023-12-25 17:44 ` [PATCH 6/7] EDAC/amd64: Delete an unnecessary variable initialisation " Markus Elfring
2023-12-25 17:46 ` [PATCH 7/7] EDAC/amd64: Move an assignment for the variable “F3” " Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4bc19468-2d48-44cd-aaad-610e720c5449@web.de \
    --to=markus.elfring@web.de \
    --cc=bp@alien8.de \
    --cc=cocci@inria.fr \
    --cc=james.morse@arm.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=muralidhara.mk@amd.com \
    --cc=rric@kernel.org \
    --cc=tony.luck@intel.com \
    --cc=yazen.ghannam@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox