All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zijie Zhao <zzjas98@gmail.com>
To: davem@davemloft.net, edumazet@google.com, pabeni@redhat.com
Cc: netdev@vger.kernel.org, chenyuan0y@gmail.com
Subject: [drivers/net/netdevsim] Question about possible memleak
Date: Wed, 13 Mar 2024 21:13:18 -0500	[thread overview]
Message-ID: <ZfJdPoN7be+5ohpl@zijie-lab> (raw)

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


             reply	other threads:[~2024-03-14  2:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14  2:13 Zijie Zhao [this message]
2024-03-14 18:55 ` [drivers/net/netdevsim] Question about possible memleak Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZfJdPoN7be+5ohpl@zijie-lab \
    --to=zzjas98@gmail.com \
    --cc=chenyuan0y@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.