Re: [RESEND PATCH] memstick: fix memory leak if card device is never registered

From: Greg Kroah-Hartman
Date: Tue Apr 04 2023 - 08:10:11 EST


On Tue, Apr 04, 2023 at 01:54:03PM +0200, Ulf Hansson wrote:
> On Sat, 1 Apr 2023 at 22:03, Greg Kroah-Hartman
> <gregkh@xxxxxxxxxxxxxxxxxxx> wrote:
> >
> > 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@xxxxxxxxx>
> > Cc: Alex Dubov <oakad@xxxxxxxxx>
> > Cc: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
> > Cc: "Rafael J. Wysocki" <rafael@xxxxxxxxxx>
> > Cc: Hans de Goede <hdegoede@xxxxxxxxxx>
> > Cc: Kay Sievers <kay.sievers@xxxxxxxx>
> > Cc: linux-mmc@xxxxxxxxxxxxxxx
> > Fixes: 0252c3b4f018 ("memstick: struct device - replace bus_id with dev_name(),
> > Cc: stable <stable@xxxxxxxxxx>
> > Co-developed-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> > Co-developed-by: Mirsad Goran Todorovac <mirsad.todorovac@xxxxxxxxxxxx>
>
> Applied for fixes and by adding Mirsad's sob tag (according to the
> other thread [1]), thanks!

Wonderful, thanks for picking up that tag, and the patch.

greg k-h