* [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* Re: [drivers/net/netdevsim] Question about possible memleak
2024-03-14 2:13 [drivers/net/netdevsim] Question about possible memleak Zijie Zhao
@ 2024-03-14 18:55 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2024-03-14 18:55 UTC (permalink / raw)
To: Zijie Zhao; +Cc: davem, edumazet, pabeni, netdev, chenyuan0y
On Wed, 13 Mar 2024 21:13:18 -0500 Zijie Zhao wrote:
> 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!
/**
* device_register - register a device with the system.
* @dev: pointer to the device structure
*
* This happens in two clean steps - initialize the device
* and add it to the system. The two steps can be called
* separately, but this is the easiest and most common.
* I.e. you should only call the two helpers separately if
* have a clearly defined need to use and refcount the device
* before it is added to the hierarchy.
*
* For more information, see the kerneldoc for device_initialize()
* and device_add().
*
* NOTE: _Never_ directly free @dev after calling this function, even
* if it returned an error! Always use put_device() to give up the
* reference initialized in this function instead.
*/
int device_register(struct device *dev)
^ 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).