* [PATCH] mtd: core: fix possible resource leak in init_mtd()
@ 2022-10-24 6:51 Gaosheng Cui
2022-11-07 16:20 ` Miquel Raynal
0 siblings, 1 reply; 2+ messages in thread
From: Gaosheng Cui @ 2022-10-24 6:51 UTC (permalink / raw)
To: miquel.raynal, richard, vigneshr, marek.vasut, jim_baxter,
computersforpeace, Sandeep_Jain, cuigaosheng1
Cc: linux-mtd
I got the error report while inject fault in init_mtd():
sysfs: cannot create duplicate filename '/devices/virtual/bdi/mtd-0'
Call Trace:
<TASK>
dump_stack_lvl+0x67/0x83
sysfs_warn_dup+0x60/0x70
sysfs_create_dir_ns+0x109/0x120
kobject_add_internal+0xce/0x2f0
kobject_add+0x98/0x110
device_add+0x179/0xc00
device_create_groups_vargs+0xf4/0x100
device_create+0x7b/0xb0
bdi_register_va.part.13+0x58/0x2d0
bdi_register+0x9b/0xb0
init_mtd+0x62/0x171 [mtd]
do_one_initcall+0x6c/0x3c0
do_init_module+0x58/0x222
load_module+0x268e/0x27d0
__do_sys_finit_module+0xd5/0x140
do_syscall_64+0x37/0x90
entry_SYSCALL_64_after_hwframe+0x63/0xcd
</TASK>
kobject_add_internal failed for mtd-0 with -EEXIST, don't try to register
things with the same name in the same directory.
Error registering mtd class or bdi: -17
If init_mtdchar() fails in init_mtd(), mtd_bdi will not be unregistered,
as a result, we can't load the mtd module again, to fix this by calling
bdi_unregister(mtd_bdi) after out_procfs label.
Fixes: 445caaa20c4d ("mtd: Allocate bdi objects dynamically")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
drivers/mtd/mtdcore.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 20fcedc3021e..d856892cb9b7 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -2475,6 +2475,7 @@ static int __init init_mtd(void)
out_procfs:
if (proc_mtd)
remove_proc_entry("mtd", NULL);
+ bdi_unregister(mtd_bdi);
bdi_put(mtd_bdi);
err_bdi:
class_unregister(&mtd_class);
--
2.25.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd: core: fix possible resource leak in init_mtd()
2022-10-24 6:51 [PATCH] mtd: core: fix possible resource leak in init_mtd() Gaosheng Cui
@ 2022-11-07 16:20 ` Miquel Raynal
0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2022-11-07 16:20 UTC (permalink / raw)
To: Gaosheng Cui, miquel.raynal, richard, vigneshr, marek.vasut,
jim_baxter, computersforpeace, Sandeep_Jain
Cc: linux-mtd
On Mon, 2022-10-24 at 06:51:09 UTC, Gaosheng Cui wrote:
> I got the error report while inject fault in init_mtd():
>
> sysfs: cannot create duplicate filename '/devices/virtual/bdi/mtd-0'
> Call Trace:
> <TASK>
> dump_stack_lvl+0x67/0x83
> sysfs_warn_dup+0x60/0x70
> sysfs_create_dir_ns+0x109/0x120
> kobject_add_internal+0xce/0x2f0
> kobject_add+0x98/0x110
> device_add+0x179/0xc00
> device_create_groups_vargs+0xf4/0x100
> device_create+0x7b/0xb0
> bdi_register_va.part.13+0x58/0x2d0
> bdi_register+0x9b/0xb0
> init_mtd+0x62/0x171 [mtd]
> do_one_initcall+0x6c/0x3c0
> do_init_module+0x58/0x222
> load_module+0x268e/0x27d0
> __do_sys_finit_module+0xd5/0x140
> do_syscall_64+0x37/0x90
> entry_SYSCALL_64_after_hwframe+0x63/0xcd
> </TASK>
> kobject_add_internal failed for mtd-0 with -EEXIST, don't try to register
> things with the same name in the same directory.
> Error registering mtd class or bdi: -17
>
> If init_mtdchar() fails in init_mtd(), mtd_bdi will not be unregistered,
> as a result, we can't load the mtd module again, to fix this by calling
> bdi_unregister(mtd_bdi) after out_procfs label.
>
> Fixes: 445caaa20c4d ("mtd: Allocate bdi objects dynamically")
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.
Miquel
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-07 16:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-24 6:51 [PATCH] mtd: core: fix possible resource leak in init_mtd() Gaosheng Cui
2022-11-07 16:20 ` Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).