aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-04-04 09:29:54 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-04-04 09:29:54 +0200
commit222b4400a177dbbb27447e4883ce1e0257a6efe7 (patch)
tree982965662b31722805e4877480322b17e3923f0d
parent8498b17c2e92652d40e289c5ba1bca6f111f82f0 (diff)
downloadpatches-222b4400a177dbbb27447e4883ce1e0257a6efe7.tar.gz
memstick patch
-rw-r--r--0001-memstick-fix-memory-leak-if-card-device-is-never-reg.patch54
-rw-r--r--series1
2 files changed, 55 insertions, 0 deletions
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 <gregkh@linuxfoundation.org>
+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 <maximlevitsky@gmail.com>
+Cc: Alex Dubov <oakad@yahoo.com>
+Cc: Ulf Hansson <ulf.hansson@linaro.org>
+Cc: "Rafael J. Wysocki" <rafael@kernel.org>
+Cc: Hans de Goede <hdegoede@redhat.com>
+Cc: Kay Sievers <kay.sievers@vrfy.org>
+Cc: linux-mmc@vger.kernel.org
+Fixes: 0252c3b4f018 ("memstick: struct device - replace bus_id with dev_name(),
+Cc: stable <stable@kernel.org>
+Co-developed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Co-developed-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
+---
+ 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