From 8a00785edd166361e08c6cf710bf3acdd6038005 Mon Sep 17 00:00:00 2001 From: Nicholas Mc Guire Date: Sun, 1 Feb 2015 03:34:34 -0500 Subject: [PATCH 1/2] can: janz-ican3: fix type mismatch in assignment return type of wait_for_completion_timeout is unsigned long not int, this patch removes the type mismatch by moving the call into the condition. Signed-off-by: Nicholas Mc Guire Signed-off-by: Marc Kleine-Budde --- drivers/net/can/janz-ican3.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/can/janz-ican3.c b/drivers/net/can/janz-ican3.c index 0eb4d181ae4d..4dd183a3643a 100644 --- a/drivers/net/can/janz-ican3.c +++ b/drivers/net/can/janz-ican3.c @@ -1679,8 +1679,7 @@ static int ican3_get_berr_counter(const struct net_device *ndev, if (ret) return ret; - ret = wait_for_completion_timeout(&mod->buserror_comp, HZ); - if (ret == 0) { + if (!wait_for_completion_timeout(&mod->buserror_comp, HZ)) { netdev_info(mod->ndev, "%s timed out\n", __func__); return -ETIMEDOUT; } @@ -1705,8 +1704,7 @@ static ssize_t ican3_sysfs_show_term(struct device *dev, if (ret) return ret; - ret = wait_for_completion_timeout(&mod->termination_comp, HZ); - if (ret == 0) { + if (!wait_for_completion_timeout(&mod->termination_comp, HZ)) { netdev_info(mod->ndev, "%s timed out\n", __func__); return -ETIMEDOUT; } From a9ca6e13d66042b3ac18d1352b88b7cd0da8fc21 Mon Sep 17 00:00:00 2001 From: "Ahmed S. Darwish" Date: Mon, 2 Feb 2015 15:15:55 -0500 Subject: [PATCH 2/2] can: kvaser_usb: Ignore spurious error events after a busoff Sending data in high speed then introducing a busoff results in spurious BUS_ERROR events from the USBCan-II firmware directly _after_ the triggered BUS_OFF event. In the current CAN state handling code, this will lead to an invalid can state of ACTIVE, ERROR, or PASSIVE even though the CAN controller has been already shut down due to the busoff. Guard the state handling code from such invalid events. Signed-off-by: Ahmed S. Darwish Signed-off-by: Marc Kleine-Budde --- drivers/net/can/usb/kvaser_usb.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c index 17d28d7dd412..2928f7003041 100644 --- a/drivers/net/can/usb/kvaser_usb.c +++ b/drivers/net/can/usb/kvaser_usb.c @@ -11,7 +11,7 @@ * Copyright (C) 2002-2006 KVASER AB, Sweden. All rights reserved. * Copyright (C) 2010 Matthias Fuchs , esd gmbh * Copyright (C) 2012 Olivier Sobrie - * Copyright (C) 2015 Valeo A.S. + * Copyright (C) 2015 Valeo S.A. */ #include @@ -824,14 +824,15 @@ static void kvaser_usb_rx_error_update_can_state(struct kvaser_usb_net_priv *pri else if (es->status & M16C_STATE_BUS_PASSIVE) new_state = CAN_STATE_ERROR_PASSIVE; else if (es->status & M16C_STATE_BUS_ERROR) { - if ((es->txerr >= 256) || (es->rxerr >= 256)) - new_state = CAN_STATE_BUS_OFF; - else if ((es->txerr >= 128) || (es->rxerr >= 128)) - new_state = CAN_STATE_ERROR_PASSIVE; - else if ((es->txerr >= 96) || (es->rxerr >= 96)) - new_state = CAN_STATE_ERROR_WARNING; - else if (cur_state > CAN_STATE_ERROR_ACTIVE) - new_state = CAN_STATE_ERROR_ACTIVE; + /* Guard against spurious error events after a busoff */ + if (cur_state < CAN_STATE_BUS_OFF) { + if ((es->txerr >= 128) || (es->rxerr >= 128)) + new_state = CAN_STATE_ERROR_PASSIVE; + else if ((es->txerr >= 96) || (es->rxerr >= 96)) + new_state = CAN_STATE_ERROR_WARNING; + else if (cur_state > CAN_STATE_ERROR_ACTIVE) + new_state = CAN_STATE_ERROR_ACTIVE; + } } if (!es->status)