Re: [PATCH] vdpa_sim: fix possible memory leak in vdpasim_net_init() and vdpasim_blk_init()

From: Stefano Garzarella
Date: Mon Nov 07 2022 - 04:15:41 EST


On Mon, Nov 07, 2022 at 03:41:42PM +0800, Jason Wang wrote:
On Fri, Nov 4, 2022 at 4:41 PM ruanjinjie <ruanjinjie@xxxxxxxxxx> wrote:

If device_register() returns error in vdpasim_net_init() or
vdpasim_blk_init(), name of kobject which is allocated in dev_set_name()
called in device_add() is leaked.

As comment of device_add() says, it should call put_device() to drop
the reference count that was set in device_initialize() when it fails,
so the name can be freed in kobject_cleanup().

Signed-off-by: ruanjinjie <ruanjinjie@xxxxxxxxxx>

Acked-by: Jason Wang <jasowang@xxxxxxxxxx>

Should we have a fixes tag and cc stable?

Yep, I think so.

The fixes tags should be:

Fixes: 899c4d187f6a ("vdpa_sim_blk: add support for vdpa management tool")
Fixes: a3c06ae158dd ("vdpa_sim_net: Add support for user supported devices")

With them:

Reviewed-by: Stefano Garzarella <sgarzare@xxxxxxxxxx>

Thanks,
Stefano