Linux CAN drivers development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: mkl@pengutronix.de
Cc: mailhol@kernel.org, socketcan@hartkopp.net, wg@grandegger.com,
	davem@davemloft.net, kernel@pengutronix.de,
	linux-can@vger.kernel.org, 25031212351@stu.xidian.edu.cn,
	stable@vger.kernel.org, byu@xidian.edu.cn,
	wencheng@xidian.edu.cn, kuba@kernel.org
Subject: Re: [PATCH can-next v3 3/6] can: bittiming: can_update_sample_point(): fix sample point error calculation on unsigned operands
Date: Wed, 02 Dec 2026 02:07:55 +0000	[thread overview]
Message-ID: <179617727537.3142.7162137065977769300@kernel.org> (raw)
In-Reply-To: <20261130-bittiming-fix-conversion-v3-3-e61f92dc76d0@pengutronix.de>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The commit message says this patch fixes a bug, but the change
  does nothing at this call site.

--

can: bittiming: can_update_sample_point(): fix sample point error calculation on unsigned operands

This commit replaces abs(sample_point_reference - sample_point) with
abs_diff(sample_point_reference, sample_point) in
can_update_sample_point(). The commit message presents this as a fix for a
wrapped unsigned difference that gets reinterpreted as a small positive
value.

> can: bittiming: can_update_sample_point(): fix sample point error calculation on unsigned operands
>
> can_update_sample_point() rates each candidate against the requested
> sample point with:
>
>         sample_point_error = abs(sample_point_reference - sample_point);
>
> Both operands are unsigned int, so the subtraction wraps instead of
> becoming negative, and abs() resolves an unsigned int argument to its
> int branch. A wrapped difference is therefore reinterpreted as a small
> positive value instead of the large error it actually represents.

[Severity: Medium]
Does this description match what happens in can_update_sample_point()?
As far as I can tell, the old and new expressions give the same result in
every case where sample_point_error is actually used.

The error for each candidate is only kept when the candidate is at or
below the reference:

    if (sample_point <= sample_point_reference &&
        sample_point_error < best_sample_point_error) {

In that case the subtraction cannot wrap.

sample_point_reference is also always below 1000. It is either
bt->sample_point, which can_validate_bittiming() in
drivers/net/can/dev/netlink.c bounds:

    if (bt->sample_point >= 1000) {
        NL_SET_ERR_MSG(extack, "sample point must be between 0 and 100%");
        return -EINVAL;
    }

or it is a fixed default from can_calc_sample_point_nrz() or
can_calc_sample_point_pwm(). So the difference never gets close to
INT_MAX. That is the only range where the int branch of abs() would
return a wrong magnitude.

When sample_point > sample_point_reference the subtraction does wrap.
Casting it to int still gives the correct small value, not a "large
error". The check above also rejects that candidate.

The wording looks like it was carried over from the previous commit "can:
bittiming: can_calc_bittiming(): fix bitrate error calculation on unsigned
operands". There, bt->bitrate can be close to UINT_MAX, so the difference
can exceed INT_MAX. That reasoning doesn't seem to apply to the sample
point.

Could this be described as a consistency cleanup with "No functional
change intended" instead of a fix? Other fixes in this series are marked
for stable, so a "fix" subject here could get this patch selected for
stable backports. Later patches in the series don't change this.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-bittiming-fix-conversion-v3-0-e61f92dc76d0%40pengutronix.de

  reply	other threads:[~2026-12-02  2:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 13:06 [PATCH can-next v3 0/6] can: bittiming: fix defects in the userspace bit rate conversion and reject invalid timing constants Marc Kleine-Budde
2026-11-30 13:06 ` [PATCH can-next v3 1/6] can: bittiming: can_calc_bittiming(): fix potential divide-by-zero Marc Kleine-Budde
2026-12-02  2:07   ` netdev-bot+sashiko
2026-11-30 13:06 ` [PATCH can-next v3 2/6] can: bittiming: can_calc_bittiming(): fix bitrate error calculation on unsigned operands Marc Kleine-Budde
2026-12-02  2:07   ` netdev-bot+sashiko
2026-11-30 13:06 ` [PATCH can-next v3 3/6] can: bittiming: can_update_sample_point(): fix sample point " Marc Kleine-Budde
2026-12-02  2:07   ` netdev-bot+sashiko [this message]
2026-11-30 13:06 ` [PATCH can-next v3 4/6] can: bittiming: register_candev(): reject unusable bit-timing constants Marc Kleine-Budde
2026-12-02  2:07   ` netdev-bot+sashiko
2026-11-30 13:06 ` [PATCH can-next v3 5/6] can: bittiming: can_bittiming_const_valid(): reject unusable BRP bit timing constant Marc Kleine-Budde
2026-12-02  2:07   ` netdev-bot+sashiko
2026-11-30 13:06 ` [PATCH can-next v3 6/6] can: bittiming: can_fixup_bittiming(): reject too high values for prop-seg/phase-seg1 Marc Kleine-Budde
2026-12-02  2:07   ` netdev-bot+sashiko

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=179617727537.3142.7162137065977769300@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=25031212351@stu.xidian.edu.cn \
    --cc=byu@xidian.edu.cn \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=socketcan@hartkopp.net \
    --cc=stable@vger.kernel.org \
    --cc=wencheng@xidian.edu.cn \
    --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