linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Oliver Hartkopp <socketcan@hartkopp.net>, linux-can@vger.kernel.org
Subject: Re: [PATCH v7 4/7] can: provide a separate bittiming_const parameter to bittiming functions
Date: Fri, 28 Feb 2014 14:02:40 +0100	[thread overview]
Message-ID: <531088F0.4040708@pengutronix.de> (raw)
In-Reply-To: <531081A9.5020107@hartkopp.net>

[-- Attachment #1: Type: text/plain, Size: 1726 bytes --]

On 02/28/2014 01:31 PM, Oliver Hartkopp wrote:
> 
> 
> On 28.02.2014 11:46, Marc Kleine-Budde wrote:
>> On 02/28/2014 11:26 AM, Oliver Hartkopp wrote:
> 
> 
>>>  {
>>> -	struct can_priv *priv = netdev_priv(dev);
>>> -	int err;
>>> +	int err = -EINVAL;
>>
>> Keep err uninitialized and make an explicit else err = -EINVAL.... see
>> below:
>>
> 
> 
>>> +	if (!bt->tq) {
>>> +		/* non-expert mode: Determine bit-timing parameters */
>>> +		if (bt->bitrate)
>>
>> Why not:
>> 	if (!bt->tq && bt->bitrate) {
>>
>>> +			err = can_calc_bittiming(dev, bt, btc);
>>> +	} else {
>>
>> 	} else if (bt->tq && !bt->bitrate) {
>>
>>> +		/*
>>> +		 * expert mode: Check bit-timing parameters and
>>> +		 * calculate proper brp and a human readable bitrate
>>> +		 */
>>> +		if (!bt->bitrate)
>>> +			err = can_fixup_bittiming(dev, bt, btc);
>>>  	}
>> 	} else {
>> 		err = -EINVAL;
>> 	}
> 
> I don't have a strong preference on my implementation.
> 
> But IMHO your suggested changes only add additional code and additional
> comparisons in the if statement.
> 
> I don't see a benefit in your suggestions :-(

You have 3 seperate if()s and an implicit error value from the
initialisation. This is IMHO more straight forward:

	if (!bt->tq && bt->bitrate)
		err = can_calc_bittiming(dev, bt, btc);
	else if (bt->tq && !bt->bitrate)
		err = can_fixup_bittiming(dev, bt, btc);
	else
		err = -EINVAL;

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 242 bytes --]

  reply	other threads:[~2014-02-28 13:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-28 10:26 [PATCH v7 0/7] Add CAN FD infrastructure for CAN driver Oliver Hartkopp
2014-02-28 10:26 ` [PATCH v7 1/7] can: preserve skbuff protocol in can_put_echo_skb Oliver Hartkopp
2014-02-28 10:26 ` [PATCH v7 2/7] can: only send bitrate data via netlink when available Oliver Hartkopp
2014-02-28 10:26 ` [PATCH v7 3/7] can: move sanity check for bitrate and tq into can_get_bittiming Oliver Hartkopp
2014-02-28 10:26 ` [PATCH v7 4/7] can: provide a separate bittiming_const parameter to bittiming functions Oliver Hartkopp
2014-02-28 10:46   ` Marc Kleine-Budde
2014-02-28 12:31     ` Oliver Hartkopp
2014-02-28 13:02       ` Marc Kleine-Budde [this message]
2014-02-28 13:07         ` Oliver Hartkopp
2014-02-28 10:26 ` [PATCH v7 5/7] can: introduce the data bitrate configuration for CAN FD Oliver Hartkopp
2014-02-28 10:26 ` [PATCH v7 6/7] can: allow to change the device mtu for CAN FD capable devices Oliver Hartkopp
2014-02-28 10:26 ` [PATCH v7 7/7] can: add bittiming check at interface open for CAN FD Oliver Hartkopp

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=531088F0.4040708@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=socketcan@hartkopp.net \
    /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;
as well as URLs for NNTP newsgroup(s).