* Re: [PATCH can-next v2 1/4] can: bittiming: fix divide-by-zero in can_calc_bittiming()
[not found] <20261130-bittiming-fix-conversion-v2-1-36e8a0275923@pengutronix.de>
@ 2026-12-02 1:07 ` netdev-bot+sashiko
0 siblings, 0 replies; only message in thread
From: netdev-bot+sashiko @ 2026-12-02 1:07 UTC (permalink / raw)
To: mkl
Cc: mailhol, socketcan, wg, davem, kernel, linux-can, ssureshmsd7,
25031212351, stable, byu, wencheng, kuba
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 misstates where priv->bitrate_max comes from.
--
can: bittiming: fix divide-by-zero in can_calc_bittiming()
This commit fixes a divide error in can_calc_bittiming(). The divide
error happens when the 32 bit product tsegall * bt->bitrate wraps to
zero for large userspace bitrates. The fix computes the product with
mul_u32_u32() and divides with div64_u64().
> 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 this description of where priv->bitrate_max comes from accurate?
The "max-bitrate" device tree property is one source. Several drivers
also take it from the generic PHY transceiver:
drivers/net/can/flexcan/flexcan-core.c:flexcan_probe() {
...
priv->can.bitrate_max = transceiver->attrs.max_link_rate;
...
}
at91_can.c, m_can_platform.c and rcar_canfd.c do the same.
Some drivers also hard-code the value. etas_es58x sets 1 MBit/s for
es581_4 and 8 MBit/s for es58x_fd. dummy_can, the driver used for the
reproduction, sets:
drivers/net/can/dummy_can.c:dummy_can_init() {
...
priv->can.bitrate_max = 20 * MEGA /* BPS */;
...
}
So bitrate_max is non-zero on the reproduction driver. The second
argument in the paragraph still holds. can_changelink() calls
can_get_bittiming() before it checks the limit:
drivers/net/can/dev/netlink.c:can_changelink() {
...
err = can_get_bittiming(dev, &bt,
priv->bittiming_const,
...
if (priv->bitrate_max && bt.bitrate > priv->bitrate_max) {
...
}
The data bittiming path follows the same order.
The code change itself looks correct. Could the paragraph drop the "zero
for most drivers" reasoning and keep only the ordering argument?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-bittiming-fix-conversion-v2-0-36e8a0275923%40pengutronix.de
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-02 1:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261130-bittiming-fix-conversion-v2-1-36e8a0275923@pengutronix.de>
2026-12-02 1:07 ` [PATCH can-next v2 1/4] can: bittiming: fix divide-by-zero in can_calc_bittiming() netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox