Message ID | 20210205072559.13241-2-xulin.sun@windriver.com (mailing list archive) |
---|---|
State | Awaiting Upstream |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [1/2] can: m_can: m_can_plat_probe(): free can_net device in case probe fails | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Series ignored based on subject |
On 05.02.2021 15:25:59, Xulin Sun wrote: > If the previous can_net device has been successfully allocated, its > private data structure is impossible to be empty, remove this redundant > error return judgment. Otherwise, memory leaks for alloc_candev() will > be triggered. Your analysis is correct, the netdev_priv() will never fail. But how will this trigger a mem leak on alloc_candev()? I've removed that statement. I'll add it back, if I've missed something. > Signed-off-by: Xulin Sun <xulin.sun@windriver.com> Applied to linux-can-next/testing. Thanks, Marc
On 2021/2/5 下午4:19, Marc Kleine-Budde wrote: > On 05.02.2021 15:25:59, Xulin Sun wrote: >> If the previous can_net device has been successfully allocated, its >> private data structure is impossible to be empty, remove this redundant >> error return judgment. Otherwise, memory leaks for alloc_candev() will >> be triggered. > Your analysis is correct, the netdev_priv() will never fail. But how > will this trigger a mem leak on alloc_candev()? I've removed that Hi Marc, The previous code judges the netdev_priv is empty, and then goto out. The correct approach should add free_candev(net_dev) before goto. The code Like: class_dev = netdev_priv(net_dev); if (!class_dev) { dev_err(dev, "Failed to init netdev cdevate"); + free_candev(net_dev); goto out; } Otherwise, memory leaks for alloc_candev() will be triggered. Now directly remove the impossible error return judgment to resolve the above possible issue. Thanks Xulin > statement. I'll add it back, if I've missed something. > >> Signed-off-by: Xulin Sun <xulin.sun@windriver.com> > Applied to linux-can-next/testing. > > Thanks, > Marc >
On 05.02.2021 16:46:16, Xulin Sun wrote: > On 2021/2/5 下午4:19, Marc Kleine-Budde wrote: > > On 05.02.2021 15:25:59, Xulin Sun wrote: > > > If the previous can_net device has been successfully allocated, its > > > private data structure is impossible to be empty, remove this redundant > > > error return judgment. Otherwise, memory leaks for alloc_candev() will > > > be triggered. > > Your analysis is correct, the netdev_priv() will never fail. But how > > will this trigger a mem leak on alloc_candev()? I've removed that > > The previous code judges the netdev_priv is empty, and then goto out. The > correct approach should add free_candev(net_dev) before goto. > > The code Like: > > class_dev = netdev_priv(net_dev); > if (!class_dev) { > dev_err(dev, "Failed to init netdev cdevate"); > + free_candev(net_dev); > goto out; > } > > Otherwise, memory leaks for alloc_candev() will be triggered. No - as you said in the original patch description. The return value of netdev_priv() cannot be NULL, as net_dev is not NULL. > Now directly remove the impossible error return judgment to resolve > the above possible issue. Marc
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 02c5795b7393..042940088d41 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1797,11 +1797,6 @@ struct m_can_classdev *m_can_class_allocate_dev(struct device *dev) } class_dev = netdev_priv(net_dev); - if (!class_dev) { - dev_err(dev, "Failed to init netdev cdevate"); - goto out; - } - class_dev->net = net_dev; class_dev->dev = dev; SET_NETDEV_DEV(net_dev, dev);
If the previous can_net device has been successfully allocated, its private data structure is impossible to be empty, remove this redundant error return judgment. Otherwise, memory leaks for alloc_candev() will be triggered. Signed-off-by: Xulin Sun <xulin.sun@windriver.com> --- drivers/net/can/m_can/m_can.c | 5 ----- 1 file changed, 5 deletions(-)