Since [1], the kernel has a new flag: CAN_ERR_CNT to notify whether or not the errour counter is set. Use this to decide whether on not the error-counter-tx-rx should be printed. For interoperability reasons, use an #ifdef so that the code still work on older kernels. [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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib.c b/lib.c index 3c1a0d9..fb08c0b 100644 --- a/lib.c +++ b/lib.c @@ -679,7 +679,11 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c } } +#ifdef CAN_ERR_CNT + if (cf->can_id & CAN_ERR_CNT) { +#else if (cf->data[6] || cf->data[7]) { +#endif 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