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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>