All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Mailhol <vincent.mailhol@gmail.com>
To: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: linux-can@vger.kernel.org, Mark Bath <mark@baggywrinkle.co.uk>
Subject: Re: [PATCH 2/5] can: bittiming: can_calc_bittiming(): make use of min3()
Date: Sun, 11 Sep 2022 17:24:01 +0900	[thread overview]
Message-ID: <CAMZ6RqKqhmTgUZiwe5uqUjBDnhhC2iOjZ791+Y845btJYwVDKg@mail.gmail.com> (raw)
In-Reply-To: <20220907103845.3929288-3-mkl@pengutronix.de>

On Wed. 7 sept. 2022 à 19:59, Marc Kleine-Budde <mkl@pengutronix.de> wrote:
> In can_calc_bittiming() there are several open coded checks to ensure
> that SJW is within certain limits. Replace this by a single call to
> min3().
>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>  drivers/net/can/dev/calc_bittiming.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/can/dev/calc_bittiming.c b/drivers/net/can/dev/calc_bittiming.c
> index d3caa040614d..ce6bef2444a2 100644
> --- a/drivers/net/can/dev/calc_bittiming.c
> +++ b/drivers/net/can/dev/calc_bittiming.c
> @@ -158,12 +158,8 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,
>         if (!bt->sjw || !btc->sjw_max) {
>                 bt->sjw = 1;
>         } else {
> -               /* bt->sjw is at least 1 -> sanitize upper bound to sjw_max */
> -               if (bt->sjw > btc->sjw_max)
> -                       bt->sjw = btc->sjw_max;
> -               /* bt->sjw must not be higher than tseg2 */
> -               if (tseg2 < bt->sjw)
> -                       bt->sjw = tseg2;
> +               /* sjw must not be higher than sjw_max and tseg2 */
> +               bt->sjw = min3(bt->sjw, btc->sjw_max, tseg2);

Not directly a criticism of this patch (as things were already like
that), but if the user provides an incorrect value for SJW (or any
other bittiming argument), wouldn't it be better to inform? Returning
-EINVAL might be too violent. Maybe a dmesg would be good?


Yours sincerely,
Vincent Mailhol

  reply	other threads:[~2022-09-11  8:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-07 10:38 [PATCH 0/5] can: bittiming: improve SJW handling and default Marc Kleine-Budde
2022-09-07 10:38 ` [PATCH 1/5] can: dev: register_candev(): ensure that bittiming const are valid Marc Kleine-Budde
2022-09-07 10:38 ` [PATCH 2/5] can: bittiming: can_calc_bittiming(): make use of min3() Marc Kleine-Budde
2022-09-11  8:24   ` Vincent Mailhol [this message]
2022-09-12  5:56     ` Thomas.Kopp
2022-09-12  8:28       ` Vincent Mailhol
2023-01-31 16:04         ` Marc Kleine-Budde
2023-02-01  5:49           ` Vincent Mailhol
2023-02-01  8:58             ` Marc Kleine-Budde
2023-02-01  9:38               ` Vincent Mailhol
2023-02-02  9:55                 ` Marc Kleine-Budde
2023-02-02 10:29                   ` Vincent Mailhol
2023-02-01  9:05         ` Marc Kleine-Budde
2022-09-07 10:38 ` [PATCH 3/5] can: bittiming: can_calc_bittiming(): clean up SJW sanitizing Marc Kleine-Budde
2022-09-07 10:38 ` [PATCH 4/5] can: bittiming: can_calc_bittiming(): ensure that SJW is not longer than either Phase Buffer Segment Marc Kleine-Budde
2022-09-07 10:38 ` [PATCH 5/5] can: bittiming: can_calc_bittiming(): use Phase Seg2 / 2 as default for SJW Marc Kleine-Budde
2022-09-07 19:19   ` Thomas.Kopp
2022-09-08 19:57     ` Marc Kleine-Budde
2022-09-09 12:29       ` Marc Kleine-Budde
2022-09-26  6:15         ` Thomas.Kopp

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=CAMZ6RqKqhmTgUZiwe5uqUjBDnhhC2iOjZ791+Y845btJYwVDKg@mail.gmail.com \
    --to=vincent.mailhol@gmail.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mark@baggywrinkle.co.uk \
    --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 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.