summaryrefslogtreecommitdiffstats
path: root/drivers/net/can/usb
AgeCommit message (Collapse)AuthorFilesLines
2022-05-23can: kvaser_usb: silence a GCC 12 -Warray-bounds warningJakub Kicinski1-0/+5
This driver does a lot of casting of smaller buffers to struct kvaser_cmd_ext, GCC 12 does not like that: | drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:65: warning: array subscript ‘struct kvaser_cmd_ext[0]’ is partly outside array bounds of ‘unsigned char[32]’ [-Warray-bounds] | drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c:489:23: note: in expansion of macro ‘le16_to_cpu’ | 489 | ret = le16_to_cpu(((struct kvaser_cmd_ext *)cmd)->len); | | ^~~~~~~~~~~ Temporarily silence this warning (move it to W=1 builds). Link: https://lore.kernel.org/all/20220520194659.2356903-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Tested-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-05-23can: peak_usb: fix typo in commentJulia Lawall1-1/+1
Spelling mistake (triple letters) in comment. Detected with the help of Coccinelle. Link: https://lore.kernel.org/all/20220521111145.81697-24-Julia.Lawall@inria.fr Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-05-19can: can-dev: remove obsolete CAN LED supportOliver Hartkopp2-19/+0
Since commit 30f3b42147ba6f ("can: mark led trigger as broken") the CAN specific LED support was disabled and marked as BROKEN. As the common LED support with CONFIG_LEDS_TRIGGER_NETDEV should do this work now the code can be removed as preparation for a CAN netdevice Kconfig rework. Link: https://lore.kernel.org/all/20220518154527.29046-1-socketcan@hartkopp.net Suggested-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> [mkl: remove led.h from MAINTAINERS] Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-31can: gs_usb: gs_make_candev(): fix memory leak for devices with extended bit ↵Marc Kleine-Budde1-0/+2
timing configuration Some CAN-FD capable devices offer extended bit timing information for the data bit timing. The information must be read with an USB control message. The memory for this message is allocated but not free()ed (in the non error case). This patch adds the missing free. Fixes: 6679f4c5e5a6 ("can: gs_usb: add extended bt_const feature") Link: https://lore.kernel.org/all/20220329193450.659726-1-mkl@pengutronix.de Reported-by: syzbot+4d0ae90a195b269f102d@syzkaller.appspotmail.com Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-31can: mcba_usb: properly check endpoint typePavel Skripkin1-10/+16
Syzbot reported warning in usb_submit_urb() which is caused by wrong endpoint type. We should check that in endpoint is actually present to prevent this warning. Found pipes are now saved to struct mcba_priv and code uses them directly instead of making pipes in place. Fail log: | usb 5-1: BOGUS urb xfer, pipe 3 != type 1 | WARNING: CPU: 1 PID: 49 at drivers/usb/core/urb.c:502 usb_submit_urb+0xed2/0x18a0 drivers/usb/core/urb.c:502 | Modules linked in: | CPU: 1 PID: 49 Comm: kworker/1:2 Not tainted 5.17.0-rc6-syzkaller-00184-g38f80f42147f #0 | Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014 | Workqueue: usb_hub_wq hub_event | RIP: 0010:usb_submit_urb+0xed2/0x18a0 drivers/usb/core/urb.c:502 | ... | Call Trace: | <TASK> | mcba_usb_start drivers/net/can/usb/mcba_usb.c:662 [inline] | mcba_usb_probe+0x8a3/0xc50 drivers/net/can/usb/mcba_usb.c:858 | usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396 | call_driver_probe drivers/base/dd.c:517 [inline] Fixes: 51f3baad7de9 ("can: mcba_usb: Add support for Microchip CAN BUS Analyzer") Link: https://lore.kernel.org/all/20220313100903.10868-1-paskripkin@gmail.com Reported-and-tested-by: syzbot+3bc1dce0cc0052d60fde@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin <paskripkin@gmail.com> Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-31can: mcba_usb: mcba_usb_start_xmit(): fix double dev_kfree_skb in error pathHangyu Hua1-1/+0
There is no need to call dev_kfree_skb() when usb_submit_urb() fails because can_put_echo_skb() deletes original skb and can_free_echo_skb() deletes the cloned skb. Fixes: 51f3baad7de9 ("can: mcba_usb: Add support for Microchip CAN BUS Analyzer") Link: https://lore.kernel.org/all/20220311080208.45047-1-hbh25y@gmail.com Signed-off-by: Hangyu Hua <hbh25y@gmail.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-31can: usb_8dev: usb_8dev_start_xmit(): fix double dev_kfree_skb() in error pathHangyu Hua1-16/+14
There is no need to call dev_kfree_skb() when usb_submit_urb() fails because can_put_echo_skb() deletes original skb and can_free_echo_skb() deletes the cloned skb. Fixes: 0024d8ad1639 ("can: usb_8dev: Add support for USB2CAN interface from 8 devices") Link: https://lore.kernel.org/all/20220311080614.45229-1-hbh25y@gmail.com Cc: stable@vger.kernel.org Signed-off-by: Hangyu Hua <hbh25y@gmail.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-31can: ems_usb: ems_usb_start_xmit(): fix double dev_kfree_skb() in error pathHangyu Hua1-1/+0
There is no need to call dev_kfree_skb() when usb_submit_urb() fails beacause can_put_echo_skb() deletes the original skb and can_free_echo_skb() deletes the cloned skb. Link: https://lore.kernel.org/all/20220228083639.38183-1-hbh25y@gmail.com Fixes: 702171adeed3 ("ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface") Cc: stable@vger.kernel.org Cc: Sebastian Haas <haas@ems-wuensche.com> Signed-off-by: Hangyu Hua <hbh25y@gmail.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-16can: ucan: fix typos in commentsJulia Lawall1-2/+2
Various spelling mistakes in comments. Detected with the help of Coccinelle. Link: https://lore.kernel.org/all/20220314115354.144023-28-Julia.Lawall@inria.fr Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr> Acked-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: add VID/PID for ABE CAN Debugger devicesBen Evans1-0/+5
Add support for ABE CAN Debugger devices using the gs_usb driver. Link: https://lore.kernel.org/all/20220309124132.291861-22-mkl@pengutronix.de Signed-off-by: Ben Evans <benny.j.evans92@gmail.com> Signed-off-by: Peter Fink <pfink@christ-es.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: add VID/PID for CES CANext FD devicesPeter Fink1-0/+5
Add support for Christ Electronic Systems GmbH CANext FD devices using the gs_usb driver. Link: https://lore.kernel.org/all/20220309124132.291861-21-mkl@pengutronix.de Signed-off-by: Peter Fink <pfink@christ-es.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: add extended bt_const featurePeter Fink1-2/+68
For example CANext FD needs to distinguish between bittiming constants valid for arbitration phase and data phase to reach maximum performance at higher speeds. Link: https://lore.kernel.org/all/20220309124132.291861-20-mkl@pengutronix.de Signed-off-by: Peter Fink <pfink@christ-es.de> Signed-off-by: Christoph Möhring <cmoehring@christ-es.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: activate quirks for CANtact Pro unconditionallyPeter Fink1-0/+23
The CANtact Pro from LinkLayer Labs is based on the LPC54616 µC, which is affected by the NXP LPC USB transfer erratum. However, the current firmware (version 2) doesn't set the GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX bit. This patch sets the feature GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX to workaround this issue. For the GS_USB_BREQ_DATA_BITTIMING USB control message the CANtact Pro firmware uses a request value, which is already used by the candleLight firmware for a different purpose (GS_USB_BREQ_GET_USER_ID). This patch set the feature GS_CAN_FEATURE_QUIRK_BREQ_CANTACT_PRO to workaround this issue. Link: https://lore.kernel.org/all/20220309124132.291861-19-mkl@pengutronix.de Cc: Ryan Edwards <ryan.edwards@gmail.com> Signed-off-by: Peter Fink <pfink@christ-es.de> Signed-off-by: Christoph Möhring <cmoehring@christ-es.de> [mkl: improve check for CANtact Pro and add GS_CAN_FEATURE_QUIRK_BREQ_CANTACT_PRO quirk] Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: add quirk for CANtact Pro overlapping GS_USB_BREQ valueMarc Kleine-Budde1-1/+13
For the GS_USB_BREQ_DATA_BITTIMING USB control message the CANtact Pro firmware uses a request value, which is already used by the candleLight firmware for a different purpose (GS_USB_BREQ_GET_USER_ID). This patch adds a quirk to use the CANtact Pro's value for the GS_USB_BREQ_DATA_BITTIMING USB control message instead of the official one. Link: https://lore.kernel.org/all/20220309124132.291861-18-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: add usb quirk for NXP LPC546xx controllersPeter Fink1-2/+27
Introduce a workaround for a NXP chip errata on LPC546xx controllers (Errata sheet LPC546xx / USB.15). According to the document corruption can occur when the following conditions are met: * A TX (IN) transfer happens after a RX (OUT) transfer. * The RX (OUT) transfer length is 4 + N * 16 (N >= 0) bytes. Even though the struct gs_host_frame has a size of 76 bytes for a FD frame, which does not apply to the above rule, corruption could be seen. Adding a dummy byte to break the second condition also on transfer lengths with 4 + N * 8 bytes reliably circumvents USB transfer data corruption. The firmware can now request this quirk by setting GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX. Link: https://lore.kernel.org/all/20220309124132.291861-17-mkl@pengutronix.de Signed-off-by: Peter Fink <pfink@christ-es.de> Signed-off-by: Christoph Möhring <cmoehring@christ-es.de> Signed-off-by: Alexander Schartner <aschartner@christ-es.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: add CAN-FD supportPeter Fink1-16/+108
CANtact Pro from Linklayer is the first gs_usb compatible device supporting CAN-FD with a different HW and re-written candlelight FW. Support for CAN-FD is indicated by the device setting the GS_CAN_FEATURE_FD flag. CAN-FD support is requested by the driver with the GS_CAN_MODE_FD flag. The CAN-FD specific data bit timing parameters are set with the GS_USB_BREQ_DATA_BITTIMING control message. This patch is based on the Eric Evenchick's gs_usb_fd driver (which itself is a fork of gs_usb). The gs_usb_fd code base was reintegrated into the gs_usb driver, and reworked to not break the existing classical-CAN only hardware. Link: https://lore.kernel.org/all/20220309124132.291861-16-mkl@pengutronix.de Link: https://github.com/linklayer/gs_usb_fd/issues/2 Co-developed-by: Eric Evenchick <eric@evenchick.com> Signed-off-by: Eric Evenchick <eric@evenchick.com> Signed-off-by: Peter Fink <pfink@christ-es.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: use union and FLEX_ARRAY for data in struct gs_host_framePeter Fink1-11/+26
Modify struct gs_host_frame to make use of a union and DECLARE_FLEX_ARRAY to be able to store different data (lengths), which will be added in later commits. Store the gs_host_frame length in TX direction (host -> device) in struct gs_can::hf_size_tx and RX direction (device -> host) in struct gs_usb::hf_size_rx so it must be calculated only once. Link: https://lore.kernel.org/all/20220309124132.291861-15-mkl@pengutronix.de Signed-off-by: Peter Fink <pfink@christ-es.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: support up to 3 channels per deviceMarc Kleine-Budde1-2/+2
Some STM32G3 chips support up to 3 CAN-FD channels, increase number of supported channels in this driver to 3 accordingly. Link: https://lore.kernel.org/all/20220309124132.291861-14-mkl@pengutronix.de Suggested-by: Ryan Edwards <ryan.edwards@gmail.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: gs_usb_probe(): introduce udev and make use of itMarc Kleine-Budde1-5/+4
Introduce the variable udev in the gs_usb_probe() function to hold a pointer to the struct usb_device. This avoids recalculating the value several times in this function. Link: https://lore.kernel.org/all/20220309124132.291861-13-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: document the PAD_PKTS_TO_MAX_PKT_SIZE featureMarc Kleine-Budde1-0/+2
The widely used open source firmware candleLight supports padding the USB packets to max packet size to improve performance on Windows systems. This patch documents the bit. Link: https://lore.kernel.org/all/20220309124132.291861-12-mkl@pengutronix.de Link: https://github.com/candle-usb/candleLight_fw/pull/7 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: document the USER_ID featureMarc Kleine-Budde1-0/+4
The widely used open source firmware candleLight has optional support for reading/writing of an user defined value into the device's flash. This is indicated by the GS_CAN_FEATURE_USER_ID feature. The corresponding request are GS_USB_BREQ_GET_USER_ID and GS_USB_BREQ_SET_USER_ID. This patch documents these values. Link: https://lore.kernel.org/all/20220309124132.291861-11-mkl@pengutronix.de Link: https://github.com/candle-usb/candleLight_fw/commit/1453d70dc9a9d98ac254893ba5114b8e826e0e39 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: update GS_CAN_FEATURE_IDENTIFY documentationMarc Kleine-Budde1-0/+1
In the binary interface a feature bit might have a corresponding mode bit (of the same value). The GS_CAN_FEATURE_IDENTIFY feature doesn't come with a mode. Document this, to avoid gaps when adding more features/modes later. Link: https://lore.kernel.org/all/20220309124132.291861-10-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: add HW timestamp mode bitMarc Kleine-Budde1-0/+1
Newer versions of the widely used open source firmware candleLight support hardware timestamps. The support is activated by setting the GS_CAN_MODE_HW_TIMESTAMP in the GS_USB_BREQ_MODE request. Although timestamp support is not yet supported by this driver, add the missing bit for documentation purpose. Link: https://lore.kernel.org/all/20220309124132.291861-9-mkl@pengutronix.de Link: https://github.com/candle-usb/candleLight_fw/commit/44431f4a4354a878fbd15b273bf04fce1dcdff7e Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: gs_make_candev(): call SET_NETDEV_DEV() after handling all ↵Marc Kleine-Budde1-2/+2
bt_const->feature This patch moves the call to SET_NETDEV_DEV() after all handling (including cleanup) of the bt_const->feature is done. This looks more consistent. Link: https://lore.kernel.org/all/20220309124132.291861-8-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: rewrap usb_control_msg() and usb_fill_bulk_urb()Marc Kleine-Budde1-65/+22
This patch rewraps the arguments of usb_control_msg() and usb_fill_bulk_urb() to make full use of the standard line length of 80 characters. Link: https://lore.kernel.org/all/20220309124132.291861-7-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: rewrap error messagesMarc Kleine-Budde1-4/+2
This patch rewraps the arguments of netdev_err() to make full use of the standard line length of 80 characters. Link: https://lore.kernel.org/all/20220309124132.291861-6-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: GS_CAN_FLAG_OVERFLOW: make use of BIT()Marc Kleine-Budde1-1/+1
This patch converts the driver to use BIT() to define flags. Link: https://lore.kernel.org/all/20220309124132.291861-5-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: sort include files alphabeticallyMarc Kleine-Budde1-1/+1
This patch sorts the include files alphabetically. Link: https://lore.kernel.org/all/20220309124132.291861-4-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: fix checkpatch warningMarc Kleine-Budde1-1/+2
This patch fixes a checkpatch warning by converting a "unsigned" into an "unsigned int". Link: https://lore.kernel.org/all/20220309124132.291861-3-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: gs_usb: use consistent one space indentionMarc Kleine-Budde1-19/+19
With this patch a consistent one space indention throughout the whole driver is used. Link: https://lore.kernel.org/all/20220309124132.291861-2-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-10can: etas_es58x: es58x_fd_rx_event_msg(): initialize rx_event_msg before ↵Vincent Mailhol1-2/+1
calling es58x_check_msg_len() Function es58x_fd_rx_event() invokes the es58x_check_msg_len() macro: | ret = es58x_check_msg_len(es58x_dev->dev, *rx_event_msg, msg_len); While doing so, it dereferences an uninitialized variable: *rx_event_msg. This is actually harmless because es58x_check_msg_len() only uses preprocessor macros (sizeof() and __stringify()) on *rx_event_msg. c.f. [1]. Nonetheless, this pattern is confusing so the lines are reordered to make sure that rx_event_msg is correctly initialized. This patch also fixes a false positive warning reported by cppcheck: | cppcheck possible warnings: (new ones prefixed by >>, may not be real problems) | | In file included from drivers/net/can/usb/etas_es58x/es58x_fd.c: | >> drivers/net/can/usb/etas_es58x/es58x_fd.c:174:8: warning: Uninitialized variable: rx_event_msg [uninitvar] | ret = es58x_check_msg_len(es58x_dev->dev, *rx_event_msg, msg_len); | ^ [1] https://elixir.bootlin.com/linux/v5.16/source/drivers/net/can/usb/etas_es58x/es58x_core.h#L467 Link: https://lore.kernel.org/all/20220306101302.708783-1-mailhol.vincent@wanadoo.fr Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-03-03Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/netJakub Kicinski3-12/+15
net/batman-adv/hard-interface.c commit 690bb6fb64f5 ("batman-adv: Request iflink once in batadv-on-batadv check") commit 6ee3c393eeb7 ("batman-adv: Demote batadv-on-batadv skip error message") https://lore.kernel.org/all/20220302163049.101957-1-sw@simonwunderlich.de/ net/smc/af_smc.c commit 4d08b7b57ece ("net/smc: Fix cleanup when register ULP fails") commit 462791bbfa35 ("net/smc: add sysctl interface for SMC") https://lore.kernel.org/all/20220302112209.355def40@canb.auug.org.au/ Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-02-25can: gs_usb: change active_channels's type from atomic_t to u8Vincent Mailhol1-5/+5
The driver uses an atomic_t variable: gs_usb:active_channels to keep track of the number of opened channels in order to only allocate memory for the URBs when this count changes from zero to one. However, the driver does not decrement the counter when an error occurs in gs_can_open(). This issue is fixed by changing the type from atomic_t to u8 and by simplifying the logic accordingly. It is safe to use an u8 here because the network stack big kernel lock (a.k.a. rtnl_mutex) is being hold. For details, please refer to [1]. [1] https://lore.kernel.org/linux-can/CAMZ6Rq+sHpiw34ijPsmp7vbUpDtJwvVtdV7CvRZJsLixjAFfrg@mail.gmail.com/T/#t Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices") Link: https://lore.kernel.org/all/20220214234814.1321599-1-mailhol.vincent@wanadoo.fr Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-02-25can: etas_es58x: change opened_channel_cnt's type from atomic_t to u8Vincent Mailhol2-7/+10
The driver uses an atomic_t variable: struct es58x_device::opened_channel_cnt to keep track of the number of opened channels in order to only allocate memory for the URBs when this count changes from zero to one. While the intent was to prevent race conditions, the choice of an atomic_t turns out to be a bad idea for several reasons: - implementation is incorrect and fails to decrement opened_channel_cnt when the URB allocation fails as reported in [1]. - even if opened_channel_cnt were to be correctly decremented, atomic_t is insufficient to cover edge cases: there can be a race condition in which 1/ a first process fails to allocate URBs memory 2/ a second process enters es58x_open() before the first process does its cleanup and decrements opened_channed_cnt. In which case, the second process would successfully return despite the URBs memory not being allocated. - actually, any kind of locking mechanism was useless here because it is redundant with the network stack big kernel lock (a.k.a. rtnl_lock) which is being hold by all the callers of net_device_ops:ndo_open() and net_device_ops:ndo_close(). c.f. the ASSERST_RTNL() calls in __dev_open() [2] and __dev_close_many() [3]. The atmomic_t is thus replaced by a simple u8 type and the logic to increment and decrement es58x_device:opened_channel_cnt is simplified accordingly fixing the bug reported in [1]. We do not check again for ASSERST_RTNL() as this is already done by the callers. [1] https://lore.kernel.org/linux-can/20220201140351.GA2548@kili/T/#u [2] https://elixir.bootlin.com/linux/v5.16/source/net/core/dev.c#L1463 [3] https://elixir.bootlin.com/linux/v5.16/source/net/core/dev.c#L1541 Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces") Link: https://lore.kernel.org/all/20220212112713.577957-1-mailhol.vincent@wanadoo.fr Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-02-24can: etas_es58x: use BITS_PER_TYPE() instead of manual calculationVincent Mailhol1-1/+2
The input to the GENMASK() macro was calculated by hand. Replaced it with a dedicated macro: BITS_PER_TYPE() which does the exact same job. Link: https://lore.kernel.org/all/20220212130737.3008-1-mailhol.vincent@wanadoo.fr Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-02-24can: kvaser_usb: kvaser_usb_send_cmd(): remove redundant variable actual_lenMarc Kleine-Budde1-3/+1
The function usb_bulk_msg() can be called with a NULL pointer as the "actual_length" parameter. This patch removes this variable. Link: https://lore.kernel.org/all/20220124215642.3474154-9-mkl@pengutronix.de Cc: Jimmy Assarsson <extja@kvaser.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-01-09Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/netJakub Kicinski1-1/+4
Merge in fixes directly in prep for the 5.17 merge window. No conflicts. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-01-09can: gs_usb: gs_can_start_xmit(): zero-initialize hf->{flags,reserved}Brian Silverman1-0/+2
No information is deliberately sent in hf->flags in host -> device communications, but the open-source candleLight firmware echoes it back, which can result in the GS_CAN_FLAG_OVERFLOW flag being set and generating spurious ERRORFRAMEs. While there also initialize the reserved member with 0. Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices") Link: https://lore.kernel.org/all/20220106002952.25883-1-brian.silverman@bluerivertech.com Link: https://github.com/candle-usb/candleLight_fw/issues/87 Cc: stable@vger.kernel.org Signed-off-by: Brian Silverman <brian.silverman@bluerivertech.com> [mkl: initialize the reserved member, too] Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-01-05can: gs_usb: fix use of uninitialized variable, detach device on reception ↵Marc Kleine-Budde1-1/+2
of invalid USB data The received data contains the channel the received data is associated with. If the channel number is bigger than the actual number of channels assume broken or malicious USB device and shut it down. This fixes the error found by clang: | drivers/net/can/usb/gs_usb.c:386:6: error: variable 'dev' is used | uninitialized whenever 'if' condition is true | if (hf->channel >= GS_MAX_INTF) | ^~~~~~~~~~~~~~~~~~~~~~~~~~ | drivers/net/can/usb/gs_usb.c:474:10: note: uninitialized use occurs here | hf, dev->gs_hf_size, gs_usb_receive_bulk_callback, | ^~~ Link: https://lore.kernel.org/all/20211210091158.408326-1-mkl@pengutronix.de Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices") Cc: stable@vger.kernel.org Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-01-05can: do not increase tx_bytes statistics for RTR framesVincent Mailhol12-79/+52
The actual payload length of the CAN Remote Transmission Request (RTR) frames is always 0, i.e. no payload is transmitted on the wire. However, those RTR frames still use the DLC to indicate the length of the requested frame. As such, net_device_stats::tx_bytes should not be increased when sending RTR frames. The function can_get_echo_skb() already returns the correct length, even for RTR frames (c.f. [1]). However, for historical reasons, the drivers do not use can_get_echo_skb()'s return value and instead, most of them store a temporary length (or dlc) in some local structure or array. Using the return value of can_get_echo_skb() solves the issue. After doing this, such length/dlc fields become unused and so this patch does the adequate cleaning when needed. This patch fixes all the CAN drivers. Finally, can_get_echo_skb() is decorated with the __must_check attribute in order to force future drivers to correctly use its return value (else the compiler would emit a warning). [1] commit ed3320cec279 ("can: dev: __can_get_echo_skb(): fix real payload length return value for RTR frames") Link: https://lore.kernel.org/all/20211207121531.42941-6-mailhol.vincent@wanadoo.fr Cc: Nicolas Ferre <nicolas.ferre@microchip.com> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com> Cc: Ludovic Desroches <ludovic.desroches@microchip.com> Cc: Maxime Ripard <mripard@kernel.org> Cc: Chen-Yu Tsai <wens@csie.org> Cc: Jernej Skrabec <jernej.skrabec@gmail.com> Cc: Yasushi SHOJI <yashi@spacecubics.com> Cc: Oliver Hartkopp <socketcan@hartkopp.net> Cc: Stephane Grosjean <s.grosjean@peak-system.com> Cc: Andreas Larsson <andreas@gaisler.com> Tested-by: Jimmy Assarsson <extja@kvaser.com> # kvaser Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Acked-by: Stefan Mätje <stefan.maetje@esd.eu> # esd_usb2 Tested-by: Stefan Mätje <stefan.maetje@esd.eu> # esd_usb2 [mkl: add conversion for grcan] Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-01-05can: do not increase rx_bytes statistics for RTR framesVincent Mailhol10-30/+43
The actual payload length of the CAN Remote Transmission Request (RTR) frames is always 0, i.e. no payload is transmitted on the wire. However, those RTR frames still use the DLC to indicate the length of the requested frame. As such, net_device_stats::rx_bytes should not be increased for the RTR frames. This patch fixes all the CAN drivers. Link: https://lore.kernel.org/all/20211207121531.42941-5-mailhol.vincent@wanadoo.fr Cc: Marc Kleine-Budde <mkl@pengutronix.de> Cc: Nicolas Ferre <nicolas.ferre@microchip.com> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com> Cc: Ludovic Desroches <ludovic.desroches@microchip.com> Cc: Chandrasekar Ramakrishnan <rcsekar@samsung.com> Cc: Maxime Ripard <mripard@kernel.org> Cc: Chen-Yu Tsai <wens@csie.org> Cc: Jernej Skrabec <jernej.skrabec@gmail.com> Cc: Yasushi SHOJI <yashi@spacecubics.com> Cc: Appana Durga Kedareswara rao <appana.durga.rao@xilinx.com> Cc: Naga Sureshkumar Relli <naga.sureshkumar.relli@xilinx.com> Cc: Michal Simek <michal.simek@xilinx.com> Cc: Stephane Grosjean <s.grosjean@peak-system.com> Tested-by: Jimmy Assarsson <extja@kvaser.com> # kvaser Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Acked-by: Stefan Mätje <stefan.maetje@esd.eu> # esd_usb2 Tested-by: Stefan Mätje <stefan.maetje@esd.eu> # esd_usb2 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-01-05can: do not copy the payload of RTR framesVincent Mailhol1-4/+4
The actual payload length of the CAN Remote Transmission Request (RTR) frames is always 0, i.e. no payload is transmitted on the wire. However, those RTR frames still use the DLC to indicate the length of the requested frame. For this reason, it is incorrect to copy the payload of RTR frames (the payload buffer would only contain garbage data). This patch encapsulates the payload copy in a check toward the RTR flag. Link: https://lore.kernel.org/all/20211207121531.42941-4-mailhol.vincent@wanadoo.fr Cc: Yasushi SHOJI <yashi@spacecubics.com> Tested-by: Yasushi SHOJI <yashi@spacecubics.com> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-01-05can: kvaser_usb: do not increase tx statistics when sending error message framesVincent Mailhol1-1/+6
The CAN error message frames (i.e. error skb) are an interface specific to socket CAN. The payload of the CAN error message frames does not correspond to any actual data sent on the wire. Only an error flag and a delimiter are transmitted when an error occurs (c.f. ISO 11898-1 section 10.4.4.2 "Error flag"). For this reason, it makes no sense to increment the tx_packets and tx_bytes fields of struct net_device_stats when sending an error message frame because no actual payload will be transmitted on the wire. N.B. Sending error message frames is a very specific feature which, at the moment, is only supported by the Kvaser Hydra hardware. Please refer to [1] for more details on the topic. [1] https://lore.kernel.org/linux-can/CAMZ6RqK0rTNg3u3mBpZOoY51jLZ-et-J01tY6-+mWsM4meVw-A@mail.gmail.com/t/#u Link: https://lore.kernel.org/all/20211207121531.42941-3-mailhol.vincent@wanadoo.fr Co-developed-by: Jimmy Assarsson <extja@kvaser.com> Signed-off-by: Jimmy Assarsson <extja@kvaser.com> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-01-05can: do not increase rx statistics when generating a CAN rx error message frameVincent Mailhol11-36/+4
The CAN error message frames (i.e. error skb) are an interface specific to socket CAN. The payload of the CAN error message frames does not correspond to any actual data sent on the wire. Only an error flag and a delimiter are transmitted when an error occurs (c.f. ISO 11898-1 section 10.4.4.2 "Error flag"). For this reason, it makes no sense to increment the rx_packets and rx_bytes fields of struct net_device_stats because no actual payload were transmitted on the wire. This patch fixes all the CAN drivers. Link: https://lore.kernel.org/all/20211207121531.42941-2-mailhol.vincent@wanadoo.fr CC: Marc Kleine-Budde <mkl@pengutronix.de> CC: Nicolas Ferre <nicolas.ferre@microchip.com> CC: Alexandre Belloni <alexandre.belloni@bootlin.com> CC: Ludovic Desroches <ludovic.desroches@microchip.com> CC: Chandrasekar Ramakrishnan <rcsekar@samsung.com> CC: Maxime Ripard <mripard@kernel.org> CC: Chen-Yu Tsai <wens@csie.org> CC: Jernej Skrabec <jernej.skrabec@gmail.com> CC: Appana Durga Kedareswara rao <appana.durga.rao@xilinx.com> CC: Naga Sureshkumar Relli <naga.sureshkumar.relli@xilinx.com> CC: Michal Simek <michal.simek@xilinx.com> CC: Stephane Grosjean <s.grosjean@peak-system.com> Tested-by: Jimmy Assarsson <extja@kvaser.com> # kvaser Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Acked-by: Stefan Mätje <stefan.maetje@esd.eu> # esd_usb2 Tested-by: Stefan Mätje <stefan.maetje@esd.eu> # esd_usb2 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-01-05can: etas_es58x: es58x_init_netdev: populate net_device::dev_portVincent Mailhol1-0/+1
The field dev_port of struct net_device indicates the port number of a network device [1]. This patch populates this field. This field can be helpful to distinguish between the two network interfaces of a dual channel device (i.e. ES581.4 or ES582.1). Indeed, at the moment, all the network interfaces of a same device share the same static udev attributes c.f. output of: | udevadm info --attribute-walk /sys/class/net/canX The dev_port attribute can then be used to write some udev rules to, for example, assign a permanent name to each network interface based on the serial/dev_port pair (which is convenient when you have a test bench with several CAN devices connected simultaneously and wish to keep consistent interface names upon reboot). [1] https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net Link: https://lore.kernel.org/all/20211026180553.1953189-1-mailhol.vincent@wanadoo.fr Suggested-by: Lukas Magel <lukas.magel@escrypt.com> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-01-05can: kvaser_usb: make use of units.h in assignment of frequencyJimmy Assarsson2-7/+9
Use the MEGA define plus the comment /* Hz */ when assigning frequencies. Link: https://lore.kernel.org/all/20211210075803.343841-1-mkl@pengutronix.de Signed-off-by: Jimmy Assarsson <extja@kvaser.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-01-05can: usb_8dev: remove unused member echo_skb from struct usb_8dev_privMarc Kleine-Budde1-2/+0
This patch removes the unused memberecho_skb from the struct usb_8dev_priv. Fixes: 0024d8ad1639 ("can: usb_8dev: Add support for USB2CAN interface from 8 devices") Link: https://lore.kernel.org/all/20220104230753.956520-1-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2021-12-29net: Don't include filter.h from net/sock.hJakub Kicinski1-0/+1
sock.h is pretty heavily used (5k objects rebuilt on x86 after it's touched). We can drop the include of filter.h from it and add a forward declaration of struct sk_filter instead. This decreases the number of rebuilt objects when bpf.h is touched from ~5k to ~1k. There's a lot of missing includes this was masking. Primarily in networking tho, this time. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Marc Kleine-Budde <mkl@pengutronix.de> Acked-by: Florian Fainelli <f.fainelli@gmail.com> Acked-by: Nikolay Aleksandrov <nikolay@nvidia.com> Acked-by: Stefano Garzarella <sgarzare@redhat.com> Link: https://lore.kernel.org/bpf/20211229004913.513372-1-kuba@kernel.org
2021-12-09Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/netJakub Kicinski1-28/+73
No conflicts. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-12-09can: kvaser_usb: get CAN clock frequency from deviceJimmy Assarsson1-28/+73
The CAN clock frequency is used when calculating the CAN bittiming parameters. When wrong clock frequency is used, the device may end up with wrong bittiming parameters, depending on user requested bittiming parameters. To avoid this, get the CAN clock frequency from the device. Various existing Kvaser Leaf products use different CAN clocks. Fixes: 080f40a6fa28 ("can: kvaser_usb: Add support for Kvaser CAN/USB devices") Link: https://lore.kernel.org/all/20211208152122.250852-2-extja@kvaser.com Cc: stable@vger.kernel.org Signed-off-by: Jimmy Assarsson <extja@kvaser.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>