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@xxxxxxxxxx> --- lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.c b/lib.c index 3c1a0d9..0f9b510 100644 --- a/lib.c +++ b/lib.c @@ -679,7 +679,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]); -- 2.37.4