]> Git Repo - linux.git/commitdiff
memstick: fix memory leak if card device is never registered
authorGreg Kroah-Hartman <[email protected]>
Sat, 1 Apr 2023 20:03:27 +0000 (22:03 +0200)
committerUlf Hansson <[email protected]>
Wed, 5 Apr 2023 09:43:51 +0000 (11:43 +0200)
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 <[email protected]>
Cc: Alex Dubov <[email protected]>
Cc: Ulf Hansson <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Kay Sievers <[email protected]>
Cc: [email protected]
Fixes: 0252c3b4f018 ("memstick: struct device - replace bus_id with dev_name(), dev_set_name()")
Cc: stable <[email protected]>
Co-developed-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Co-developed-by: Mirsad Goran Todorovac <[email protected]>
Signed-off-by: Mirsad Goran Todorovac <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Ulf Hansson <[email protected]>
drivers/memstick/core/memstick.c

index bf766784545916a6068932ed4ea925e94a240aef..bbfaf6536903d35c704fced42859fb4fb3e54afe 100644 (file)
@@ -410,6 +410,7 @@ static struct memstick_dev *memstick_alloc_card(struct memstick_host *host)
        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_struct *work)
                                put_device(&card->dev);
                                host->card = NULL;
                        }
-               } else
+               } else {
+                       kfree_const(card->dev.kobj.name);
                        kfree(card);
+               }
        }
 
 out_power_off:
This page took 0.058343 seconds and 4 git commands to generate.