OSDN Git Service

can: m_can: m_can_read_fifo: fix memory leak in error branch
authorVincent Mailhol <mailhol.vincent@wanadoo.fr>
Sun, 7 Nov 2021 05:07:55 +0000 (14:07 +0900)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Tue, 7 Dec 2021 08:09:06 +0000 (09:09 +0100)
commit31cb32a590d62b18f69a9a6d433f4e69c74fdd56
tree7bba2d6b82f39b00cccab047e33bf1e5f0dfec11
parentf58ac1adc76b5beda43c64ef359056077df4d93a
can: m_can: m_can_read_fifo: fix memory leak in error branch

In m_can_read_fifo(), if the second call to m_can_fifo_read() fails,
the function jump to the out_fail label and returns without calling
m_can_receive_skb(). This means that the skb previously allocated by
alloc_can_skb() is not freed. In other terms, this is a memory leak.

This patch adds a goto label to destroy the skb if an error occurs.

Issue was found with GCC -fanalyzer, please follow the link below for
details.

Fixes: e39381770ec9 ("can: m_can: Disable IRQs on FIFO bus errors")
Link: https://lore.kernel.org/all/20211107050755.70655-1-mailhol.vincent@wanadoo.fr
Cc: stable@vger.kernel.org
Cc: Matt Kline <matt@bitbashing.io>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/m_can/m_can.c