Linux EDAC development
 help / color / mirror / Atom feed
From: Orange Kao <orange@aiven.io>
To: tony.luck@intel.com, qiuxu.zhuo@intel.com
Cc: bp@alien8.de, james.morse@arm.com, orange@kaosy.org,
	linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org,
	mchehab@kernel.org, rric@kernel.org, Orange Kao <orange@aiven.io>
Subject: [PATCH 1/3] EDAC/igen6: Avoid segmentation fault when rmmod
Date: Mon,  4 Nov 2024 12:40:52 +0000	[thread overview]
Message-ID: <20241104124237.124109-2-orange@aiven.io> (raw)
In-Reply-To: <20241104124237.124109-1-orange@aiven.io>

The segmentation fault happens because

During modprobe:
1. In igen6_probe(), igen6_pvt will be allocated with kzalloc()
2. In igen6_register_mci(), mci->pvt_info will point to
   &igen6_pvt->imc[mc]

During rmmod:
1. In mci_release() in edac_mc.c, it will kfree(mci->pvt_info)
2. In igen6_remove(), it will kfree(igen6_pvt);

Fix this issue by setting mci->pvt_info to NULL to avoid the double
kfree.

Fixes: 10590a9d4f23 ("EDAC/igen6: Add EDAC driver for Intel client SoCs using IBECC")
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219360
Signed-off-by: Orange Kao <orange@aiven.io>
---
 drivers/edac/igen6_edac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/edac/igen6_edac.c b/drivers/edac/igen6_edac.c
index 189a2fc29e74..07dacf8c10be 100644
--- a/drivers/edac/igen6_edac.c
+++ b/drivers/edac/igen6_edac.c
@@ -1245,6 +1245,7 @@ static int igen6_register_mci(int mc, u64 mchbar, struct pci_dev *pdev)
 	imc->mci = mci;
 	return 0;
 fail3:
+	mci->pvt_info = NULL;
 	kfree(mci->ctl_name);
 fail2:
 	edac_mc_free(mci);
@@ -1269,6 +1270,7 @@ static void igen6_unregister_mcis(void)
 
 		edac_mc_del_mc(mci->pdev);
 		kfree(mci->ctl_name);
+		mci->pvt_info = NULL;
 		edac_mc_free(mci);
 		iounmap(imc->window);
 	}
-- 
2.47.0


  reply	other threads:[~2024-11-04 12:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-04 12:40 [PATCH 0/3] EDAC/igen6: Avoid segmentation fault and add polling support Orange Kao
2024-11-04 12:40 ` Orange Kao [this message]
2024-11-04 20:16   ` [PATCH 1/3] EDAC/igen6: Avoid segmentation fault when rmmod Luck, Tony
2024-11-04 12:40 ` [PATCH 2/3] EDAC/igen6: Initialize edac_op_state according to the configuration data Orange Kao
2024-11-04 12:40 ` [PATCH 3/3] EDAC/igen6: Add polling support Orange Kao
2024-11-04 17:40   ` Borislav Petkov
2024-11-05  2:35     ` Zhuo, Qiuxu

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=20241104124237.124109-2-orange@aiven.io \
    --to=orange@aiven.io \
    --cc=bp@alien8.de \
    --cc=james.morse@arm.com \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=orange@kaosy.org \
    --cc=qiuxu.zhuo@intel.com \
    --cc=rric@kernel.org \
    --cc=tony.luck@intel.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