summaryrefslogtreecommitdiff
path: root/drivers/cdrom
diff options
context:
space:
mode:
authorAtul Gopinathan <atulgopinathan@gmail.com>2021-05-03 13:56:54 +0200
committerDenys Drozdov <denys.drozdov@toradex.com>2021-07-15 13:53:57 +0300
commitd6ec8be2e5651b262d69d41ce450b979d733fdcb (patch)
tree03197e55d368191cd5d848fc3e721c3617f4c5dd /drivers/cdrom
parente8fa11787eefc058f68f940b3d5f2f323719d7f0 (diff)
cdrom: gdrom: deallocate struct gdrom_unit fields in remove_gdrom
commit d03d1021da6fe7f46efe9f2a7335564e7c9db5ab upstream. The fields, "toc" and "cd_info", of "struct gdrom_unit gd" are allocated in "probe_gdrom()". Prevent a memory leak by making sure "gd.cd_info" is deallocated in the "remove_gdrom()" function. Also prevent double free of the field "gd.toc" by moving it from the module's exit function to "remove_gdrom()". This is because, in "probe_gdrom()", the function makes sure to deallocate "gd.toc" in case of any errors, so the exit function invoked later would again free "gd.toc". The patch also maintains consistency by deallocating the above mentioned fields in "remove_gdrom()" along with another memory allocated field "gd.disk". Suggested-by: Jens Axboe <axboe@kernel.dk> Cc: Peter Rosin <peda@axentia.se> Cc: stable <stable@vger.kernel.org> Signed-off-by: Atul Gopinathan <atulgopinathan@gmail.com> Link: https://lore.kernel.org/r/20210503115736.2104747-28-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/cdrom')
-rw-r--r--drivers/cdrom/gdrom.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 6988af381101..ccb3f286deb9 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -828,6 +828,8 @@ static int remove_gdrom(struct platform_device *devptr)
if (gdrom_major)
unregister_blkdev(gdrom_major, GDROM_DEV_NAME);
unregister_cdrom(gd.cd_info);
+ kfree(gd.cd_info);
+ kfree(gd.toc);
return 0;
}
@@ -859,7 +861,6 @@ static void __exit exit_gdrom(void)
{
platform_device_unregister(pd);
platform_driver_unregister(&gdrom_driver);
- kfree(gd.toc);
}
module_init(init_gdrom);