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, ssureshmsd7@gmail.com,
	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 v2 3/4] can: bittiming: can_update_sample_point(): fix sample point error calculation on unsigned operands
Date: Wed, 02 Dec 2026 01:07:38 +0000	[thread overview]
Message-ID: <179617365866.3142.11965848914227822369@kernel.org> (raw)
In-Reply-To: <20261130-bittiming-fix-conversion-v2-3-36e8a0275923@pengutronix.de>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message claims a bug that does not exist.

--

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

This commit changes the sample point error calculation in
can_update_sample_point() from abs(sample_point_reference - sample_point)
to abs_diff(sample_point_reference, sample_point). The commit message
says the old code turned a wrapped unsigned difference into a small
positive value instead of a large error.

> 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: Low]
This isn't a bug, but is this description accurate for
can_update_sample_point()?

For an unsigned int argument, abs() in include/linux/math.h does this:

    ({ signed type __x = (x); __x < 0 ? -__x : __x; })

So a wrapped result such as 875 - 880 becomes (int)-5, and abs() returns
5. That is the correct magnitude, not a misrepresented error. The
magnitude would only come out wrong if the real difference were larger
than INT_MAX.

> diff --git a/drivers/net/can/dev/calc_bittiming.c b/drivers/net/can/dev/calc_bittiming.c
> index 2789b99ab6a83..f081819fd8f90 100644
> --- a/drivers/net/can/dev/calc_bittiming.c
> +++ b/drivers/net/can/dev/calc_bittiming.c
> @@ -73,7 +73,7 @@ can_update_sample_point(const struct can_bittiming_const *btc,
>  
>  		sample_point = 1000 * (tseg + CAN_SYNC_SEG - tseg2) /
>  			(tseg + CAN_SYNC_SEG);
> -		sample_point_error = abs(sample_point_reference - sample_point);
> +		sample_point_error = abs_diff(sample_point_reference, sample_point);
>  
>  		if (sample_point <= sample_point_reference &&
>  		    sample_point_error < best_sample_point_error) {

Also, sample_point_error is only used inside this guarded branch. There,
sample_point <= sample_point_reference holds, so the unsigned subtraction
cannot wrap. When sample_point > sample_point_reference, the value is
thrown away. Only best_sample_point_error is written to
*sample_point_error_ptr.

sample_point_reference is also always below 1000. It comes either from
bt->sample_point, which can_validate_bittiming() rejects when it is
>= 1000:

    if (bt->sample_point >= 1000) {

or from the constant tables in can_calc_sample_point_nrz() and
can_calc_sample_point_pwm().

So in every case where the result is used, the old and new code give the
same value. The switch to abs_diff() looks like a correct cleanup that
matches the earlier bitrate error change. The rationale from that change
does not seem to carry over here.

Could the subject and body say this is a consistency cleanup with no
functional change, rather than a fix? That would avoid stable or AUTOSEL
picking it up as a bug fix. It would also avoid suggesting that sample
point selection was broken before.

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

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

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 11:13 [PATCH can-next v2 0/4] can: bittiming: fix defects in the userspace bit rate conversion and reject invalid timing constants Marc Kleine-Budde
2026-11-30 11:13 ` [PATCH can-next v2 1/4] can: bittiming: fix divide-by-zero in can_calc_bittiming() Marc Kleine-Budde
2026-12-02  1:07   ` netdev-bot+sashiko
2026-11-30 11:13 ` [PATCH can-next v2 2/4] can: bittiming: fix bitrate error calculation on unsigned operands Marc Kleine-Budde
2026-11-30 11:13 ` [PATCH can-next v2 3/4] can: bittiming: can_update_sample_point(): fix sample point " Marc Kleine-Budde
2026-12-02  1:07   ` netdev-bot+sashiko [this message]
2026-11-30 11:13 ` [PATCH can-next v2 4/4] can: dev: reject unusable bit-timing constants Marc Kleine-Budde
2026-11-30 11:25   ` sashiko-bot
2026-11-30 13:07     ` Marc Kleine-Budde
2026-12-02  1: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=179617365866.3142.11965848914227822369@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=ssureshmsd7@gmail.com \
    --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