megaraid_init() calls proc_mkdir("megaraid", NULL) but only logs a
warning and continues when it fails. If pci_register_driver()
subsequently fails, the error path unconditionally calls
remove_proc_entry("megaraid", NULL) for a directory that was never
created, triggering a WARN at fs/proc/generic.c:736.
The same issue exists in megaraid_exit(): if proc_mkdir() failed during
init but the module loaded successfully (pci_register_driver succeeded),
module removal unconditionally calls remove_proc_entry("megaraid", NULL).
Guard both remove_proc_entry() calls with a check for
mega_proc_dir_entry being non-NULL, aligned with the check of
`if (!mega_proc_dir_entry)` during megaraid_init() creation stage
Signed-off-by: Ziyi Guo <n7l8m4@u.northwestern.edu>
---
drivers/scsi/megaraid.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index a00622c0c526..ab901ad6c480 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -4589,7 +4589,8 @@ static int __init megaraid_init(void)
error = pci_register_driver(&megaraid_pci_driver);
if (error) {
#ifdef CONFIG_PROC_FS
- remove_proc_entry("megaraid", NULL);
+ if (mega_proc_dir_entry)
+ remove_proc_entry("megaraid", NULL);
#endif
return error;
}
@@ -4619,7 +4620,8 @@ static void __exit megaraid_exit(void)
pci_unregister_driver(&megaraid_pci_driver);
#ifdef CONFIG_PROC_FS
- remove_proc_entry("megaraid", NULL);
+ if (mega_proc_dir_entry)
+ remove_proc_entry("megaraid", NULL);
#endif
}
--
2.34.1