can: rx-offload: can_rx_offload_queue_sorted(): fix error handling, avoid skb mem...
authorMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 9 Oct 2019 13:48:48 +0000 (15:48 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Mon, 4 Nov 2019 20:47:21 +0000 (21:47 +0100)
commitca913f1ac024559ebc17f0b599af262f0ad997c9
treea1717fbdbbc4e06dcd718bed9d593df0f0758129
parent659680bc232ff29cd6aea8df58115775ac365565
can: rx-offload: can_rx_offload_queue_sorted(): fix error handling, avoid skb mem leak

If the rx-offload skb_queue is full can_rx_offload_queue_sorted() will
not queue the skb and return with an error.

None of the callers of this function, issue a kfree_skb() to free the
not queued skb. This results in a memory leak.

This patch fixes the problem by freeing the skb in case of a full queue.
The return value is adjusted to -ENOBUFS to better reflect the actual
problem.

The device stats handling is left to the callers, as this function might
be used in both the rx and tx path.

Fixes: 55059f2b7f86 ("can: rx-offload: introduce can_rx_offload_get_echo_skb() and can_rx_offload_queue_sorted() functions")
Cc: linux-stable <stable@vger.kernel.org>
Cc: Martin Hundebøll <martin@geanix.com>
Reported-by: Martin Hundebøll <martin@geanix.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/rx-offload.c