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: Re: [PATCH 1/4] Consolidate and unify state change handling
Date: Sun, 21 Sep 2014 15:27:42 +0000 [thread overview]
Message-ID: <541EEE6E.5010805@marel.com> (raw)
In-Reply-To: <541C9306.1020800@grandegger.com>
On fös 19.sep 2014 20:33, Wolfgang Grandegger wrote:
> On 09/18/2014 06:25 PM, Andri Yngvason wrote:
>
> Please add a brief patch description. E.g. what is it good for and what
> does it improve.
I'll do that. Thanks for pointing this out.
>> ...
>> +
>> +void can_change_state(struct net_device *dev, struct can_frame *cf,
>> + enum can_state state, enum can_err_dir err_dir)
> Thinking about it... passing txerr and rxerr directly here would make
> the err_dir obsolete and the code more simpler. CAN controllers
> not supporting tx/rx error counter should pass "0, 0".
There are controllers that do not expose the error counters but do expose
the individual states of the error counters (e.g. mscan); or maybe rather
which state changed? What I proposed in my reply to [PATCH 2/4] would
solve this.
>
> Also s/state/new_state/ would improve readability.
Yes.
>
>> +{
>> + struct can_priv *priv = netdev_priv(dev);
>> +
>> + if (unlikely(state == priv->state)) {
>> + netdev_warn(dev, "%s: oops, state did not change", __func__);
>> + return;
>> + }
>> +
>> + if (state != CAN_STATE_BUS_OFF)
>> + cf->can_id |= CAN_ERR_CRTL;
>> +
>> + switch (state) {
>> + case CAN_STATE_ERROR_WARNING:
>> + if (state > priv->state)
>> + priv->can_stats.error_warning++;
>> + cf->data[1] = can_make_state_warning(err_dir);
>> + break;
>> +
>> + case CAN_STATE_ERROR_PASSIVE:
>> + if (state > priv->state)
>> + priv->can_stats.error_passive++;
>> + cf->data[1] = can_make_state_passive(err_dir);
>> + break;
>> +
>> + case CAN_STATE_ERROR_ACTIVE:
>> + cf->data[1] = CAN_ERR_CRTL_ACTIVE;
>> + break;
>> +
>> + case CAN_STATE_BUS_OFF:
>> + priv->can_stats.bus_off++;
>> + cf->can_id |= CAN_ERR_BUSOFF;
>> + break;
>> +
>> + default:
> A netdev_warn would be nice here.
Yes, that would probably we wise in case someone accidentally passes
something
that isn't really a state.
Andri
prev parent reply other threads:[~2014-09-21 15:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-18 16:25 [PATCH 1/4] Consolidate and unify state change handling Andri Yngvason
[not found] ` <CAHuoermUnpToi9TzMDL9+h_LD4yQtuhdG6M=yhs7Q7vFLjNvKA@mail.gmail.com>
2014-09-18 17:05 ` Andri Yngvason
2014-09-18 17:08 ` Andri Yngvason
2014-09-19 20:33 ` Wolfgang Grandegger
2014-09-21 15:27 ` Andri Yngvason [this message]
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=541EEE6E.5010805@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.