Linux CAN drivers development
 help / color / mirror / Atom feed
From: Jimmy Assarsson <extja@kvaser.com>
To: linux-can@vger.kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>,
	Anssi Hannula <anssi.hannula@bitwise.fi>
Cc: Jimmy Assarsson <jimmyassarsson@gmail.com>,
	Jimmy Assarsson <extja@kvaser.com>
Subject: [PATCH can-next v5 07/11] can: kvaser_usb_leaf: Fix wrong CAN state after stopping
Date: Mon, 10 Oct 2022 20:52:33 +0200	[thread overview]
Message-ID: <20221010185237.319219-8-extja@kvaser.com> (raw)
In-Reply-To: <20221010185237.319219-1-extja@kvaser.com>

From: Anssi Hannula <anssi.hannula@bitwise.fi>

0bfd:0124 Kvaser Mini PCI Express 2xHS FW 4.18.778 sends a
CMD_CHIP_STATE_EVENT indicating bus-off after stopping the device,
causing a stopped device to appear as CAN_STATE_BUS_OFF instead of
CAN_STATE_STOPPED.

Fix that by not handling error events on stopped devices.

Fixes: 080f40a6fa28 ("can: kvaser_usb: Add support for Kvaser CAN/USB devices")
Tested-by: Jimmy Assarsson <extja@kvaser.com>
Signed-off-by: Anssi Hannula <anssi.hannula@bitwise.fi>
Signed-off-by: Jimmy Assarsson <extja@kvaser.com>
---
Changes in v5:
 - Split series and rebased on linux-can-next
 - Remove stable from CC

Changes in v4:
 - No changes

Changes in v3:
 - Rebased on 1d5eeda23f36 ("can: kvaser_usb: advertise timestamping capabilities and add ioctl support")
 - Add stable to CC
 - Add S-o-b

Changes in v2:
  - Rebased on b3b6df2c56d8 ("can: kvaser_usb: kvaser_usb_leaf: fix bittiming limits")

 drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
index 993fcc19637d..4f9c76f4d0da 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
@@ -1045,6 +1045,10 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev,
 	leaf = priv->sub_priv;
 	stats = &priv->netdev->stats;
 
+	/* Ignore e.g. state change to bus-off reported just after stopping */
+	if (!netif_running(priv->netdev))
+		return;
+
 	/* Update all of the CAN interface's state and error counters before
 	 * trying any memory allocation that can actually fail with -ENOMEM.
 	 *
-- 
2.38.0


  parent reply	other threads:[~2022-10-10 18:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10 18:52 [PATCH can-next v5 00/11] can: kvaser_usb: Fixes and improvements Jimmy Assarsson
2022-10-10 18:52 ` [PATCH can-next v5 01/11] can: kvaser_usb: Fix possible completions during init_completion Jimmy Assarsson
2022-10-26  8:14   ` Marc Kleine-Budde
2022-10-26 18:04     ` Jimmy Assarsson
2022-10-10 18:52 ` [PATCH can-next v5 02/11] can: kvaser_usb: kvaser_usb_leaf: Get capabilities from device Jimmy Assarsson
2022-10-10 18:52 ` [PATCH can-next v5 03/11] can: kvaser_usb: kvaser_usb_leaf: Rename {leaf,usbcan}_cmd_error_event to {leaf,usbcan}_cmd_can_error_event Jimmy Assarsson
2022-10-10 18:52 ` [PATCH can-next v5 04/11] can: kvaser_usb: kvaser_usb_leaf: Handle CMD_ERROR_EVENT Jimmy Assarsson
2022-10-10 18:52 ` [PATCH can-next v5 05/11] can: kvaser_usb_leaf: Set Warning state even without bus errors Jimmy Assarsson
2022-10-10 18:52 ` [PATCH can-next v5 06/11] can: kvaser_usb_leaf: Fix improved state not being reported Jimmy Assarsson
2022-10-10 18:52 ` Jimmy Assarsson [this message]
2022-10-10 18:52 ` [PATCH can-next v5 08/11] can: kvaser_usb_leaf: Ignore stale bus-off after start Jimmy Assarsson
2022-10-10 18:52 ` [PATCH can-next v5 09/11] can: kvaser_usb_leaf: Fix bogus restart events Jimmy Assarsson
2022-10-10 18:52 ` [PATCH can-next v5 10/11] can: kvaser_usb: Add struct kvaser_usb_busparams Jimmy Assarsson
2022-10-19 21:57   ` Marc Kleine-Budde
2022-10-10 18:52 ` [PATCH can-next v5 11/11] can: kvaser_usb: Compare requested bittiming parameters with actual parameters in do_set_{,data}_bittiming Jimmy Assarsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221010185237.319219-8-extja@kvaser.com \
    --to=extja@kvaser.com \
    --cc=anssi.hannula@bitwise.fi \
    --cc=jimmyassarsson@gmail.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox