Skip to content

Commit b360a13

Browse files
hartkoppmarckleinebudde
authored andcommitted
can: dev: print bitrate error with two decimal digits
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 <[email protected]> Signed-off-by: Oliver Hartkopp <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 1a620a7 commit b360a13

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/net/can/dev/calc_bittiming.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,22 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,
153153
}
154154

155155
if (best_bitrate_error) {
156-
/* Error in one-tenth of a percent */
157-
v64 = (u64)best_bitrate_error * 1000;
156+
/* Error in one-hundredth of a percent */
157+
v64 = (u64)best_bitrate_error * 10000;
158158
do_div(v64, bt->bitrate);
159159
bitrate_error = (u32)v64;
160+
/* print at least 0.01% if the error is smaller */
161+
bitrate_error = max(bitrate_error, 1U);
160162
if (bitrate_error > CAN_CALC_MAX_ERROR) {
161163
NL_SET_ERR_MSG_FMT(extack,
162-
"bitrate error: %u.%u%% too high",
163-
bitrate_error / 10, bitrate_error % 10);
164+
"bitrate error: %u.%02u%% too high",
165+
bitrate_error / 100,
166+
bitrate_error % 100);
164167
return -EINVAL;
165168
}
166169
NL_SET_ERR_MSG_FMT(extack,
167-
"bitrate error: %u.%u%%",
168-
bitrate_error / 10, bitrate_error % 10);
170+
"bitrate error: %u.%02u%%",
171+
bitrate_error / 100, bitrate_error % 100);
169172
}
170173

171174
/* real sample point */

0 commit comments

Comments
 (0)