fs: nilfs2: fix memory leak in nilfs_sysfs_create_device_group
PATCH 1/1 fs: nilfs2: fix memory leak in nilfs_sysfs_create_device_group
The preivous commit 8fd0c1b0647a ("nilfs2: fix memory leak in nilfs_sysfs_delete_device_group") only handles the memory leak in the nilfs_sysfs_delete_device_group. However, the similar memory leak still occurs in the nilfs_sysfs_create_device_group.
Fix it by adding kobject_del whenkobject_init_and_add succeeds, but one of the following calls fails.
--- fs/nilfs2/sysfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/nilfs2/sysfs.c +4 -1
@@ -995,7 +995,7 @@ int nilfs_sysfs_create_device_group(struct super_block *sb) err =nilfs_sysfs_create_mounted_snapshots_group (nilfs);if (err) - goto cleanup_dev_kobject; + goto delete_dev_kobject; err =nilfs_sysfs_create_checkpoints_group (nilfs);if (err)
@@ -1027,6 +1027,9 @@ int nilfs_sysfs_create_device_group(struct super_block *sb) delete_mounted_snapshots_group:nilfs_sysfs_delete_mounted_snapshots_group (nilfs); +delete_dev_kobject: +kobject_del (&nilfs->ns_dev_kobj); + cleanup_dev_kobject:kobject_put (&nilfs->ns_dev_kobj);kfree (nilfs->ns_dev_subgroups);
Signature · 1 line
2.25.1
Hi Dongliang,
Quoted 9 lines · Dongliang Mu
The preivous commit
8fd0c1b0647a("nilfs2: fix memory leak innilfs_sysfs_delete_device_group") only handles the memory leak in thenilfs_sysfs_delete_device_group. However, the similar memory leak still occurs in thenilfs_sysfs_create_device_group.Fix it by adding
kobject_delwhenkobject_init_and_addsucceeds, but one of the following calls fails.Fixes 8fd0c1b0647a ("nilfs2: fix memory leak in nilfs_sysfs_delete_device_group")
Why Fixes tag points to my commit? This issue was introduced before my patch
Quoted 19 lines
Signed-off-by Dongliang Mu <[email protected]>--- fs/nilfs2/sysfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/nilfs2/sysfs.c +1
-1@@ -995,7 +995,7 @@ int nilfs_sysfs_create_device_group(struct super_block *sb) err =nilfs_sysfs_create_mounted_snapshots_group (nilfs);if (err) - goto cleanup_dev_kobject; + goto delete_dev_kobject; err =nilfs_sysfs_create_checkpoints_group (nilfs);if (err)
fs/nilfs2/sysfs.c int nilfs_sysfs_create_device_group(struct super_block *sb) · line 1035
Quoted 9 lines
fs/nilfs2/sysfs.c +3
-0@@ -1027,6 +1027,9 @@ int nilfs_sysfs_create_device_group(struct super_block *sb) delete_mounted_snapshots_group:nilfs_sysfs_delete_mounted_snapshots_group (nilfs); +delete_dev_kobject: +kobject_del (&nilfs->ns_dev_kobj); + cleanup_dev_kobject:kobject_put (&nilfs->ns_dev_kobj);kfree (nilfs->ns_dev_subgroups);
With regards,
Pavel Skripkin
Ryusuke Konishi
maintainer(added Nanyong Sun to CC)
Hi Dongliang,
Quoted 9 lines · Pavel Skripkin
Hi Dongliang,
Quoted 5 lines · Dongliang Mu
The preivous commit
8fd0c1b0647a("nilfs2: fix memory leak innilfs_sysfs_delete_device_group") only handles the memory leak in thenilfs_sysfs_delete_device_group. However, the similar memory leak still occurs in thenilfs_sysfs_create_device_group.
Quoted 7 lines
Quoted 4 lines
Fix it by adding
kobject_delwhenkobject_init_and_addsucceeds, but one of the following calls fails.Fixes 8fd0c1b0647a ("nilfs2: fix memory leak in nilfs_sysfs_delete_device_group")Why Fixes tag points to my commit? This issue was introduced before my patch
As Pavel pointed out, this patch is independent of his patch. The following one ?
5f5dec07aca7 ("nilfs2: fix memory leak in nilfs_sysfs_create_device_group")
Quoted 4 lines
Quoted 4 lines
Signed-off-by Dongliang Mu <[email protected]>--- fs/nilfs2/sysfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Can you describe what memory leak issue does this patch actually fix ?
It looks like kobject_put() can call __kobject_del() unless circular references exist.
kobject_put() -> kref_put() -> kobject_release() ->kobject_cleanup() -> __kobject_del()
As explained in Documentation/core-api/kobject.rst,
kobject_del() can be used to drop the reference to the parent object, if circular references are constructed.
But, at least, the parent object is NULL in this case. I really want to understand what the real problem is.
Thanks,
Ryusuke Konishi
Quoted 26 lines
Quoted 15 lines
fs/nilfs2/sysfs.c +1
-1@@ -995,7 +995,7 @@ int nilfs_sysfs_create_device_group(struct super_block *sb) err =nilfs_sysfs_create_mounted_snapshots_group (nilfs);if (err) - goto cleanup_dev_kobject; + goto delete_dev_kobject; err =nilfs_sysfs_create_checkpoints_group (nilfs);if (err)fs/nilfs2/sysfs.c int nilfs_sysfs_create_device_group(struct super_block *sb) · line 1035
Quoted 9 lines
fs/nilfs2/sysfs.c +3
-0@@ -1027,6 +1027,9 @@ int nilfs_sysfs_create_device_group(struct super_block *sb) delete_mounted_snapshots_group:nilfs_sysfs_delete_mounted_snapshots_group (nilfs); +delete_dev_kobject: +kobject_del (&nilfs->ns_dev_kobj); + cleanup_dev_kobject:kobject_put (&nilfs->ns_dev_kobj);kfree (nilfs->ns_dev_subgroups);With regards,
Pavel Skripkin