Skip to content

Commit bccd8fd

Browse files
Ahmed S. Darwishgregkh
authored andcommitted
can: kvaser_usb: Fix state handling upon BUS_ERROR events
commit e638642 upstream. While being in an ERROR_WARNING state, and receiving further bus error events with error counters still in the ERROR_WARNING range of 97-127 inclusive, the state handling code erroneously reverts back to ERROR_ACTIVE. Per the CAN standard, only revert to ERROR_ACTIVE when the error counters are less than 96. Moreover, in certain Kvaser models, the BUS_ERROR flag is always set along with undefined bits in the M16C status register. Thus use bitwise operators instead of full equality for checking that register against bus errors. Signed-off-by: Ahmed S. Darwish <ahmed.darwish@valeo.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1c13b0f commit bccd8fd

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

‎drivers/net/can/usb/kvaser_usb.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,7 @@ static void kvaser_usb_rx_error(const struct kvaser_usb *dev,
698698
}
699699

700700
new_state = CAN_STATE_ERROR_PASSIVE;
701-
}
702-
703-
if (status == M16C_STATE_BUS_ERROR) {
701+
} else if (status & M16C_STATE_BUS_ERROR) {
704702
if ((priv->can.state < CAN_STATE_ERROR_WARNING) &&
705703
((txerr >= 96) || (rxerr >= 96))) {
706704
cf->can_id |= CAN_ERR_CRTL;
@@ -710,7 +708,8 @@ static void kvaser_usb_rx_error(const struct kvaser_usb *dev,
710708

711709
priv->can.can_stats.error_warning++;
712710
new_state = CAN_STATE_ERROR_WARNING;
713-
} else if (priv->can.state > CAN_STATE_ERROR_ACTIVE) {
711+
} else if ((priv->can.state > CAN_STATE_ERROR_ACTIVE) &&
712+
((txerr < 96) && (rxerr < 96))) {
714713
cf->can_id |= CAN_ERR_PROT;
715714
cf->data[2] = CAN_ERR_PROT_ACTIVE;
716715

0 commit comments

Comments
 (0)