Linux CAN drivers development
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Wolfgang Grandegger <wg@grandegger.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Andri Yngvason <andri.yngvason@marel.com>, linux-can@vger.kernel.org
Subject: Re: Inconsistent error state transition error frames
Date: Wed, 10 Sep 2014 21:08:21 +0200	[thread overview]
Message-ID: <5410A1A5.1090802@hartkopp.net> (raw)
In-Reply-To: <25bf289f701148cd1800c8e79da342aa@grandegger.com>

On 10.09.2014 13:53, Wolfgang Grandegger wrote:

>>>> +/* controller error counter values / data[6..7] */
>>>> +#define CAN_ERR_TXERR_BYTE 6
>>>> +#define CAN_ERR_RXERR_BYTE 7
>>>>     #endif /* _UAPI_CAN_ERROR_H */
>>>>
>>> I'm not sure what's considered good practice in kernel code but
> wouldn't
>>> it be better to use a macro like this instead?
>>>     #define CAN_ERR_CRTL_DATA(frame) ((frame)->data[1])
>>> which would be used like this:
>>>     if(CAN_ERR_CRTL_DATA(frame) & CAN_ERR_CRTL_whatever) ...
>>
>> I'm not sure....but...
>>
>> Make it a static inline function and give it a proper name, something
>> like can_err_frame_get_ctrl(). Maybe without err_....

Maybe without _frame ? :-)

Think of 

	frame->data[CAN_ERR_CTRL_BYTE] |= CAN_ERR_CRTL_RX_OVERFLOW;

How would this look like?

	can_err_frame_set_ctrl(frame) = can_err_frame_get_ctrl(frame) | CAN_ERR_CRTL_RX_OVERFLOW;

Hm. Not nice.

	CAN_ERR_CRTL_DATA(frame) |= CAN_ERR_CRTL_RX_OVERFLOW;

Is hard to understand at first sight.

> 
> I'm not sure... we also need to set the value. Therefore I would
> vote for:
> 
>  frame->data[CAN_ERR_TXERR_BYTE];
> 
> It does make the code more readable.

Unfortunately CAN_ERR_TXERR_BYTE is pretty long and I have no good idea
how to make it shorter. CAN_ERR_TXERR_IDX is probably more handy.

E.g.

	frame->data[CAN_ERR_CTRL_IDX] |= CAN_ERR_CRTL_RX_OVERFLOW;

I would vote for something like this too.

Should I send a patch for this approach?

Regards,
Oliver


  reply	other threads:[~2014-09-10 19:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-08 16:26 Inconsistent error state transition error frames Andri Yngvason
2014-09-08 16:36 ` Marc Kleine-Budde
2014-09-09 10:48   ` Wolfgang Grandegger
2014-09-09 11:59     ` Andri Yngvason
2014-09-09 13:53       ` Wolfgang Grandegger
2014-09-09 14:49         ` Andri Yngvason
2014-09-09 15:41           ` Wolfgang Grandegger
2014-09-09 18:08             ` Oliver Hartkopp
2014-09-10 10:19               ` Andri Yngvason
2014-09-10 10:29                 ` Marc Kleine-Budde
2014-09-10 11:53                   ` Wolfgang Grandegger
2014-09-10 19:08                     ` Oliver Hartkopp [this message]
2014-09-11 10:03                       ` Andri Yngvason

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=5410A1A5.1090802@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox