]> git.baikalelectronics.ru Git - kernel.git/commit
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Dec 2021 09:57:07 +0000 (10:57 +0100)
commit04fb296e7879d8c2f679abf8be23daec4c934a48
tree7e392adcfea16b037f07cfe1effe9c2e6222bfa5
parent12371fb1ba77fb254e5e8d4761b2baf9b17dbcd7
can: m_can: m_can_read_fifo: fix memory leak in error branch

commit 2cad1a8236e76dd1b188806101eb6a0bb4f570c4 upstream.

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: 81caecb72d42 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/can/m_can/m_can.c