lib: snprintf_can_error_frame: print counter errors if CAN_ERR_CNT is set

Since version 6.0.0 (specifically [1]), the kernel has a new flag:
CAN_ERR_CNT to notify whether or not the error counter is set. Use
this to decide whether on not the error-counter-tx-rx should be
printed.

This way, when a driver set data[6] and data[7] to zero, it is
possible to differentiate whether the error counter is not available
or if the drivers simply reported both counters to be zero.

For interoperability reasons, continue to check data[6] and data[7]
against zero so that the code still works with the old behavior if
run on a kernel version lower than 6.0.0.

[1] commit 3e5c291c7942 ("can: add CAN_ERR_CNT flag to notify
    availability of error counter")
Link: https://git.kernel.org/torvalds/linux/c/3e5c291c7942

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-4-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
pull/387/head
Vincent Mailhol 2022-11-15 01:38:45 +09:00 committed by Marc Kleine-Budde
parent f3ce3efe66
commit 21fb43532e
1 changed files with 1 additions and 1 deletions

2
lib.c
View File

@ -680,7 +680,7 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c
}
}
if (cf->data[6] || cf->data[7]) {
if (cf->can_id & CAN_ERR_CNT || cf->data[6] || cf->data[7]) {
n += snprintf(buf + n, len - n, "%s", sep);
n += snprintf(buf + n, len - n, "error-counter-tx-rx{{%d}{%d}}",
cf->data[6], cf->data[7]);