From 21fb43532e80f7df62bc32baa3772fa3bb071cb4 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Tue, 15 Nov 2022 01:38:45 +0900 Subject: [PATCH] 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 Acked-by: Oliver Hartkopp Link: https://lore.kernel.org/all/20221114163848.3398-4-mailhol.vincent@wanadoo.fr Signed-off-by: Marc Kleine-Budde --- lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.c b/lib.c index 72afd79..ebad278 100644 --- a/lib.c +++ b/lib.c @@ -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]);