Thread (6 messages) 6 messages, 2 authors, 2021-02-05

Re: [PATCH 2/2] can: m_can: m_can_class_allocate_dev(): remove impossible error return judgment

flat view

From: Marc Kleine-Budde <mkl@pengutronix.de>
Date: 2021-02-05 08:53:23
Also in: linux-can, lkml

On 05.02.2021 16:46:16, Xulin Sun wrote:
On 2021/2/5 下午4:19, Marc Kleine-Budde wrote:
quoted
On 05.02.2021 15:25:59, Xulin Sun wrote:
quoted
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

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help