From: Oliver Hartkopp <socketcan@hartkopp.net>
To: linux-can@vger.kernel.org
Cc: Oliver Hartkopp <socketcan@hartkopp.net>,
Vincent Mailhol <mailhol@kernel.org>
Subject: [canxl v7 17/17] can: dev: print bitrate error with two decimal digits
Date: Tue, 25 Nov 2025 13:38:59 +0100 [thread overview]
Message-ID: <20251125123859.3924-18-socketcan@hartkopp.net> (raw)
In-Reply-To: <20251125123859.3924-1-socketcan@hartkopp.net>
Increase the resolution when printing the bitrate error and round-up the
value to 0.01% in the case the resolution would still provide values
which would lead to 0.00%.
Suggested-by: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
drivers/net/can/dev/calc_bittiming.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/net/can/dev/calc_bittiming.c b/drivers/net/can/dev/calc_bittiming.c
index 0b11c4e98172..e232993a5138 100644
--- a/drivers/net/can/dev/calc_bittiming.c
+++ b/drivers/net/can/dev/calc_bittiming.c
@@ -150,23 +150,26 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,
if (bitrate_error == 0 && sample_point_error == 0)
break;
}
if (best_bitrate_error) {
- /* Error in one-tenth of a percent */
- v64 = (u64)best_bitrate_error * 1000;
+ /* Error in one-hundredth of a percent */
+ v64 = (u64)best_bitrate_error * 10000;
do_div(v64, bt->bitrate);
bitrate_error = (u32)v64;
+ /* print at least 0.01% if the error is smaller */
+ bitrate_error = max(bitrate_error, 1U);
if (bitrate_error > CAN_CALC_MAX_ERROR) {
NL_SET_ERR_MSG_FMT(extack,
- "bitrate error: %u.%u%% too high",
- bitrate_error / 10, bitrate_error % 10);
+ "bitrate error: %u.%02u%% too high",
+ bitrate_error / 100,
+ bitrate_error % 100);
return -EINVAL;
}
NL_SET_ERR_MSG_FMT(extack,
- "bitrate error: %u.%u%%",
- bitrate_error / 10, bitrate_error % 10);
+ "bitrate error: %u.%02u%%",
+ bitrate_error / 100, bitrate_error % 100);
}
/* real sample point */
bt->sample_point = can_update_sample_point(btc, sample_point, best_tseg,
&tseg1, &tseg2, NULL);
--
2.47.3
next prev parent reply other threads:[~2025-11-25 12:39 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-25 12:38 [canxl v7 00/17] can: netlink: add CAN XL support Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 01/17] can: dev: can_get_ctrlmode_str: use capitalized ctrlmode strings Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 02/17] can: bittiming: apply NL_SET_ERR_MSG() to can_calc_bittiming() Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 03/17] can: dev: can_dev_dropped_skb: drop CAN FD skbs if FD is off Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 04/17] can: netlink: add CAN_CTRLMODE_RESTRICTED Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 05/17] can: netlink: add initial CAN XL support Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 06/17] can: netlink: add CAN_CTRLMODE_XL_TMS flag Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 07/17] can: dev: can_dev_dropped_skb: drop CC/FD frames in CANXL-only mode Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 08/17] can: bittiming: add PWM parameters Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 09/17] can: bittiming: add PWM validation Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 10/17] can: calc_bittiming: add PWM calculation Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 11/17] can: netlink: add PWM netlink interface Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 12/17] can: calc_bittiming: get rid of the incorrect "nominal" word Oliver Hartkopp
2025-11-26 10:14 ` Marc Kleine-Budde
2025-11-25 12:38 ` [canxl v7 13/17] can: calc_bittiming: add can_calc_sample_point_nrz() Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 14/17] can: calc_bittiming: add can_calc_sample_point_pwm() Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 15/17] can: add dummy_can driver Oliver Hartkopp
2025-11-25 12:38 ` [canxl v7 16/17] can: raw: instantly reject unsupported CAN frames Oliver Hartkopp
2025-11-25 12:38 ` Oliver Hartkopp [this message]
2025-11-25 16:13 ` [canxl v7 00/17] can: netlink: add CAN XL support Rakuram Eswaran
2025-11-25 16:59 ` Oliver Hartkopp
2025-11-26 18:37 ` Rakuram Eswaran
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=20251125123859.3924-18-socketcan@hartkopp.net \
--to=socketcan@hartkopp.net \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
/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