Commit Graph

1012 Commits (ceda93bd5c56927c72d48dcaa30e17d6ecea86b8)

Author SHA1 Message Date
Marc Kleine-Budde 96309409c2
Merge pull request #388 from marckleinebudde/fix-warnings
fix warnings
2022-12-07 16:40:08 +01:00
Marc Kleine-Budde 7e8cfac0de j1939cat: j1939cat_send(): fix uninitialized variable 2022-12-07 16:35:44 +01:00
Marc Kleine-Budde 0b84a782c2 mcp251xfd-dump: fix comparison of integer expressions of different signedness warning
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 16:32:41 +01:00
Marc Kleine-Budde abbd47bd09
Merge pull request #386 from marckleinebudde/cangen-cleanups
cangen cleanups
2022-12-07 15:38:01 +01:00
Marc Kleine-Budde b6a65b8105 cangen: sort getopt() by order of option in usage
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 99686af630 cangen: print_usage() don't hardcode default burst size
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 4b6f8d62dd cangen: move scope of variable ret
... so that it can be used in other parts of the main() functions, too.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 8fb0e954b3 cangen: remove unneeded masking
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 29b05de39d cangen: mark setsockopt() options as const
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 1f96d674c0 cangen: use if_nametoindex() to avoid overflows
This patch replaces strcpy() + ioctl() by if_nametoindex() to avoid
overflows caused by long user input.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 0f7c1aa23a cangen: use consistent indention scheme of 1 space
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde a130ab5e8d cangen: mark functions as static
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 11a0f19244 cangen: properly initialize struct sockaddr_can addr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 8d493edbbe cangen: checkpatch: put braces on all arms of if statement
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 59c87f149b cangen: checkpatch: don't assign in if statement
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde ad638db75d cangen: checkpatch: remove break after return
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 1d55d085c9 cangen: checkpatch: fix comment style
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 77e785b022 cangen: checkpatch: fix space and newline usage
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
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