block: fix memory leak in disk_register_independent_access_ranges
PATCH 1/1 block: fix memory leak in disk_register_independent_access_ranges
kobject_init_and_add() takes reference even when it fails. According to the doc of kobject_init_and_add()
If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object.
Fix this issue by adding kobject_put().
Callback function blk_ia_ranges_sysfs_release() in kobject_put() can handle the pointer "iars" properly.
--- block/blk-ia-ranges.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-ia-ranges.c +1 -1
@@ -144,7 +144,7 @@ int disk_register_independent_access_ranges(struct gendisk *disk, &q->kobj, "%s", "independent_access_ranges");if (ret) { q->ia_ranges =NULL ; -kfree (iars); +kobject_put (&iars->kobj);return ret; }
Signature · 1 line
2.17.1
Quoted 21 lines · Miaoqian Lin
kobject_init_and_add()takes reference even when it fails. According to the doc ofkobject_init_and_add()If this function returns an error,
kobject_put()must be called to properly clean up the memory associated with the object.Fix this issue by adding
kobject_put().
Callback functionblk_ia_ranges_sysfs_release()inkobject_put()can handle the pointer "iars" properly.Fixes a2247f19ee1c ("block: Add independent access ranges support")Signed-off-by Miaoqian Lin <[email protected]>--- block/blk-ia-ranges.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-ia-ranges.c +0
-0
block/blk-ia-ranges.c int disk_register_independent_access_ranges(struct gendisk *disk, · line 150
Quoted 8 lines
block/blk-ia-ranges.c +1
-1@@ -144,7 +144,7 @@ int disk_register_independent_access_ranges(struct gendisk *disk, &q->kobj, "%s", "independent_access_ranges");if (ret) { q->ia_ranges =NULL ; -kfree (iars); +kobject_put (&iars->kobj);return ret; }
Looks good.
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 11 lines · Miaoqian Lin
kobject_init_and_add()takes reference even when it fails. According to the doc ofkobject_init_and_add()If this function returns an error,
kobject_put()must be called to properly clean up the memory associated with the object.Fix this issue by adding
kobject_put().
Callback functionblk_ia_ranges_sysfs_release()inkobject_put()can handle the pointer "iars" properly.[...]
Applied, thanks!
[1/1] block: fix memory leak in disk_register_independent_access_ranges
commit: c321e650a45c4228cce1107680ac74e06f014906
Best regards,
Signature · 1 line
Jens Axboe