From 222b4400a177dbbb27447e4883ce1e0257a6efe7 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 4 Apr 2023 09:29:54 +0200 Subject: memstick patch --- ...x-memory-leak-if-card-device-is-never-reg.patch | 54 ++++++++++++++++++++++ series | 1 + 2 files changed, 55 insertions(+) create mode 100644 0001-memstick-fix-memory-leak-if-card-device-is-never-reg.patch diff --git a/0001-memstick-fix-memory-leak-if-card-device-is-never-reg.patch b/0001-memstick-fix-memory-leak-if-card-device-is-never-reg.patch new file mode 100644 index 00000000000000..276e5f9cd0812c --- /dev/null +++ b/0001-memstick-fix-memory-leak-if-card-device-is-never-reg.patch @@ -0,0 +1,54 @@ +From fb1f85bf132550be559fe712e845eee4475d193f Mon Sep 17 00:00:00 2001 +From: Greg Kroah-Hartman +Date: Sat, 1 Apr 2023 19:12:32 +0200 +Subject: [PATCH 1/2] memstick: fix memory leak if card device is never + registered with the driver core + +When calling dev_set_name() memory is allocated for the name for the +struct device. Once that structure device is registered, or attempted +to be registerd, with the driver core, the driver core will handle +cleaning up that memory when the device is removed from the system. + +Unfortunatly for the memstick code, there is an error path that causes +the struct device to never be registered, and so the memory allocated in +dev_set_name will be leaked. Fix that leak by manually freeing it right +before the memory for the device is freed. + +Cc: Maxim Levitsky +Cc: Alex Dubov +Cc: Ulf Hansson +Cc: "Rafael J. Wysocki" +Cc: Hans de Goede +Cc: Kay Sievers +Cc: linux-mmc@vger.kernel.org +Fixes: 0252c3b4f018 ("memstick: struct device - replace bus_id with dev_name(), +Cc: stable +Co-developed-by: Greg Kroah-Hartman +Signed-off-by: Greg Kroah-Hartman +Co-developed-by: Mirsad Goran Todorovac +--- + drivers/memstick/core/memstick.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +--- a/drivers/memstick/core/memstick.c ++++ b/drivers/memstick/core/memstick.c +@@ -410,6 +410,7 @@ static struct memstick_dev *memstick_all + return card; + err_out: + host->card = old_card; ++ kfree_const(card->dev.kobj.name); + kfree(card); + return NULL; + } +@@ -468,8 +469,10 @@ static void memstick_check(struct work_s + put_device(&card->dev); + host->card = NULL; + } +- } else ++ } else { ++ kfree_const(card->dev.kobj.name); + kfree(card); ++ } + } + + out_power_off: diff --git a/series b/series index c3f4fe52648e38..1c62875d6a49a8 100644 --- a/series +++ b/series @@ -1,4 +1,5 @@ # +0001-memstick-fix-memory-leak-if-card-device-is-never-reg.patch 0001-driver-core-remove-CONFIG_SYSFS_DEPRECATED-and-CONFI.patch 0002-driver-core-class-fix-block-class-problem-when-remov.patch usb.patch -- cgit 1.2.3-korg