diff mbox series

[1/3] EDAC/igen6: Avoid segmentation fault when rmmod

Message ID 20241104124237.124109-2-orange@aiven.io (mailing list archive)
State New
Headers show
Series EDAC/igen6: Avoid segmentation fault and add polling support | expand

Commit Message

Orange Kao Nov. 4, 2024, 12:40 p.m. UTC
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(+)

Comments

Tony Luck Nov. 4, 2024, 8:16 p.m. UTC | #1
> 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>

I've applied this patch to the ras tree. Thanks.

Patches 2 & 3 are on hold waiting for an answer to Boris' question
on whether polling mode can be applied automatically on systems
that need it. Rather than pushing the burden onto the user to use the
module parameter to select it.

-Tony
diff mbox series

Patch

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);
 	}