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: Thomas.Kopp@microchip.com, linux-can@vger.kernel.org,
	mark@baggywrinkle.co.uk
Subject: Re: [PATCH 2/5] can: bittiming: can_calc_bittiming(): make use of min3()
Date: Wed, 1 Feb 2023 14:49:23 +0900	[thread overview]
Message-ID: <CAMZ6RqJDARUjhDF5k1DydZMr=YWU9QSXDshTwznV4oh79a7niQ@mail.gmail.com> (raw)
In-Reply-To: <20230131160436.2vfszb3qqsyx3ea7@pengutronix.de>

On Wed. 1 Feb 2023 at 01:04, Marc Kleine-Budde <mkl@pengutronix.de> wrote:
> Finally I've found some time to look at this again...
>
> On 12.09.2022 17:28:15, Vincent Mailhol wrote:
> > Also, I was assuming that can_fixup_bittiming() was already doing the
> > out of range check:
> > https://elixir.bootlin.com/linux/v6.0-rc1/source/drivers/net/can/dev/bittiming.c#L27
> >
> > But in reality, only one of either can_calc_bittiming(),
> > can_fixup_bittiming() or can_validate_bitrate() is being called. And
> > thus, can_validate_bitrate() might be called with out of range values
> > and in that case the neltink interface should return -ERANGE (for
> > example if sjw > sjw_max).
> >
> > Sees that there is more work to do here than initially anticipated.
>
> I've converted the existing netdev_err() NL_SET_ERR_MSG_FMT(). This
> means the error message is transported via netlink to user space and
> printed by the "ip" tool.

I was not aware of this NL_SET_ERR_MSG_FMT() thing, and let me say
that I really like that solution!

> | # ip link set flexcan0 txqueuelen 10 type can bitrate 2200000
> | Warning: bitrate error 2.5%.

The Linux coding style says:

  Kernel messages do not have to be terminated with a period.

Ref: https://www.kernel.org/doc/html/latest/process/coding-style.html#printing-kernel-messages

However, I am not sure if this also applies to the ip tool.

> |
> | # ip link set flexcan0 txqueuelen 10 type can bitrate 22000000
> | Error: bitrate error 80.5% too high.
>
> This is the error message for the SJW check:
>
> | # ip link set flexcan0 txqueuelen 10 type can bitrate 500000 sjw 3
> | Error: SJW 3 bigger than phase_seg1 6 and/or phase_seg2 2.

At that point in the code, I assume that sjw was already validated
against sjw_max. While not impossible, I think that having sjw bigger
than both phase_seg1 and phase_seg2 at the same time is uncommon. I
suggest to split the error message in two and only print the relevant
one:

  Error: SJW 3 bigger than phase_seg1 x
  Error: SJW 3 bigger than phase_seg2 x

If the user still manages to violate both, only the phase_seg1 error
message is displayed.

> Maybe add a '=' between the phase_seg and the actual number:
>
> | Error: SJW 3 bigger than phase_seg1=6 and/or phase_seg2=2.

If you ask me my preferences, I will go with column:

  Error: SJW: 3 bigger than phase_seg1: 6 and/or phase_seg2: 2.

But I will not complain if you pick anything else.

  reply	other threads:[~2023-02-01  5:49 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
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 [this message]
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='CAMZ6RqJDARUjhDF5k1DydZMr=YWU9QSXDshTwznV4oh79a7niQ@mail.gmail.com' \
    --to=vincent.mailhol@gmail.com \
    --cc=Thomas.Kopp@microchip.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.