mirror of
git://git.openembedded.org/meta-openembedded
synced 2026-04-02 02:49:12 +00:00
can-utils: handle CAN_ERR_CNT correctly
If CAN_ERR_CNT is set, the snprintf_can_error_frame() bails out, as it cannot decode CAN_ERR_CNT. Signed-off-by: Jeroen Hofstee <jhofstee@victronenergy.com> Signed-off-by: Armin Kuster <akuster808@gmail.com>
This commit is contained in:
parent
923a8b73b8
commit
c1c33c3a4b
@ -0,0 +1,70 @@
|
||||
From 7d59157d4d570ba994f7dd07243ac5fb1c541410 Mon Sep 17 00:00:00 2001
|
||||
From: Marc Kleine-Budde <mkl@pengutronix.de>
|
||||
Date: Wed, 27 Sep 2023 16:15:52 +0200
|
||||
Subject: [PATCH] lib: snprintf_can_error_frame(): don't bail out if
|
||||
CAN_ERR_CNT is set
|
||||
|
||||
If CAN_ERR_CNT is set, the snprintf_can_error_frame() bails out, as it
|
||||
cannot decode CAN_ERR_CNT.
|
||||
|
||||
Fixes: 21fb43532e80 ("lib: snprintf_can_error_frame: print counter errors if CAN_ERR_CNT is set")
|
||||
|
||||
Upstream-Status: Backport [https://github.com/linux-can/can-utils/commit/7d59157d4d570ba994f7dd07243ac5fb1c541410]
|
||||
---
|
||||
lib.c | 23 +++++++++++++++++++----
|
||||
1 file changed, 19 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/lib.c b/lib.c
|
||||
index d665c69..0201e94 100644
|
||||
--- a/lib.c
|
||||
+++ b/lib.c
|
||||
@@ -499,6 +499,7 @@ static const char *error_classes[] = {
|
||||
"bus-off",
|
||||
"bus-error",
|
||||
"restarted-after-bus-off",
|
||||
+ "error-counter-tx-rx",
|
||||
};
|
||||
|
||||
static const char *controller_problems[] = {
|
||||
@@ -636,6 +637,19 @@ static int snprintf_error_prot(char *buf, size_t len, const struct canfd_frame *
|
||||
return n;
|
||||
}
|
||||
|
||||
+static int snprintf_error_cnt(char *buf, size_t len, const struct canfd_frame *cf)
|
||||
+{
|
||||
+ int n = 0;
|
||||
+
|
||||
+ if (len <= 0)
|
||||
+ return 0;
|
||||
+
|
||||
+ n += snprintf(buf + n, len - n, "{{%d}{%d}}",
|
||||
+ cf->data[6], cf->data[7]);
|
||||
+
|
||||
+ return n;
|
||||
+}
|
||||
+
|
||||
void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *cf,
|
||||
const char* sep)
|
||||
{
|
||||
@@ -679,13 +693,14 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c
|
||||
n += snprintf_error_ctrl(buf + n, len - n, cf);
|
||||
if (mask == CAN_ERR_PROT)
|
||||
n += snprintf_error_prot(buf + n, len - n, cf);
|
||||
+ if (mask == CAN_ERR_CNT)
|
||||
+ n += snprintf_error_cnt(buf + n, len - n, cf);
|
||||
classes++;
|
||||
}
|
||||
}
|
||||
|
||||
- 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]);
|
||||
+ if (!(cf->can_id & CAN_ERR_CNT) && (cf->data[6] || cf->data[7])) {
|
||||
+ n += snprintf(buf + n, len - n, "%serror-counter-tx-rx", sep);
|
||||
+ n += snprintf_error_cnt(buf + n, len - n, cf);
|
||||
}
|
||||
}
|
||||
--
|
||||
2.43.0
|
||||
|
||||
@ -6,6 +6,7 @@ DEPENDS = "libsocketcan"
|
||||
|
||||
SRC_URI = "git://github.com/linux-can/${BPN}.git;protocol=https;branch=master \
|
||||
file://0001-timestamp-formatting-always-use-64-bit-for-timestamp.patch \
|
||||
file://0001-lib-snprintf_can_error_frame-don-t-bail-out-if-CAN_E.patch \
|
||||
"
|
||||
|
||||
SRCREV = "cfe41963f3425e9adb01a70cfaddedf5e5982720"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user