netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [drivers/net/netdevsim] Question about possible memleak
@ 2024-03-14  2:13 Zijie Zhao
  2024-03-14 18:55 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Zijie Zhao @ 2024-03-14  2:13 UTC (permalink / raw)
  To: davem, edumazet, pabeni; +Cc: netdev, chenyuan0y

Dear Netdevsim Developers,

We are curious whether the function `nsim_bus_dev_new` might have a memory leak.

The function is https://elixir.bootlin.com/linux/v6.8/source/drivers/net/netdevsim/bus.c#L275
and the relevant code is 
```
static struct nsim_bus_dev *
nsim_bus_dev_new(unsigned int id, unsigned int port_count, unsigned int num_queues)
{
	struct nsim_bus_dev *nsim_bus_dev;
	int err;

	nsim_bus_dev = kzalloc(sizeof(*nsim_bus_dev), GFP_KERNEL);
	...

	err = device_register(&nsim_bus_dev->dev);
	if (err)
		goto err_nsim_bus_dev_id_free;

	return nsim_bus_dev;

err_nsim_bus_dev_id_free:
	ida_free(&nsim_bus_dev_ids, nsim_bus_dev->dev.id);
	put_device(&nsim_bus_dev->dev);
	nsim_bus_dev = NULL;
err_nsim_bus_dev_free:
	kfree(nsim_bus_dev);
	return ERR_PTR(err);
}
```

Here if the `err_nsim_bus_dev_id_free` label is entered, `nsim_bus_dev` will be assigned `NULL` and then `kfree(nsim_bus_dev)` will not free the allocated memory.

Please kindly correct us if we missed any key information. Looking forward to your response!

Best,
Zijie


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-14 18:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-14  2:13 [drivers/net/netdevsim] Question about possible memleak Zijie Zhao
2024-03-14 18:55 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).