Skip to content

Commit d536e6e

Browse files
can: fix failing assertion and counter in CAN mode
This patch fixes the following assertion: microcom: can.c:63: can_write: Assertion `err < count' failed. #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 #1 0x00007ffff7db6535 in __GI_abort () at abort.c:79 #2 0x00007ffff7db640f in __assert_fail_base (fmt=0x7ffff7f18ee0 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55555555c3f3 "err < count", file=0x55555555c3d3 "can.c", line=63, function=<optimized out>) at assert.c:92 #3 0x00007ffff7dc4102 in __GI___assert_fail (assertion=assertion@entry=0x55555555c3f3 "err < count", file=file@entry=0x55555555c3d3 "can.c", line=line@entry=63, function=function@entry=0x55555555c440 <__PRETTY_FUNCTION__.4646> "can_write") at assert.c:101 #4 0x0000555555559cff in can_write (ios=0x555555560260, buf=0x7fffffffdb30, count=1) at can.c:63 #5 can_write (ios=0x555555560260, buf=0x7fffffffdb30, count=1) at can.c:42 #6 0x00005555555584d9 in cook_buf (num=1, buf=0x7fffffffdb30 "t", ios=<optimized out>) at mux.c:390 #7 mux_loop (ios=0x555555560260) at mux.c:479 #8 0x00005555555565e2 in main (argc=3, argv=0x7fffffffe2c8) at microcom.c:330 The write call returns the size of the whole CAN frame, which is sizeof(struct can_frame), regardless of the length of the data. Use this in the assertion. For the same reason, we have to use struct can_frame::can_dlc as the couter of sent bytes. This patch also fixes that problem. Fixes: dc0d7aa ("can: Get rid of pthread for can transfers") Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent c6d5e12 commit d536e6e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

can.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ static ssize_t can_write(struct ios_ops *ios, const void *buf, size_t count)
6060
if (err < 0)
6161
return err;
6262

63-
assert(err < count);
64-
buf += err;
65-
count -= err;
66-
ret += err;
63+
assert(err == sizeof(to_can));
64+
buf += loopcount;
65+
count -= loopcount;
66+
ret += loopcount;
6767
}
6868

6969
return ret;

0 commit comments

Comments
 (0)