pull-request: can 2021-11-06
Subsystems (8)
Marc Kleine-Budde
maintainerHello Jakub, hello David,
this is a pull request of 8 patches for net/master.
The first 3 patches are by Zhang Changzhong and fix 3 standard conformance problems in the j1939 CAN stack.
The next patch is by Vincent Mailhol and fixes a memory leak in the leak error path of the etas_es58x CAN driver.
Stephane Grosjean contributes 2 patches for the peak_usb driver to fix the bus error handling and update the order of printed information regarding firmware version and available updates.
The last 2 patches are by me and fixes a packet starvation problem in the bus off case and the error handling in the mcp251xfd_chip_start() function.
regards,
Marc
---
The following changes since commit 70bf363d7adb3a428773bc905011d0ff923ba747:
ipv6: remove useless assignment to newinet in tcp_v6_syn_recv_sock() (2021-11-05 19:49:40 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git tags/linux-can-fixes-for-5.16-20211106
for you to fetch changes up to 69c55f6e7669d46bb40e41f6e2b218428178368a:
can: mcp251xfd: mcp251xfd_chip_start(): fix error handling for mcp251xfd_chip_rx_int_enable() (2021-11-06 21:25:25 +0100)
----------------------------------------------------------------
linux-can-fixes-for-5.16-20211106
----------------------------------------------------------------
Marc Kleine-Budde (2):
can: mcp251xfd: mcp251xfd_irq(): add missing can_rx_offload_threaded_irq_finish() in case of bus off
can: mcp251xfd: mcp251xfd_chip_start(): fix error handling for mcp251xfd_chip_rx_int_enable()
Stephane Grosjean (2):
can: peak_usb: always ask for BERR reporting for PCAN-USB devices
can: peak_usb: exchange the order of information messages
Vincent Mailhol (1):
can: etas_es58x: es58x_rx_err_msg(): fix memory leak in error path
Zhang Changzhong (3):
can: j1939: j1939_tp_cmd_recv(): ignore abort message in the BAM transport
can: j1939: j1939_can_recv(): ignore messages with invalid source address
can: j1939: j1939_tp_cmd_recv(): check the dst address of TP.CM_BAM
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 6 ++++-- drivers/net/can/usb/etas_es58x/es58x_core.c | 6 ++---- drivers/net/can/usb/peak_usb/pcan_usb.c | 27 +++++++++++++------------- net/can/j1939/main.c | 7 +++++++ net/can/j1939/transport.c | 11 +++++++++++ 5 files changed, 37 insertions(+), 20 deletions(-)
Marc Kleine-Budde
maintainerPATCH 1/8 can: j1939: j1939_tp_cmd_recv(): ignore abort message in the BAM transport
From: Zhang Changzhong <[email protected]>
This patch prevents BAM transport from being closed by receiving abort message, as specified in SAE-J1939-82 2015 (A.3.3 Row 4).
--- net/can/j1939/transport.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/can/j1939/transport.c +6 -0
@@ -2085,6 +2085,12 @@ static void j1939_tp_cmd_recv(struct j1939_priv *priv, struct sk_buff *skb)break ;case J1939_ETP_CMD_ABORT :/* && J1939_TP_CMD_ABORT */ +if (j1939_cb_is_broadcast (skcb)) { +netdev_err_once (priv->ndev,"%s: abort to broadcast (%02x), ignoring!\n" , + __func__, skcb->addr.sa); +return ; + } +if (j1939_tp_im_transmitter (skcb))j1939_xtp_rx_abort (priv, skb, true);
base-commit: 70bf363d7adb3a428773bc905011d0ff923ba747
Signature · 1 line
2.33.0
Marc Kleine-Budde
maintainerPATCH 2/8 can: j1939: j1939_can_recv(): ignore messages with invalid source address
In reply to Marc Kleine-BuddeFrom: Zhang Changzhong <[email protected]>
According to SAE-J1939-82 2015 (A.3.6 Row 2), a receiver should never send TP.CM_CTS to the global address, so we can add a check in j1939_can_recv() to drop messages with invalid source address.
--- net/can/j1939/main.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/can/j1939/main.c +7 -0
@@ -75,6 +75,13 @@ static void j1939_can_recv(struct sk_buff *iskb, void *data) skcb->addr.pgn = (cf->can_id >>8 ) &J1939_PGN_MAX ;/* set default message type */ skcb->addr.type =J1939_TP ; + +if (!j1939_address_is_valid (skcb->addr.sa)) { +netdev_err_once (priv->ndev,"%s: sa is broadcast address, ignoring!\n" , + __func__); + goto done; + } +if (j1939_pgn_is_pdu1 (skcb->addr.pgn)) {/* Type 1: with destination address */ skcb->addr.da = skcb->addr.pgn;
Signature · 1 line
2.33.0
Marc Kleine-Budde
maintainerPATCH 3/8 can: j1939: j1939_tp_cmd_recv(): check the dst address of TP.CM_BAM
In reply to Marc Kleine-BuddeFrom: Zhang Changzhong <[email protected]>
The TP.CM_BAM message must be sent to the global address [1], so add a check to drop TP.CM_BAM sent to a non-global address.
Without this patch, the receiver will treat the following packets as normal RTS/CTS transport:
18EC0102#20090002FF002301
18EB0102#0100000000000000
18EB0102#020000FFFFFFFFFF
[1] SAE-J1939-82 2015 A.3.3 Row 1.
--- net/can/j1939/transport.c | 5 +++++ 1 file changed, 5 insertions(+)
net/can/j1939/transport.c +5 -0
@@ -2023,6 +2023,11 @@ static void j1939_tp_cmd_recv(struct j1939_priv *priv, struct sk_buff *skb) extd =J1939_ETP ; fallthrough;case J1939_TP_CMD_BAM : +if (cmd ==J1939_TP_CMD_BAM && !j1939_cb_is_broadcast (skcb)) { +netdev_err_once (priv->ndev,"%s: BAM to unicast (%02x), ignoring!\n" , + __func__, skcb->addr.sa); +return ; + } fallthrough;case J1939_TP_CMD_RTS :if (skcb->addr.type != extd)
Signature · 1 line
2.33.0
Marc Kleine-Budde
maintainerPATCH 4/8 can: etas_es58x: es58x_rx_err_msg(): fix memory leak in error path
In reply to Marc Kleine-BuddeFrom: Vincent Mailhol <[email protected]>
In es58x_rx_err_msg(), if can->do_set_mode() fails, the function directly returns without calling netif_rx(skb). This means that the skb previously allocated by alloc_can_err_skb() is not freed. In other terms, this is a memory leak.
This patch simply removes the return statement in the error branch and let the function continue.
Issue was found with GCC -fanalyzer, please follow the link below for details.
--- drivers/net/can/usb/etas_es58x/es58x_core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/can/usb/etas_es58x/es58x_core.c +2 -4
@@ -664,7 +664,7 @@ int es58x_rx_err_msg(struct net_device *netdev, enum es58x_err error,struct can_device_stats *can_stats = &can->can_stats;struct can_frame *cf =NULL ;struct sk_buff *skb; -int ret; +int ret =0 ;if (!netif_running (netdev)) {if (net_ratelimit ())
@@ -823,8 +823,6 @@ int es58x_rx_err_msg(struct net_device *netdev, enum es58x_err error, can->state =CAN_STATE_BUS_OFF ;can_bus_off (netdev); ret = can->do_set_mode (netdev,CAN_MODE_STOP ); -if (ret) -return ret; }break ;
@@ -881,7 +879,7 @@ int es58x_rx_err_msg(struct net_device *netdev, enum es58x_err error, ES58X_EVENT_BUSOFF, timestamp); } -return 0 ; +return ret; }/**
Signature · 1 line
2.33.0
Marc Kleine-Budde
maintainerPATCH 5/8 can: peak_usb: always ask for BERR reporting for PCAN-USB devices
In reply to Marc Kleine-BuddeFrom: Stephane Grosjean <[email protected]>
Since for the PCAN-USB, the management of the transition to the ERROR_WARNING or ERROR_PASSIVE state is done according to the error counters, these must be requested unconditionally.
--- drivers/net/can/usb/peak_usb/pcan_usb.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/can/usb/peak_usb/pcan_usb.c +8 -9
@@ -841,14 +841,14 @@ static int pcan_usb_start(struct peak_usb_device *dev) pdev->bec.rxerr =0 ; pdev->bec.txerr =0 ; -/* be notified on error counter changes (if requested by user) */ -if (dev->can.ctrlmode &CAN_CTRLMODE_BERR_REPORTING ) { - err =pcan_usb_set_err_frame (dev,PCAN_USB_BERR_MASK ); -if (err) -netdev_warn (dev->netdev, -"Asking for BERR reporting error %u\n" , - err); - } +/* always ask the device for BERR reporting, to be able to switch from +* WARNING to PASSIVE state +*/ + err =pcan_usb_set_err_frame (dev,PCAN_USB_BERR_MASK ); +if (err) +netdev_warn (dev->netdev, +"Asking for BERR reporting error %u\n" , + err);/* if revision greater than 3, can put silent mode on/off */ if (dev->device_rev >3 ) {
@@ -986,7 +986,6 @@ const struct peak_usb_adapter pcan_usb = { .device_id = PCAN_USB_PRODUCT_ID, .ctrl_count = 1, .ctrlmode_supported =CAN_CTRLMODE_3_SAMPLES |CAN_CTRLMODE_LISTENONLY | -CAN_CTRLMODE_BERR_REPORTING | CAN_CTRLMODE_CC_LEN8_DLC, .clock = { .freq = PCAN_USB_CRYSTAL_HZ / 2,
Signature · 1 line
2.33.0
Marc Kleine-Budde
maintainerPATCH 6/8 can: peak_usb: exchange the order of information messages
In reply to Marc Kleine-BuddeFrom: Stephane Grosjean <[email protected]>
Proposes the possible update of the PCAN-USB firmware after indicating its name and current version.
--- drivers/net/can/usb/peak_usb/pcan_usb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/can/usb/peak_usb/pcan_usb.c +5 -5
@@ -883,6 +883,11 @@ static int pcan_usb_init(struct peak_usb_device *dev)return err; } +dev_info (dev->netdev->dev.parent, +"PEAK-System %s adapter hwrev %u serial %08X (%u channel)\n" , + pcan_usb.name, dev->device_rev, serial_number, + pcan_usb.ctrl_count); +/* Since rev 4.1, PCAN-USB is able to make single-shot as well as * looped back frames. */
@@ -896,11 +901,6 @@ static int pcan_usb_init(struct peak_usb_device *dev) "Firmware update available. Please contact [email protected]\n"); } -dev_info (dev->netdev->dev.parent, -"PEAK-System %s adapter hwrev %u serial %08X (%u channel)\n" , - pcan_usb.name, dev->device_rev, serial_number, - pcan_usb.ctrl_count); -return 0 ; }
Signature · 1 line
2.33.0
Marc Kleine-Budde
maintainerPATCH 7/8 can: mcp251xfd: mcp251xfd_irq(): add missing can_rx_offload_threaded_irq_finish() in case of bus off
In reply to Marc Kleine-BuddeThe function can_rx_offload_threaded_irq_finish() is needed to trigger the NAPI thread to deliver read CAN frames to the networking stack.
This patch adds the missing call to can_rx_offload_threaded_irq_finish() in case of a bus off, before leaving the interrupt handler to avoid packet starvation.
--- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +3 -1
@@ -2290,8 +2290,10 @@ static irqreturn_t mcp251xfd_irq(int irq, void *dev_id)* check will fail, too. So leave IRQ handler * directly. */ -if (priv->can.state ==CAN_STATE_BUS_OFF ) +if (priv->can.state ==CAN_STATE_BUS_OFF ) { +can_rx_offload_threaded_irq_finish (&priv->offload);return IRQ_HANDLED ; + } } handled =IRQ_HANDLED ;
Signature · 1 line
2.33.0
Marc Kleine-Budde
maintainerPATCH 8/8 can: mcp251xfd: mcp251xfd_chip_start(): fix error handling for mcp251xfd_chip_rx_int_enable()
In reply to Marc Kleine-BuddeThis patch fixes the error handling for mcp251xfd_chip_rx_int_enable(). Instead just returning the error, properly shut down the chip.
--- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -1
@@ -1092,7 +1092,7 @@ static int mcp251xfd_chip_start(struct mcp251xfd_priv *priv) err =mcp251xfd_chip_rx_int_enable (priv);if (err) -return err; + goto out_chip_stop; err =mcp251xfd_chip_ecc_init (priv);if (err)
Signature · 1 line
2.33.0
This pull request was applied to netdev/net.git (master) by Marc Kleine-Budde <[email protected]>:
Hello:
This pull request was applied to netdev/net.git (master) by Marc Kleine-Budde <[email protected]>:
Quoted 8 lines · On Sat, 6 Nov 2021 22:54:41 +0100 you wrote:
Hello Jakub, hello David,
this is a pull request of 8 patches for net/master.
The first 3 patches are by Zhang Changzhong and fix 3 standard conformance problems in the j1939 CAN stack.
[...]
Here is the summary with links:
- pull-request: can 2021-11-06
https://git.kernel.org/netdev/net/c/f05fb508ec3b - [net,2/8] can: j1939: j1939_can_recv(): ignore messages with invalid source address https://git.kernel.org/netdev/net/c/a79305e156db - [net,3/8] can: j1939: j1939_tp_cmd_recv(): check the dst address of TP.CM_BAM https://git.kernel.org/netdev/net/c/164051a6ab54 - [net,4/8] can: etas_es58x: es58x_rx_err_msg(): fix memory leak in error path https://git.kernel.org/netdev/net/c/d9447f768bc8 - [net,5/8] can: peak_usb: always ask for BERR reporting for PCAN-USB devices https://git.kernel.org/netdev/net/c/3f1c7aa28498 - [net,6/8] can: peak_usb: exchange the order of information messages https://git.kernel.org/netdev/net/c/6b78ba3e51f9 - [net,7/8] can: mcp251xfd: mcp251xfd_irq(): add missing can_rx_offload_threaded_irq_finish() in case of bus off https://git.kernel.org/netdev/net/c/691204bd66b3 - [net,8/8] can: mcp251xfd: mcp251xfd_chip_start(): fix error handling for mcp251xfd_chip_rx_int_enable() https://git.kernel.org/netdev/net/c/69c55f6e7669
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html