From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Marc Kleine-Budde <mkl@pengutronix.de>, 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:07:22 +0100 [thread overview]
Message-ID: <53108A0A.5040202@hartkopp.net> (raw)
In-Reply-To: <531088F0.4040708@pengutronix.de>
On 28.02.2014 14:02, Marc Kleine-Budde wrote:
> 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;
>
Ok - looks good too.
Will change this in the v8 patch series.
Regards,
Oliver
next prev parent reply other threads:[~2014-02-28 13:07 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
2014-02-28 13:07 ` Oliver Hartkopp [this message]
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=53108A0A.5040202@hartkopp.net \
--to=socketcan@hartkopp.net \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
/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).