All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andri Yngvason <andri.yngvason@marel.com>
To: Wolfgang Grandegger <wg@grandegger.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	linux-can@vger.kernel.org
Subject: [PATCH 4/4] Consolidate and unify state change handling
Date: Thu, 18 Sep 2014 16:26:05 +0000	[thread overview]
Message-ID: <541B079D.1020409@marel.com> (raw)

Signed-off-by: Andri Yngvason <andri.yngvason@marel.com>
---
  drivers/net/can/sja1000/sja1000.c | 29 +++++++++--------------------
  1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/drivers/net/can/sja1000/sja1000.c 
b/drivers/net/can/sja1000/sja1000.c
index b27ac60..224e7f3 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -467,27 +467,16 @@ static int sja1000_err(struct net_device *dev, 
uint8_t isrc, uint8_t status)
          cf->data[0] = alc & 0x1f;
      }

-    if (state != priv->can.state && (state == CAN_STATE_ERROR_WARNING ||
-                     state == CAN_STATE_ERROR_PASSIVE)) {
-        uint8_t rxerr = priv->read_reg(priv, SJA1000_RXERR);
-        uint8_t txerr = priv->read_reg(priv, SJA1000_TXERR);
-        cf->can_id |= CAN_ERR_CRTL;
-        if (state == CAN_STATE_ERROR_WARNING) {
-            priv->can.can_stats.error_warning++;
-            cf->data[1] = (txerr > rxerr) ?
-                CAN_ERR_CRTL_TX_WARNING :
-                CAN_ERR_CRTL_RX_WARNING;
-        } else {
-            priv->can.can_stats.error_passive++;
-            cf->data[1] = (txerr > rxerr) ?
-                CAN_ERR_CRTL_TX_PASSIVE :
-                CAN_ERR_CRTL_RX_PASSIVE;
-        }
-        cf->data[6] = txerr;
-        cf->data[7] = rxerr;
-    }
+    if (state != priv->can.state) {
+        unsigned int rxerr = priv->read_reg(priv, SJA1000_RXERR);
+        unsigned int txerr = priv->read_reg(priv, SJA1000_TXERR);

-    priv->can.state = state;
+        can_change_state(dev, cf, state,
+                 can_get_err_dir(rxerr, txerr));
+
+        cf->data[6] = rxerr;
+        cf->data[7] = txerr;
+    }

      netif_rx(skb);

                 reply	other threads:[~2014-09-18 16:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=541B079D.1020409@marel.com \
    --to=andri.yngvason@marel.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=wg@grandegger.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.