Commit Graph

994 Commits (39d6bba36aafe5fe68a5e290180ac4de5dbca4a0)

Author SHA1 Message Date
Marc Kleine-Budde 144d77180e cangen: checkpatch: don't split strings over multiple lines
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 213a814da6 cangen: don't compare floating-point gap with ‘==’
Fixes the following warning:

| cangen.c:524:7: warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe [-Wfloat-equal]
|   524 |   if (gap && burst_sent_count >= burst_count) /* gap == 0 => performance test :-] */
|       |       ^~~

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:26:42 +01:00
Marc Kleine-Budde a18337b102
Merge pull request #387 from marckleinebudde/can-calc-bit-timing
can-calc-bit-timing: fix various compiler warnings
2022-12-07 15:22:51 +01:00
Marc Kleine-Budde 0b3112edf2 can-calc-bit-timing: remove const from printf_btr functions to silence warning on clang
Fixes: 9b63929974 ("can-calc-bit-timing: mark several structs and members as const")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:08:59 +01:00
Marc Kleine-Budde 74897b69c3 can-calc-bit-timing: silence "comparison of integer expressions of different signedness" warning
Silence the "comparison of integer expressions of different
signedness" warning. We want to compile the code as is from the
kernel, including bugs.

| calc-bit-timing/can-calc-bit-timing-v2_6_31.c: In function ‘can_update_spt_v2_6_31’:
| calc-bit-timing/can-calc-bit-timing-v2_6_31.c:51:13: warning: comparison of integer expressions of different signedness: ‘int’ and ‘__u32’ {aka ‘const unsigned int’} [-Wsign-compare]

Fixes: 18eb0ab784 ("can-calc-bit-timing: import bit timing calculation algorithm from v4.8")
Fixes: b777ce2e6d ("can-calc-bit-timing: import bit timing calculation algorithm from v3.18")
Fixes: c1f5dc53ec ("can-calc-bit-timing: import bit timing calculation algorithm from v2.6.31")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 14:50:02 +01:00
Marc Kleine-Budde 9177294093 Merge patch series "can-utils-dev: a set of update and cleanup patches"
Vincent Mailhol <mailhol.vincent@wanadoo.fr> says:

This series contain cleanup patches and update of header files. There
is no real relation between each patch (aside of 2/6 and 3/6 which
form a pair) so I will end the cover letter here and let you refer to
the short description.

* Changelog *

v2 -> v3:

  * reorder the patches so that related changes are next to each
    other (especially patch 2/6 and 3/6).

  * patch 2/6: new patch to update include/linux/can/error.h with the
    latest hearder from Linux 6.0.0.

  * patch 3/6: do not use an #ifdef anymore and make sure that the
    code still work if run on old kernel version lower than 6.0.0.

  * patch 6/6: rewrite commit description to point out that there is a
    local copy of the linux headers under include/linux/.

v1 -> v2:

  * patch 2/5: add a note in commit message to explain that slcanpty.c
    debug is deactivated by default.

  * patch 2/5: make the compiler check the pr_debug() syntax even if
    debug is off.

  * reorder the patches so that the lib.c and the candump.c patches
    are next to each other in the series.

Link: https://lore.kernel.org/all/20221114163848.3398-1-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 10:14:47 +01:00
Vincent Mailhol 4764212483 candump: use linux/net_tstamp.h instead of redefining values ourselves
The project contains a local copy of the timestamp header at
include/linux/net_tstamp.h. However, candump.c redefines the
net_tstamp.h values instead of relying on the header.

Replace these by a "include <linux/net_tstamp.h>".

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-7-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:49:52 +01:00
Vincent Mailhol 8e45fc5158 candump: add global variable progname
Instead of using argv[0] several time, make the progname a global
variable.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-6-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:49:52 +01:00
Vincent Mailhol 0cfd56d613 lib: add pr_debug() macro
Add the pr_debug() macro so that:

  #ifdef DEBUG
  	printf("foo");
  #endif

can be replaced by:

  	pr_debug("foo");

Apply the pr_debug() macro wherever relevant.

Currently, there is no consensus whether debug messages should be
printed on stdout or stderr. Most of the modules: canbusload.c,
candump.c and canlogserver.c use stdout but
mcp251xfd/mcp251xfd-dev-coredump.c uses stderr. Harmonize the behavior
by following the major trend and make
mcp251xfd/mcp251xfd-dev-coredump.c also output to stdout.

slcanpty.c does a #define DEBUG, meaning that debug is always turned
on for this file. Remove this and make debug an option like every
other files.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-5-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:49:52 +01:00
Vincent Mailhol 21fb43532e 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 <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-4-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:44:51 +01:00
Vincent Mailhol f3ce3efe66 include: update linux/can/error.h
Update the linux/can/error.h hearder to incorporate the changes made
in Linux 6.0.0. Namely:

  - commit 3e5c291c7942 ("can: add CAN_ERR_CNT flag to notify
    availability of error counter")
    Link: https://git.kernel.org/torvalds/linux/c/3e5c291c7942

  - commit 3f9c26210cf8 ("can: error: add definitions for the
    different CAN error thresholds")
    Link: https://git.kernel.org/torvalds/linux/c/3f9c26210cf8

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-3-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:44:51 +01:00
Vincent Mailhol 4c9f046615 slcanpty: remove redundant asc2nibble()
asc2nibble() is already defined in lib.h. Include lib.h in slcnpty.c
so that asc2nibble() does not need to be redefined a second time and
adjust the Makefile accordingly.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-2-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:44:51 +01:00
Marc Kleine-Budde 71a0156bd5
Merge pull request #380 from marckleinebudde/fix-fname-scope
candump: main(): fix scope of fname
2022-09-29 12:50:05 +02:00
Marc Kleine-Budde e54d677999 candump: main(): fix scope of fname
Reported-by: https://github.com/HBLocker
Link: https://github.com/linux-can/can-utils/issues/379
2022-09-29 12:47:17 +02:00
Marc Kleine-Budde 2b3b5c498f
Merge pull request #378 from RICCIARDI-Adrien/canfdtest_add_extended_frame_format_support
canfdtest: Add extended frame format support
2022-09-09 11:28:19 +02:00
RICCIARDI-Adrien 8e66a0bae3 canfdtest: Add extended frame format support
Added the '-e' command line option to enable 29-bit CAN ID.

Signed-off-by: RICCIARDI-Adrien <adrien.ricciardi@hotmail.fr>
2022-09-09 11:01:43 +02:00
Marc Kleine-Budde e602e391a5
Merge pull request #376 from marckleinebudde/fix-candump
candump: fix HW timestamps + dropcount
2022-08-28 00:21:27 +02:00
Marc Kleine-Budde 2b5e93744b candump: reserve enough space for ctrlmsg
The ctrlmsg must be large enough to contains 3 elements of various
sizes, not a single element of the sum of the size.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-27 23:26:39 +02:00
Marc Kleine-Budde 0d26ba9ea3 candump: print number of dropped frames as unsigned values
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-27 23:25:18 +02:00
Marc Kleine-Budde 5736818292
Merge pull request #375 from jhofstee/fix_snprintf_error_data
lib: fix seperator in snprintf_error_data
2022-08-17 17:11:34 +02:00
Jeroen Hofstee 3bb412e072 lib: fix seperator in snprintf_error_data
When multiple error flags are set, snprintf_error_data created a comma
seperated textual presentation of it. Commit ef853f5553 ("added return value
check of snprintf to prevent possible buffer overflows detected by CodeQL")
removed the increment of count, so the delimiter is no longer added. Fix this
by incrementing count again.

Fixes: Commit ef853f5553 ("added return value check of snprintf to prevent possible buffer overflows detected by CodeQL")
Signed-off-by: Jeroen Hofstee <jhofstee@victronenergy.com>
2022-08-17 16:57:26 +02:00
Marc Kleine-Budde f020f563e7
Merge pull request #374 from marckleinebudde/fix-android
Android.mk: fix compilation of can-calc-bit-timing
2022-08-17 11:54:50 +02:00
Marc Kleine-Budde e0945d867e CMakeLists: fix compilation of can-calc-bit-timing
Fixes: 9c38c16437 ("can-calc-bit-timing: move into subdir")
Reported-by: Tompee Balauag <tompee26@gmail.com>
Link: https://github.com/linux-can/can-utils/issues/373
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-17 11:39:16 +02:00
Marc Kleine-Budde f81ce85730 Android.mk: fix compilation of can-calc-bit-timing
Fixes: 9c38c16437 ("can-calc-bit-timing: move into subdir")
Reported-by: Tompee Balauag <tompee26@gmail.com>
Link: https://github.com/linux-can/can-utils/issues/373
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-17 09:07:01 +02:00
Marc Kleine-Budde a44238c9e2
Merge pull request #372 from marckleinebudde/calc-bit-timing
improve can-calc-bittiming
2022-08-12 15:16:02 +02:00
Marc Kleine-Budde 7e2010a1c0 can-calc-bit-timing: import bit timing calculation algorithm from v5.19
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 22:42:16 +02:00
Marc Kleine-Budde 0654d4e711 can-calc-bit-timing: import bit timing calculation algorithm from v5.16
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 22:42:16 +02:00
Marc Kleine-Budde 18eb0ab784 can-calc-bit-timing: import bit timing calculation algorithm from v4.8
The bit timing algorithm is not identical with the referenced commit.
So re-import from that commit.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 22:25:51 +02:00
Marc Kleine-Budde b777ce2e6d can-calc-bit-timing: import bit timing calculation algorithm from v3.18
add missing can_fixup_bittiming()

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 22:25:16 +02:00
Marc Kleine-Budde c1f5dc53ec can-calc-bit-timing: import bit timing calculation algorithm from v2.6.31
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 22:24:43 +02:00
Marc Kleine-Budde ee2f48f33b can-calc-bit-timing: move algorithms into separate files
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 21:47:47 +02:00
Marc Kleine-Budde a7062893da can-calc-bit-timing: add can_fixup_bittiming to alg
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 21:45:50 +02:00
Marc Kleine-Budde cfc3030080 can-calc-bit-timing: prepare for more algos
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 21:25:40 +02:00
Marc Kleine-Budde 9c38c16437 can-calc-bit-timing: move into subdir
The source file will be split into several files in the next patches.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 20:34:40 +02:00
Marc Kleine-Budde 258f357814 can-calc-bit-timing: add information if printing data bit timing table
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 20:34:40 +02:00
Marc Kleine-Budde ab2b11d9a8 can-calc-bit-timing: add new ref_clk to xilinx_can_fd2
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 20:34:40 +02:00
Marc Kleine-Budde 710fc99961 can-calc-bit-timing: add new ref_clk to mcp2515
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 20:34:40 +02:00
Marc Kleine-Budde 104e3f97a0 can-calc-bit-timing: add new ref_clk to mcan
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 20:34:39 +02:00
Marc Kleine-Budde 2b2d38d06b can-calc-bit-timing: fix indention
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 16:35:59 +02:00
Marc Kleine-Budde 75291c2a88 can-calc-bit-timing: common_bitrates: add more bitrates
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-11 16:35:59 +02:00
Marc Kleine-Budde cad1cecf1c
Merge pull request #370 from weichslgartner/master
fix for issue #369
2022-07-04 14:43:57 +02:00
weichslgartner da0326ffc6 fix for issue #369
adding cast preventing int/unsigned comparison (-Wsign-compare warning in lib.c)
2022-06-30 18:40:07 +02:00
Marc Kleine-Budde cfe13a4c7d
Merge pull request #368 from RICCIARDI-Adrien/canfdtest_add_message_length_support
canfdtest: Add message length support
2022-06-28 10:50:52 +02:00
RICCIARDI-Adrien b8af5a6031 canfdtest: Add message length support
Added the '-s' command line option to set the frame payload length in bytes.

Signed-off-by: RICCIARDI-Adrien <adrien.ricciardi@hotmail.fr>
2022-06-27 23:49:02 +02:00
Marc Kleine-Budde 5e06623b3d
Merge pull request #366 from RICCIARDI-Adrien/canfdtest_add_bit_rate_switch_support
canfdtest: Add CAN FD Bit Rate Switch support
2022-06-22 11:34:09 +02:00
RICCIARDI-Adrien 6d3bf51e0a canfdtest: Add CAN FD Bit Rate Switch support
Added the '-b' command line option, to be used in conjunction with the '-d'
option that enables CAN FD, to set the BRS bit in a CAN FD frame. When
enabled, the data part of the CAN FD frame is transmitted at a higher speed.
All remaining parts of the CAN FD frame use the classic CAN speed.

Signed-off-by: RICCIARDI-Adrien <adrien.ricciardi@hotmail.fr>
2022-06-22 10:50:12 +02:00
Marc Kleine-Budde 2b0ed067dd
Merge pull request #321 from weichslgartner/master
Fixed some undefined behavior and added CodeQL workflow
2022-06-20 19:40:36 +02:00
weichslgartner ef853f5553 added return value check of snprintf to prevent possible buffer overflows detected by CodeQL 2022-06-20 19:22:11 +02:00
weichslgartner eb2b38790a fixes undefined behavior in parse_canframe (lib.c:187) by chaning tmp to
canid_t

Issue:
mkdir build && cd build
CC=clang cmake -DCMAKE_C_FLAGS="-fsanitize=address,undefined"
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined" .. && cmake
--build .

 echo "(0.0) can1 ffffffff#00000000" | ./log2long
can-utils/lib.c:187:23: runtime error: left shift of 15 by 28 places
cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
/can-utils/lib.c:187:23 in
(0.0)  can1  3FFFFFFF
2022-06-20 19:11:00 +02:00
Marc Kleine-Budde bace2e7d73
Merge pull request #365 from RICCIARDI-Adrien/canfdtest_add_can_fd_support
canfdtest: Add CAN FD support
2022-06-20 18:30:14 +02:00