pull-request: can 2019-07-24
Subsystems (6)
Marc Kleine-Budde
maintainerHello David,
this is a pull reqeust of 7 patches for net/master.
The first patch is by Rasmus Villemoes add a missing netif_carrier_off() to register_candev() so that generic netdev trigger based LEDs are initially off.
Nikita Yushchenko's patch for the rcar_canfd driver fixes a possible IRQ storm on high load.
The patch by Weitao Hou for the mcp251x driver add missing error checking to the work queue allocation.
Both Wen Yang's and Joakim Zhang's patch for the flexcan driver fix a problem with the stop-mode.
Stephane Grosjean contributes a patch for the peak_usb driver to fix a potential double kfree_skb().
The last patch is by YueHaibing and fixes the error path in can-gw's cgw_module_init() function.
regards,
Marc
---
The following changes since commit d86afb89305de205b0d2f20c2160adf039e9508d:
net: thunderx: Use fwnode_get_mac_address() (2019-07-23 14:09:21 -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.3-20190724
for you to fetch changes up to b7a14297f102b6e2ce6f16feffebbb9bde1e9b55:
can: gw: Fix error path of cgw_module_init (2019-07-24 11:19:03 +0200)
----------------------------------------------------------------
linux-can-fixes-for-5.3-20190724
----------------------------------------------------------------
Joakim Zhang (1):
can: flexcan: fix stop mode acknowledgment
Nikita Yushchenko (1):
can: rcar_canfd: fix possible IRQ storm on high load
Rasmus Villemoes (1):
can: dev: call netif_carrier_off() in register_candev()
Stephane Grosjean (1):
can: peak_usb: fix potential double kfree_skb()
Weitao Hou (1):
can: mcp251x: add error check when wq alloc failed
Wen Yang (1):
can: flexcan: fix an use-after-free in flexcan_setup_stop_mode()
YueHaibing (1):
can: gw: Fix error path of cgw_module_init
drivers/net/can/dev.c | 2 ++ drivers/net/can/flexcan.c | 39 ++++++++++++++++++---- drivers/net/can/rcar/rcar_canfd.c | 9 ++--- drivers/net/can/spi/mcp251x.c | 49 +++++++++++++--------------- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 8 ++--- net/can/gw.c | 48 ++++++++++++++++++--------- 6 files changed, 98 insertions(+), 57 deletions(-)
Marc Kleine-Budde
maintainerPATCH 1/7 can: dev: call netif_carrier_off() in register_candev()
From: Rasmus Villemoes <[email protected]>
CONFIG_CAN_LEDS is deprecated. When trying to use the generic netdev trigger as suggested, there's a small inconsistency with the link
property: The LED is on initially, stays on when the device is brought up, and then turns off (as expected) when the device is brought down.
Make sure the LED always reflects the state of the CAN device.
--- drivers/net/can/dev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/can/dev.c +2 -0
@@ -1249,6 +1249,8 @@ int register_candev(struct net_device *dev)return -EINVAL ; dev->rtnl_link_ops = &can_link_ops; +netif_carrier_off (dev); +return register_netdev (dev); }EXPORT_SYMBOL_GPL (register_candev);
Signature · 1 line
2.20.1
Marc Kleine-Budde
maintainerPATCH 2/7 can: rcar_canfd: fix possible IRQ storm on high load
In reply to Marc Kleine-BuddeFrom: Nikita Yushchenko <[email protected]>
We have observed rcar_canfd driver entering IRQ storm under high load, with following scenario:
- rcar_canfd_global_interrupt() in entered due to Rx available,
- napi_schedule_prep() is called, and sets NAPIF_STATE_SCHED in state
- Rx fifo interrupts are masked,
- rcar_canfd_global_interrupt() is entered again, this time due to error interrupt (e.g. due to overflow),
- since scheduled napi poller has not yet executed, condition for calling napi_schedule_prep() from rcar_canfd_global_interrupt() remains true, thus napi_schedule_prep() gets called and sets NAPIF_STATE_MISSED flag in state,
- later, napi poller function rcar_canfd_rx_poll() gets executed, and calls napi_complete_done(),
- due to NAPIF_STATE_MISSED flag in state, this call does not clear NAPIF_STATE_SCHED flag from state,
- on return from napi_complete_done(), rcar_canfd_rx_poll() unmasks Rx interrutps,
- Rx interrupt happens, rcar_canfd_global_interrupt() gets called and calls napi_schedule_prep(),
- since NAPIF_STATE_SCHED is set in state at this time, this call returns false,
- due to that false return, rcar_canfd_global_interrupt() returns without masking Rx interrupt
- and this results into IRQ storm: unmasked Rx interrupt happens again and again is misprocessed in the same way.
This patch fixes that scenario by unmasking Rx interrupts only when napi_complete_done() returns true, which means it has cleared NAPIF_STATE_SCHED in state.
--- drivers/net/can/rcar/rcar_canfd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/can/rcar/rcar_canfd.c +5 -4
@@ -1508,10 +1508,11 @@ static int rcar_canfd_rx_poll(struct napi_struct *napi, int quota)/* All packets processed */ if (num_pkts < quota) { -napi_complete_done (napi, num_pkts); -/* Enable Rx FIFO interrupts */ -rcar_canfd_set_bit (priv->base,RCANFD_RFCC (ridx), -RCANFD_RFCC_RFIE ); +if (napi_complete_done (napi, num_pkts)) { +/* Enable Rx FIFO interrupts */ +rcar_canfd_set_bit (priv->base,RCANFD_RFCC (ridx), +RCANFD_RFCC_RFIE ); + } }return num_pkts; }
Signature · 1 line
2.20.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 2/7] can: rcar_canfd: fix possible IRQ storm on high load
Quoted 3 lines
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
I don't know.
Maintainer did not respond, nor to original send nor to resend.
Marc Kleine-Budde
maintainerRe: [PATCH 2/7] can: rcar_canfd: fix possible IRQ storm on high load
Quoted 6 lines · Nikita Yushchenko
Quoted 3 lines
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
I don't know.
Maintainer did not respond, nor to original send nor to resend.
You can backport this patch to v4.9.186 and send it to Sasha
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Marc Kleine-Budde
maintainerPATCH 3/7 can: mcp251x: add error check when wq alloc failed
In reply to Marc Kleine-BuddeFrom: Weitao Hou <[email protected]>
add error check when workqueue alloc failed, and remove redundant code to make it clear.
--- drivers/net/can/spi/mcp251x.c | 49 ++++++++++++++++------------------- 1 file changed, 22 insertions(+), 27 deletions(-)
drivers/net/can/spi/mcp251x.c +22 -27
@@ -664,17 +664,6 @@ static int mcp251x_power_enable(struct regulator *reg, int enable)return regulator_disable (reg); } -static void mcp251x_open_clean (struct net_device *net) -{ -struct mcp251x_priv *priv =netdev_priv (net); -struct spi_device *spi = priv->spi; - -free_irq (spi->irq, priv); -mcp251x_hw_sleep (spi); -mcp251x_power_enable (priv->transceiver,0 ); -close_candev (net); -} -static int mcp251x_stop (struct net_device *net) {struct mcp251x_priv *priv =netdev_priv (net);
@@ -940,37 +929,43 @@ static int mcp251x_open(struct net_device *net) flags | IRQF_ONESHOT, DEVICE_NAME, priv);if (ret) {dev_err (&spi->dev,"failed to acquire irq %d\n" , spi->irq); -mcp251x_power_enable (priv->transceiver,0 ); -close_candev (net); - goto open_unlock; + goto out_close; } priv->wq =alloc_workqueue ("mcp251x_wq" ,WQ_FREEZABLE |WQ_MEM_RECLAIM ,0 ); +if (!priv->wq) { + ret = -ENOMEM ; + goto out_clean; + }INIT_WORK (&priv->tx_work, mcp251x_tx_work_handler);INIT_WORK (&priv->restart_work, mcp251x_restart_work_handler); ret =mcp251x_hw_reset (spi); -if (ret) { -mcp251x_open_clean (net); - goto open_unlock; - } +if (ret) + goto out_free_wq; ret =mcp251x_setup (net, spi); -if (ret) { -mcp251x_open_clean (net); - goto open_unlock; - } +if (ret) + goto out_free_wq; ret =mcp251x_set_normal_mode (spi); -if (ret) { -mcp251x_open_clean (net); - goto open_unlock; - } +if (ret) + goto out_free_wq;can_led_event (net,CAN_LED_EVENT_OPEN );netif_wake_queue (net); +mutex_unlock (&priv->mcp_lock); -open_unlock: +return 0 ; + +out_free_wq: +destroy_workqueue (priv->wq); +out_clean: +free_irq (spi->irq, priv); +mcp251x_hw_sleep (spi); +out_close: +mcp251x_power_enable (priv->transceiver,0 ); +close_candev (net);mutex_unlock (&priv->mcp_lock);return ret; }
Signature · 1 line
2.20.1
Marc Kleine-Budde
maintainerPATCH 4/7 can: flexcan: fix an use-after-free in flexcan_setup_stop_mode()
In reply to Marc Kleine-BuddeFrom: Wen Yang <[email protected]>
The gpr_np variable is still being used in dev_dbg() after the of_node_put() call, which may result in use-after-free.
--- drivers/net/can/flexcan.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/can/flexcan.c +5 -3
@@ -1437,10 +1437,10 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev) priv =netdev_priv (dev); priv->stm.gpr =syscon_node_to_regmap (gpr_np); -of_node_put (gpr_np);if (IS_ERR (priv->stm.gpr)) {dev_dbg (&pdev->dev,"could not find gpr regmap\n" ); -return PTR_ERR (priv->stm.gpr); + ret =PTR_ERR (priv->stm.gpr); + goto out_put_node; } priv->stm.req_gpr = out_val[1 ];
@@ -1455,7 +1455,9 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)device_set_wakeup_capable (&pdev->dev, true); -return 0 ; +out_put_node: +of_node_put (gpr_np); +return ret; }static const struct of_device_id flexcan_of_match[] = {
Signature · 1 line
2.20.1
Marc Kleine-Budde
maintainerPATCH 5/7 can: flexcan: fix stop mode acknowledgment
In reply to Marc Kleine-BuddeFrom: Joakim Zhang <[email protected]>
To enter stop mode, the CPU should manually assert a global Stop Mode request and check the acknowledgment asserted by FlexCAN. The CPU must only consider the FlexCAN in stop mode when both request and acknowledgment conditions are satisfied.
--- drivers/net/can/flexcan.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
drivers/net/can/flexcan.c +27 -4
@@ -400,9 +400,10 @@ static void flexcan_enable_wakeup_irq(struct flexcan_priv *priv, bool enable) priv->write (reg_mcr, ®s->mcr); } -static inline void flexcan_enter_stop_mode (struct flexcan_priv *priv) +static inline int flexcan_enter_stop_mode (struct flexcan_priv *priv) {struct flexcan_regs __iomem *regs = priv->regs; +unsigned int ackval;u32 reg_mcr; reg_mcr = priv->read (®s->mcr);
@@ -412,20 +413,37 @@ static inline void flexcan_enter_stop_mode(struct flexcan_priv *priv)/* enable stop request */ regmap_update_bits (priv->stm.gpr, priv->stm.req_gpr,1 << priv->stm.req_bit,1 << priv->stm.req_bit); + +/* get stop acknowledgment */ +if (regmap_read_poll_timeout (priv->stm.gpr, priv->stm.ack_gpr, + ackval, ackval & (1 << priv->stm.ack_bit), +0 ,FLEXCAN_TIMEOUT_US )) +return -ETIMEDOUT ; + +return 0 ; } -static inline void flexcan_exit_stop_mode (struct flexcan_priv *priv) +static inline int flexcan_exit_stop_mode (struct flexcan_priv *priv) {struct flexcan_regs __iomem *regs = priv->regs; +unsigned int ackval;u32 reg_mcr;/* remove stop request */ regmap_update_bits (priv->stm.gpr, priv->stm.req_gpr,1 << priv->stm.req_bit,0 ); +/* get stop acknowledgment */ +if (regmap_read_poll_timeout (priv->stm.gpr, priv->stm.ack_gpr, + ackval, !(ackval & (1 << priv->stm.ack_bit)), +0 ,FLEXCAN_TIMEOUT_US )) +return -ETIMEDOUT ; + reg_mcr = priv->read (®s->mcr); reg_mcr &= ~FLEXCAN_MCR_SLF_WAK ; priv->write (reg_mcr, ®s->mcr); + +return 0 ; }static inline void flexcan_error_irq_enable (const struct flexcan_priv *priv)
@@ -1614,7 +1632,9 @@ static int __maybe_unused flexcan_suspend(struct device *device)*/ if (device_may_wakeup (device)) {enable_irq_wake (dev->irq); -flexcan_enter_stop_mode (priv); + err =flexcan_enter_stop_mode (priv); +if (err) +return err; }else { err =flexcan_chip_disable (priv);if (err)
@@ -1664,10 +1684,13 @@ static int __maybe_unused flexcan_noirq_resume(struct device *device) {struct net_device *dev =dev_get_drvdata (device);struct flexcan_priv *priv =netdev_priv (dev); +int err;if (netif_running (dev) &&device_may_wakeup (device)) {flexcan_enable_wakeup_irq (priv, false); -flexcan_exit_stop_mode (priv); + err =flexcan_exit_stop_mode (priv); +if (err) +return err; }return 0 ;
Signature · 1 line
2.20.1
Marc Kleine-Budde
maintainerPATCH 6/7 can: peak_usb: fix potential double kfree_skb()
In reply to Marc Kleine-BuddeFrom: Stephane Grosjean <[email protected]>
When closing the CAN device while tx skbs are inflight, echo skb could be released twice. By calling close_candev() before unlinking all pending tx urbs, then the internal echo_skb[] array is fully and correctly cleared before the USB write callback and, therefore, can_get_echo_skb() are called, for each aborted URB.
--- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/can/usb/peak_usb/pcan_usb_core.c +4 -4
@@ -568,16 +568,16 @@ static int peak_usb_ndo_stop(struct net_device *netdev) dev->state &= ~PCAN_USB_STATE_STARTED ;netif_stop_queue (netdev); +close_candev (netdev); + + dev->can.state =CAN_STATE_STOPPED ; +/* unlink all pending urbs and free used memory */ peak_usb_unlink_all_urbs (dev);if (dev->adapter->dev_stop) dev->adapter->dev_stop (dev); -close_candev (netdev); - - dev->can.state =CAN_STATE_STOPPED ; -/* can set bus off now */ if (dev->adapter->dev_set_bus) {int err = dev->adapter->dev_set_bus (dev,0 );
Signature · 1 line
2.20.1
Marc Kleine-Budde
maintainerPATCH 7/7 can: gw: Fix error path of cgw_module_init
In reply to Marc Kleine-BuddeFrom: YueHaibing <[email protected]>
This patch add error path for cgw_module_init to avoid possible crash if some error occurs.
--- net/can/gw.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-)
net/can/gw.c +33 -15
@@ -1046,32 +1046,50 @@ static __init int cgw_module_init(void)pr_info ("can: netlink gateway (rev " CAN_GW_VERSION ") max_hops=%d\n" , max_hops); -register_pernet_subsys (&cangw_pernet_ops); + ret =register_pernet_subsys (&cangw_pernet_ops); +if (ret) +return ret; + + ret = -ENOMEM ; cgw_cache =kmem_cache_create ("can_gw" ,sizeof (struct cgw_job ),0 ,0 ,NULL ); -if (!cgw_cache) -return -ENOMEM ; + goto out_cache_create;/* set notifier */ notifier.notifier_call = cgw_notifier; -register_netdevice_notifier (¬ifier); + ret =register_netdevice_notifier (¬ifier); +if (ret) + goto out_register_notifier; ret =rtnl_register_module (THIS_MODULE ,PF_CAN ,RTM_GETROUTE ,NULL , cgw_dump_jobs,0 ); -if (ret) { -unregister_netdevice_notifier (¬ifier); -kmem_cache_destroy (cgw_cache); -return -ENOBUFS ; - } - -/* Only the first call to rtnl_register_module can fail */ -rtnl_register_module (THIS_MODULE ,PF_CAN ,RTM_NEWROUTE , - cgw_create_job,NULL ,0 ); -rtnl_register_module (THIS_MODULE ,PF_CAN ,RTM_DELROUTE , - cgw_remove_job,NULL ,0 ); +if (ret) + goto out_rtnl_register1; + + ret =rtnl_register_module (THIS_MODULE ,PF_CAN ,RTM_NEWROUTE , + cgw_create_job,NULL ,0 ); +if (ret) + goto out_rtnl_register2; + ret =rtnl_register_module (THIS_MODULE ,PF_CAN ,RTM_DELROUTE , + cgw_remove_job,NULL ,0 ); +if (ret) + goto out_rtnl_register3;return 0 ; + +out_rtnl_register3: +rtnl_unregister (PF_CAN ,RTM_NEWROUTE ); +out_rtnl_register2: +rtnl_unregister (PF_CAN ,RTM_GETROUTE ); +out_rtnl_register1: +unregister_netdevice_notifier (¬ifier); +out_register_notifier: +kmem_cache_destroy (cgw_cache); +out_cache_create: +unregister_pernet_subsys (&cangw_pernet_ops); + +return ret; } static __exit void cgw_module_exit(void)
Signature · 1 line
2.20.1
David Miller
maintainerFrom: Marc Kleine-Budde <[email protected]>
Date: Wed, 24 Jul 2019 15:03:15 +0200
Quoted 1 line
this is a pull reqeust of 7 patches for net/master.
Pulled, thank you.