* [PATCH] can: m_can: m_can_receive_skb(): add missing error handling to can_rx_offload_queue_sorted() call
@ 2021-04-01 8:45 Marc Kleine-Budde
2021-04-01 20:40 ` Kees Cook
0 siblings, 1 reply; 2+ messages in thread
From: Marc Kleine-Budde @ 2021-04-01 8:45 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde, coverity-bot, Torin Cooper-Bennun
In commit 1be37d3b0414 ("can: m_can: fix periph RX path: use
rx-offload to ensure skbs are sent from softirq context") the RX path
for peripherals (i.e. SPI based m_can controllers) was converted to
the rx-offload infrastructure. However, the error handling for
can_rx_offload_queue_sorted() was forgotten.
can_rx_offload_queue_sorted() will return with an error if the
internal queue is full.
This patch adds the missing error handling, by increasing the
rx_fifo_errors.
Fixes: 1be37d3b0414 ("can: m_can: fix periph RX path: use rx-offload to ensure skbs are sent from softirq context")
Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1503583 ("Error handling issues")
Cc: Torin Cooper-Bennun <torin@maxiluxsystems.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/m_can/m_can.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 890ed826a355..9df1ba1f2d04 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -466,10 +466,17 @@ static void m_can_receive_skb(struct m_can_classdev *cdev,
struct sk_buff *skb,
u32 timestamp)
{
- if (cdev->is_peripheral)
- can_rx_offload_queue_sorted(&cdev->offload, skb, timestamp);
- else
+ if (cdev->is_peripheral) {
+ struct net_device_stats *stats = &cdev->net->stats;
+ int err;
+
+ err = can_rx_offload_queue_sorted(&cdev->offload, skb,
+ timestamp);
+ if (err)
+ stats->rx_fifo_errors++;
+ } else {
netif_receive_skb(skb);
+ }
}
static void m_can_read_fifo(struct net_device *dev, u32 rxfs)
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] can: m_can: m_can_receive_skb(): add missing error handling to can_rx_offload_queue_sorted() call
2021-04-01 8:45 [PATCH] can: m_can: m_can_receive_skb(): add missing error handling to can_rx_offload_queue_sorted() call Marc Kleine-Budde
@ 2021-04-01 20:40 ` Kees Cook
0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2021-04-01 20:40 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can, Torin Cooper-Bennun
On Thu, Apr 01, 2021 at 10:45:15AM +0200, Marc Kleine-Budde wrote:
> In commit 1be37d3b0414 ("can: m_can: fix periph RX path: use
> rx-offload to ensure skbs are sent from softirq context") the RX path
> for peripherals (i.e. SPI based m_can controllers) was converted to
> the rx-offload infrastructure. However, the error handling for
> can_rx_offload_queue_sorted() was forgotten.
> can_rx_offload_queue_sorted() will return with an error if the
> internal queue is full.
>
> This patch adds the missing error handling, by increasing the
> rx_fifo_errors.
>
> Fixes: 1be37d3b0414 ("can: m_can: fix periph RX path: use rx-offload to ensure skbs are sent from softirq context")
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1503583 ("Error handling issues")
> Cc: Torin Cooper-Bennun <torin@maxiluxsystems.com>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Thanks for the fix!
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
> ---
> drivers/net/can/m_can/m_can.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
> index 890ed826a355..9df1ba1f2d04 100644
> --- a/drivers/net/can/m_can/m_can.c
> +++ b/drivers/net/can/m_can/m_can.c
> @@ -466,10 +466,17 @@ static void m_can_receive_skb(struct m_can_classdev *cdev,
> struct sk_buff *skb,
> u32 timestamp)
> {
> - if (cdev->is_peripheral)
> - can_rx_offload_queue_sorted(&cdev->offload, skb, timestamp);
> - else
> + if (cdev->is_peripheral) {
> + struct net_device_stats *stats = &cdev->net->stats;
> + int err;
> +
> + err = can_rx_offload_queue_sorted(&cdev->offload, skb,
> + timestamp);
> + if (err)
> + stats->rx_fifo_errors++;
> + } else {
> netif_receive_skb(skb);
> + }
> }
>
> static void m_can_read_fifo(struct net_device *dev, u32 rxfs)
> --
> 2.30.2
>
>
--
Kees Cook
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-01 20:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-01 8:45 [PATCH] can: m_can: m_can_receive_skb(): add missing error handling to can_rx_offload_queue_sorted() call Marc Kleine-Budde
2021-04-01 20:40 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox