|
Takashi Iwai |
71939a |
From d03d1021da6fe7f46efe9f2a7335564e7c9db5ab Mon Sep 17 00:00:00 2001
|
|
Takashi Iwai |
71939a |
From: Atul Gopinathan <atulgopinathan@gmail.com>
|
|
Takashi Iwai |
71939a |
Date: Mon, 3 May 2021 13:56:54 +0200
|
|
Takashi Iwai |
71939a |
Subject: [PATCH] cdrom: gdrom: deallocate struct gdrom_unit fields in remove_gdrom
|
|
Takashi Iwai |
71939a |
Git-commit: d03d1021da6fe7f46efe9f2a7335564e7c9db5ab
|
|
Takashi Iwai |
71939a |
Patch-mainline: v5.13-rc3
|
|
Takashi Iwai |
71939a |
References: git-fixes
|
|
Takashi Iwai |
71939a |
|
|
Takashi Iwai |
71939a |
The fields, "toc" and "cd_info", of "struct gdrom_unit gd" are allocated
|
|
Takashi Iwai |
71939a |
in "probe_gdrom()". Prevent a memory leak by making sure "gd.cd_info" is
|
|
Takashi Iwai |
71939a |
deallocated in the "remove_gdrom()" function.
|
|
Takashi Iwai |
71939a |
|
|
Takashi Iwai |
71939a |
Also prevent double free of the field "gd.toc" by moving it from the
|
|
Takashi Iwai |
71939a |
module's exit function to "remove_gdrom()". This is because, in
|
|
Takashi Iwai |
71939a |
"probe_gdrom()", the function makes sure to deallocate "gd.toc" in case
|
|
Takashi Iwai |
71939a |
of any errors, so the exit function invoked later would again free
|
|
Takashi Iwai |
71939a |
"gd.toc".
|
|
Takashi Iwai |
71939a |
|
|
Takashi Iwai |
71939a |
The patch also maintains consistency by deallocating the above mentioned
|
|
Takashi Iwai |
71939a |
fields in "remove_gdrom()" along with another memory allocated field
|
|
Takashi Iwai |
71939a |
"gd.disk".
|
|
Takashi Iwai |
71939a |
|
|
Takashi Iwai |
71939a |
Suggested-by: Jens Axboe <axboe@kernel.dk>
|
|
Takashi Iwai |
71939a |
Cc: Peter Rosin <peda@axentia.se>
|
|
Takashi Iwai |
71939a |
Cc: stable <stable@vger.kernel.org>
|
|
Takashi Iwai |
71939a |
Signed-off-by: Atul Gopinathan <atulgopinathan@gmail.com>
|
|
Takashi Iwai |
71939a |
Link: https://lore.kernel.org/r/20210503115736.2104747-28-gregkh@linuxfoundation.org
|
|
Takashi Iwai |
71939a |
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
|
|
Takashi Iwai |
71939a |
Acked-by: Takashi Iwai <tiwai@suse.de>
|
|
Takashi Iwai |
71939a |
|
|
Takashi Iwai |
71939a |
---
|
|
Takashi Iwai |
71939a |
drivers/cdrom/gdrom.c | 3 ++-
|
|
Takashi Iwai |
71939a |
1 file changed, 2 insertions(+), 1 deletion(-)
|
|
Takashi Iwai |
71939a |
|
|
Takashi Iwai |
71939a |
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
|
|
Takashi Iwai |
71939a |
index 7f681320c7d3..6c4f6139f853 100644
|
|
Takashi Iwai |
71939a |
--- a/drivers/cdrom/gdrom.c
|
|
Takashi Iwai |
71939a |
+++ b/drivers/cdrom/gdrom.c
|
|
Takashi Iwai |
71939a |
@@ -830,6 +830,8 @@ static int remove_gdrom(struct platform_device *devptr)
|
|
Takashi Iwai |
71939a |
if (gdrom_major)
|
|
Takashi Iwai |
71939a |
unregister_blkdev(gdrom_major, GDROM_DEV_NAME);
|
|
Takashi Iwai |
71939a |
unregister_cdrom(gd.cd_info);
|
|
Takashi Iwai |
71939a |
+ kfree(gd.cd_info);
|
|
Takashi Iwai |
71939a |
+ kfree(gd.toc);
|
|
Takashi Iwai |
71939a |
|
|
Takashi Iwai |
71939a |
return 0;
|
|
Takashi Iwai |
71939a |
}
|
|
Takashi Iwai |
71939a |
@@ -861,7 +863,6 @@ static void __exit exit_gdrom(void)
|
|
Takashi Iwai |
71939a |
{
|
|
Takashi Iwai |
71939a |
platform_device_unregister(pd);
|
|
Takashi Iwai |
71939a |
platform_driver_unregister(&gdrom_driver);
|
|
Takashi Iwai |
71939a |
- kfree(gd.toc);
|
|
Takashi Iwai |
71939a |
}
|
|
Takashi Iwai |
71939a |
|
|
Takashi Iwai |
71939a |
module_init(init_gdrom);
|
|
Takashi Iwai |
71939a |
--
|
|
Takashi Iwai |
71939a |
2.26.2
|
|
Takashi Iwai |
71939a |
|