gfs2: Fix error path kobject memory leak
PATCH 1/1 gfs2: Fix error path kobject memory leak
If a call to kobject_init_and_add() fails we must call kobject_put() otherwise we leak memory.
Function always calls kobject_init_and_add() which always calls kobject_init().
It is safe to leave object destruction up to the kobject release function and never free it manually.
Remove call to kfree() and always call kobject_put() in the error path.
---
Is it ok to send patches during the merge window?
Applies on top of Linus' mainline tag: v5.1
Happy to rebase if there are conflicts.
thanks,
Tobin.
fs/gfs2/sys.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
fs/gfs2/sys.c +1 -6
@@ -661,8 +661,6 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)if (error) goto fail_reg; - sysfs_frees_sdp =1 ;/* Freeing sdp is now done by sysfs calling -function gfs2_sbd_release. */ error =sysfs_create_group (&sdp->sd_kobj, &tune_group);if (error) goto fail_reg;
@@ -687,10 +685,7 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp) fail_reg:free_percpu (sdp->sd_lkstats);fs_err (sdp,"error %d adding sysfs files\n" , error); -if (sysfs_frees_sdp) -kobject_put (&sdp->sd_kobj); -else -kfree (sdp); +kobject_put (&sdp->sd_kobj); sb->s_fs_info =NULL ;return error; }
Signature · 1 line
2.21.0
Quoted 31 lines · Tobin C. Harding
If a call to
kobject_init_and_add()fails we must callkobject_put()otherwise we leak memory.Function always calls
kobject_init_and_add()which always callskobject_init().It is safe to leave object destruction up to the kobject release function and never free it manually.
Remove call to
kfree()and always callkobject_put()in the error path.Signed-off-by Tobin C. Harding <[email protected]>---
Is it ok to send patches during the merge window?
Applies on top of Linus' mainline tag: v5.1
Happy to rebase if there are conflicts.
thanks,
Tobin.fs/gfs2/sys.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)fs/gfs2/sys.c +0
-0
fs/gfs2/sys.c int gfs2_sys_fs_add(struct gfs2_sbd *sdp) · line 665
Quoted 5 lines
fs/gfs2/sys.c +0
-2@@ -661,8 +661,6 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)if (error) goto fail_reg; - sysfs_frees_sdp =1 ;/* Freeing sdp is now done by sysfs calling -function gfs2_sbd_release. */
You should also delete this variable at the top of the function, as it is now only set once there and never used.
With that:
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · Tobin C. Harding
If a call to
kobject_init_and_add()fails we must callkobject_put()otherwise we leak memory.Function always calls
kobject_init_and_add()which always callskobject_init().It is safe to leave object destruction up to the kobject release function and never free it manually.
Remove call to
kfree()and always callkobject_put()in the error path.Signed-off-by Tobin C. Harding <[email protected]>---
Is it ok to send patches during the merge window?
Applies on top of Linus' mainline tag: v5.1
Happy to rebase if there are conflicts.
thanks,
Tobin.fs/gfs2/sys.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)fs/gfs2/sys.c +0
-0@@ -661,8 +661,6 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)if (error) goto fail_reg;
Quoted 5 lines
fs/gfs2/sys.c int gfs2_sys_fs_add(struct gfs2_sbd *sdp) · line 665
Quoted 2 lines
fs/gfs2/sys.c +0
-2- sysfs_frees_sdp =1 ;/* Freeing sdp is now done by sysfs calling -function gfs2_sbd_release. */ You should also delete this variable at the top of the function, as it is now only set once there and never used.
Thanks, I should have gotten a compiler warning for that. I was feeling so confident with my builds this morning ... pays not to get too cocky I suppose.
Quoted 3 lines
With that:
Reviewed-by Greg Kroah-Hartman <[email protected]>
Thanks, will re-spin.
Tobin.
Andreas Gruenbacher
maintainerQuoted 47 lines · Tobin C. Harding
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · Tobin C. Harding
If a call to
kobject_init_and_add()fails we must callkobject_put()otherwise we leak memory.Function always calls
kobject_init_and_add()which always callskobject_init().It is safe to leave object destruction up to the kobject release function and never free it manually.
Remove call to
kfree()and always callkobject_put()in the error path.Signed-off-by Tobin C. Harding <[email protected]>---
Is it ok to send patches during the merge window?
Applies on top of Linus' mainline tag: v5.1
Happy to rebase if there are conflicts.
thanks,
Tobin.fs/gfs2/sys.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)fs/gfs2/sys.c +0
-0@@ -661,8 +661,6 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)if (error) goto fail_reg;Quoted 5 lines
fs/gfs2/sys.c int gfs2_sys_fs_add(struct gfs2_sbd *sdp) · line 665
Quoted 2 lines
fs/gfs2/sys.c +0
-2- sysfs_frees_sdp =1 ;/* Freeing sdp is now done by sysfs calling -function gfs2_sbd_release. */ You should also delete this variable at the top of the function, as it is now only set once there and never used.
Thanks, I should have gotten a compiler warning for that. I was feeling so confident with my builds this morning ... pays not to get too cocky I suppose.
Quoted 5 lines
Quoted 3 lines
With that:
Reviewed-by Greg Kroah-Hartman <[email protected]>Thanks, will re-spin.
Don't bother, I'll fix that up.
Thanks,
Andreas
Quoted 48 lines · Andreas Gruenbacher
Quoted 47 lines · Tobin C. Harding
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · Tobin C. Harding
If a call to
kobject_init_and_add()fails we must callkobject_put()otherwise we leak memory.Function always calls
kobject_init_and_add()which always callskobject_init().It is safe to leave object destruction up to the kobject release function and never free it manually.
Remove call to
kfree()and always callkobject_put()in the error path.Signed-off-by Tobin C. Harding <[email protected]>---
Is it ok to send patches during the merge window?
Applies on top of Linus' mainline tag: v5.1
Happy to rebase if there are conflicts.
thanks,
Tobin.fs/gfs2/sys.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)fs/gfs2/sys.c +0
-0@@ -661,8 +661,6 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)if (error) goto fail_reg;Quoted 5 lines
fs/gfs2/sys.c int gfs2_sys_fs_add(struct gfs2_sbd *sdp) · line 665
Quoted 2 lines
fs/gfs2/sys.c +0
-2- sysfs_frees_sdp =1 ;/* Freeing sdp is now done by sysfs calling -function gfs2_sbd_release. */ You should also delete this variable at the top of the function, as it is now only set once there and never used.
Thanks, I should have gotten a compiler warning for that. I was feeling so confident with my builds this morning ... pays not to get too cocky I suppose.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
With that:
Reviewed-by Greg Kroah-Hartman <[email protected]>Thanks, will re-spin.
Don't bother, I'll fix that up.
Thanks man!