Skip to content

Commit 4b6d621

Browse files
gregkhUlf Hansson
authored andcommitted
memstick: fix memory leak if card device is never registered
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: 0252c3b ("memstick: struct device - replace bus_id with dev_name(), dev_set_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> Signed-off-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr> Link: https://lore.kernel.org/r/20230401200327.16800-1-gregkh@linuxfoundation.org Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 2265098 commit 4b6d621

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

drivers/memstick/core/memstick.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ static struct memstick_dev *memstick_alloc_card(struct memstick_host *host)
410410
return card;
411411
err_out:
412412
host->card = old_card;
413+
kfree_const(card->dev.kobj.name);
413414
kfree(card);
414415
return NULL;
415416
}
@@ -468,8 +469,10 @@ static void memstick_check(struct work_struct *work)
468469
put_device(&card->dev);
469470
host->card = NULL;
470471
}
471-
} else
472+
} else {
473+
kfree_const(card->dev.kobj.name);
472474
kfree(card);
475+
}
473476
}
474477

475478
out_power_off:

0 commit comments

Comments
 (0)