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 1/6] can: bittiming: can_calc_bittiming(): fix potential divide-by-zero
Date: Wed, 02 Dec 2026 02:07:52 +0000	[thread overview]
Message-ID: <179617727289.3142.10542530065267570578@kernel.org> (raw)
In-Reply-To: <20261130-bittiming-fix-conversion-v3-1-e61f92dc76d0@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 is inaccurate about where priv->bitrate_max
  comes from.

--

can: bittiming: can_calc_bittiming(): fix potential divide-by-zero

This patch fixes a divide-by-zero in can_calc_bittiming(). The 32-bit
product tsegall * bt->bitrate can wrap to zero for a bitrate supplied by
userspace. It now uses check_mul_overflow() and skips any tseg value
whose divisor would overflow an unsigned int.

Closes: https://sashiko.dev/#/bug/linux-880c95de-8fd9-4e53-8531-985d9b140f44

> priv->bitrate_max cannot guard against this: it is populated from the
> optional "max-bitrate" device tree property, so it is zero for most
> drivers, and can_changelink() only consults it after can_get_bittiming()
> has already returned.

[Severity: Low]

Is the description of where bitrate_max comes from accurate?

of_can_transceiver() in drivers/net/can/dev/dev.c does read the
"max-bitrate" property. Several drivers also set the field in other ways.

dummy_can, the driver used for the reproducer, hard-codes it:

drivers/net/can/dummy_can.c:dummy_can_init() {
    ...
	priv->can.bitrate_max = 20 * MEGA /* BPS */;
    ...
}

at91_can, flexcan, m_can_platform and rcar_canfd copy it from the PHY
transceiver:

	priv->can.bitrate_max = transceiver->attrs.max_link_rate;

etas_es58x sets it from static values (1 * MEGA in es581_4.c, 8 * MEGA in
es58x_fd.c).

The ordering argument still holds. can_changelink() checks bitrate_max
only after can_get_bittiming() has returned:

drivers/net/can/dev/netlink.c:can_changelink() {
    ...
		err = can_get_bittiming(dev, &bt,
					priv->bittiming_const,
					priv->bitrate_const,
					priv->bitrate_const_cnt,
					extack);
		if (err)
			return err;

		if (priv->bitrate_max && bt.bitrate > priv->bitrate_max) {
    ...
}

Could the paragraph keep just the ordering argument, or describe the other
places where bitrate_max is set?

-- 
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 [this message]
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
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=179617727289.3142.10542530065267570578@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