[PATCH can-utils-dev v2 3/5] lib: snprintf_can_error_frame: print counter errors if CAN_ERR_CNT is set

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since [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.

For interoperability reasons, use an #ifdef so that the code still
work if built 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




[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux