pull-request: can 2020-11-15
Subsystems (6)
Marc Kleine-Budde
maintainerHello Jakub, hello David,
here's a pull request for net/master consisting of 15 patches for net/master, with the fixes tags corrected.
Anant Thazhemadam contributed two patches for the AF_CAN that prevent potential access of uninitialized member in can_rcv() and canfd_rcv().
The next patch is by Alejandro Concepcion Rodriguez and changes can_restart() to use the correct function to push a skb into the networking stack from process context.
Zhang Qilong's patch fixes a memory leak in the error path of the ti_hecc's probe function.
A patch by me fixes mcba_usb_start_xmit() function in the mcba_usb driver, to first fill the skb and then pass it to can_put_echo_skb().
Colin Ian King's patch fixes a potential integer overflow on shift in the peak_usb driver.
The next two patches target the flexcan driver, a patch by me adds the missing "req_bit" to the stop mode property comment (which was broken during net-next for v5.10). Zhang Qilong's patch fixes the failure handling of pm_runtime_get_sync().
The next seven patches target the m_can driver including the tcan4x5x spi driver glue code. Enric Balletbo i Serra's patch for the tcan4x5x Kconfig fix the REGMAP_SPI dependency handling. A patch by me for the tcan4x5x driver's probe() function adds missing error handling to for devm_regmap_init(), and in tcan4x5x_can_remove() the order of deregistration is fixed. Wu Bo's patch for the m_can driver fixes the state change handling in m_can_handle_state_change(). Two patches by Dan Murphy first introduce m_can_class_free_dev() and then make use of it to fix the freeing of the can device. A patch by Faiz Abbas add a missing shutdown of the CAN controller in the m_can_stop() function.
regards,
Marc
---
The following changes since commit ceb736e1d45c253f5e86b185ca9b497cdd43063f:
ipv6: Fix error path to cancel the meseage (2020-11-13 18:20:00 -0800)
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.10-20201115
for you to fetch changes up to a584e9bc1b7e88f24f8504886eafbe6c73d8a97c:
can: m_can: m_can_stop(): set device to software init mode before closing (2020-11-15 18:33:45 +0100)
----------------------------------------------------------------
linux-can-fixes-for-5.10-20201115
----------------------------------------------------------------
Alejandro Concepcion Rodriguez (1):
can: dev: can_restart(): post buffer from the right context
Anant Thazhemadam (2):
can: af_can: prevent potential access of uninitialized member in can_rcv()
can: af_can: prevent potential access of uninitialized member in canfd_rcv()
Colin Ian King (1):
can: peak_usb: fix potential integer overflow on shift of a int
Dan Murphy (2):
can: m_can: m_can_class_free_dev(): introduce new function
can: m_can: Fix freeing of can device from peripherials
Enric Balletbo i Serra (1):
can: tcan4x5x: replace depends on REGMAP_SPI with depends on SPI
Faiz Abbas (1):
can: m_can: m_can_stop(): set device to software init mode before closing
Marc Kleine-Budde (4):
can: mcba_usb: mcba_usb_start_xmit(): first fill skb, then pass to can_put_echo_skb()
can: flexcan: flexcan_setup_stop_mode(): add missing "req_bit" to stop mode property comment
can: tcan4x5x: tcan4x5x_can_probe(): add missing error checking for devm_regmap_init()
can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration
Wu Bo (1):
can: m_can: m_can_handle_state_change(): fix state change
Zhang Qilong (2):
can: ti_hecc: Fix memleak in ti_hecc_probe
can: flexcan: fix failure handling of pm_runtime_get_sync()
drivers/net/can/dev.c | 2 +- drivers/net/can/flexcan.c | 10 +++++--- drivers/net/can/m_can/Kconfig | 3 ++- drivers/net/can/m_can/m_can.c | 16 ++++++++---- drivers/net/can/m_can/m_can.h | 1 + drivers/net/can/m_can/m_can_platform.c | 23 +++++++++++------ drivers/net/can/m_can/tcan4x5x.c | 32 ++++++++++++++++------- drivers/net/can/ti_hecc.c | 13 ++++++---- drivers/net/can/usb/mcba_usb.c | 4 +-- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 4 +-- net/can/af_can.c | 38 ++++++++++++++++++++-------- 11 files changed, 100 insertions(+), 46 deletions(-)
Marc Kleine-Budde
maintainerPATCH 1/15 can: af_can: prevent potential access of uninitialized member in can_rcv()
From: Anant Thazhemadam <[email protected]>
In can_rcv(), cfd->len is uninitialized when skb->len = 0, and this uninitialized cfd->len is accessed nonetheless by pr_warn_once().
Fix this uninitialized variable access by checking cfd->len's validity condition (cfd->len > CAN_MAX_DLEN) separately after the skb->len's condition is checked, and appropriately modify the log messages that are generated as well.
In case either of the required conditions fail, the skb is freed and NET_RX_DROP is returned, same as before.
--- net/can/af_can.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
net/can/af_can.c +14 -5
@@ -677,16 +677,25 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev, {struct canfd_frame *cfd = (struct canfd_frame *)skb->data; -if (unlikely (dev->type !=ARPHRD_CAN || skb->len !=CAN_MTU || - cfd->len >CAN_MAX_DLEN )) { -pr_warn_once ("PF_CAN: dropped non conform CAN skbuf: dev type %d, len %d, datalen %d\n" , +if (unlikely (dev->type !=ARPHRD_CAN || skb->len !=CAN_MTU )) { +pr_warn_once ("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n" , + dev->type, skb->len); + goto free_skb; + } + +/* This check is made separately since cfd->len would be uninitialized if skb->len = 0. */ +if (unlikely (cfd->len >CAN_MAX_DLEN )) { +pr_warn_once ("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d, datalen %d\n" , dev->type, skb->len, cfd->len); -kfree_skb (skb); -return NET_RX_DROP ; + goto free_skb; }can_receive (skb, dev);return NET_RX_SUCCESS ; + +free_skb: +kfree_skb (skb); +return NET_RX_DROP ; } static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
base-commit: ceb736e1d45c253f5e86b185ca9b497cdd43063f
Signature · 1 line
2.29.2
Marc Kleine-Budde
maintainerPATCH 2/15 can: af_can: prevent potential access of uninitialized member in canfd_rcv()
In reply to Marc Kleine-BuddeFrom: Anant Thazhemadam <[email protected]>
In canfd_rcv(), cfd->len is uninitialized when skb->len = 0, and this uninitialized cfd->len is accessed nonetheless by pr_warn_once().
Fix this uninitialized variable access by checking cfd->len's validity condition (cfd->len > CANFD_MAX_DLEN) separately after the skb->len's condition is checked, and appropriately modify the log messages that are generated as well.
In case either of the required conditions fail, the skb is freed and NET_RX_DROP is returned, same as before.
--- net/can/af_can.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
net/can/af_can.c +14 -5
@@ -703,16 +703,25 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev, {struct canfd_frame *cfd = (struct canfd_frame *)skb->data; -if (unlikely (dev->type !=ARPHRD_CAN || skb->len !=CANFD_MTU || - cfd->len >CANFD_MAX_DLEN )) { -pr_warn_once ("PF_CAN: dropped non conform CAN FD skbuf: dev type %d, len %d, datalen %d\n" , +if (unlikely (dev->type !=ARPHRD_CAN || skb->len !=CANFD_MTU )) { +pr_warn_once ("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d\n" , + dev->type, skb->len); + goto free_skb; + } + +/* This check is made separately since cfd->len would be uninitialized if skb->len = 0. */ +if (unlikely (cfd->len >CANFD_MAX_DLEN )) { +pr_warn_once ("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d, datalen %d\n" , dev->type, skb->len, cfd->len); -kfree_skb (skb); -return NET_RX_DROP ; + goto free_skb; }can_receive (skb, dev);return NET_RX_SUCCESS ; + +free_skb: +kfree_skb (skb); +return NET_RX_DROP ; }/* af_can protocol functions */
Signature · 1 line
2.29.2
Marc Kleine-Budde
maintainerPATCH 3/15 can: dev: can_restart(): post buffer from the right context
In reply to Marc Kleine-BuddeFrom: Alejandro Concepcion Rodriguez <[email protected]>
netif_rx() is meant to be called from interrupt contexts. can_restart() may be called by can_restart_work(), which is called from a worqueue, so it may run in process context. Use netif_rx_ni() instead.
--- drivers/net/can/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/dev.c +1 -1
@@ -592,7 +592,7 @@ static void can_restart(struct net_device *dev) cf->can_id |=CAN_ERR_RESTARTED ; -netif_rx (skb); +netif_rx_ni (skb); stats->rx_packets++; stats->rx_bytes += cf->can_dlc;
Signature · 1 line
2.29.2
Marc Kleine-Budde
maintainerPATCH 4/15 can: ti_hecc: Fix memleak in ti_hecc_probe
In reply to Marc Kleine-BuddeFrom: Zhang Qilong <[email protected]>
In the error handling, we should goto the probe_exit_candev to free ndev to prevent memory leak.
--- drivers/net/can/ti_hecc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/can/ti_hecc.c +8 -5
@@ -881,7 +881,8 @@ static int ti_hecc_probe(struct platform_device *pdev) priv->base =devm_platform_ioremap_resource_byname (pdev,"hecc" );if (IS_ERR (priv->base)) {dev_err (&pdev->dev,"hecc ioremap failed\n" ); -return PTR_ERR (priv->base); + err =PTR_ERR (priv->base); + goto probe_exit_candev; }/* handle hecc-ram memory */
@@ -889,20 +890,22 @@ static int ti_hecc_probe(struct platform_device *pdev) "hecc-ram");if (IS_ERR (priv->hecc_ram)) {dev_err (&pdev->dev,"hecc-ram ioremap failed\n" ); -return PTR_ERR (priv->hecc_ram); + err =PTR_ERR (priv->hecc_ram); + goto probe_exit_candev; }/* handle mbx memory */ priv->mbx =devm_platform_ioremap_resource_byname (pdev,"mbx" );if (IS_ERR (priv->mbx)) {dev_err (&pdev->dev,"mbx ioremap failed\n" ); -return PTR_ERR (priv->mbx); + err =PTR_ERR (priv->mbx); + goto probe_exit_candev; } irq =platform_get_resource (pdev,IORESOURCE_IRQ ,0 );if (!irq) {dev_err (&pdev->dev,"No irq resource\n" ); - goto probe_exit; + goto probe_exit_candev; } priv->ndev = ndev;
@@ -966,7 +969,7 @@ static int ti_hecc_probe(struct platform_device *pdev)clk_put (priv->clk); probe_exit_candev:free_candev (ndev); -probe_exit: +return err; }
Signature · 1 line
2.29.2
Marc Kleine-Budde
maintainerPATCH 5/15 can: mcba_usb: mcba_usb_start_xmit(): first fill skb, then pass to can_put_echo_skb()
In reply to Marc Kleine-BuddeThe driver has to first fill the skb with data and then handle it to can_put_echo_skb(). This patch moves the can_put_echo_skb() down, right before sending the skb out via USB.
--- drivers/net/can/usb/mcba_usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/usb/mcba_usb.c +2 -2
@@ -326,8 +326,6 @@ static netdev_tx_t mcba_usb_start_xmit(struct sk_buff *skb,if (!ctx)return NETDEV_TX_BUSY ; -can_put_echo_skb (skb, priv->netdev, ctx->ndx); -if (cf->can_id &CAN_EFF_FLAG ) {/* SIDH | SIDL | EIDH | EIDL * 28 - 21 | 20 19 18 x x x 17 16 | 15 - 8 | 7 - 0
@@ -357,6 +355,8 @@ static netdev_tx_t mcba_usb_start_xmit(struct sk_buff *skb,if (cf->can_id &CAN_RTR_FLAG ) usb_msg.dlc |=MCBA_DLC_RTR_MASK ; +can_put_echo_skb (skb, priv->netdev, ctx->ndx); + err =mcba_usb_xmit (priv, (struct mcba_usb_msg *)&usb_msg, ctx);if (err) goto xmit_failed;
Signature · 1 line
2.29.2
Marc Kleine-Budde
maintainerPATCH 6/15 can: peak_usb: fix potential integer overflow on shift of a int
In reply to Marc Kleine-BuddeFrom: Colin Ian King <[email protected]>
The left shift of int 32 bit integer constant 1 is evaluated using 32 bit arithmetic and then assigned to a signed 64 bit variable. In the case where time_ref->adapter->ts_used_bits is 32 or more this can lead to an oveflow. Avoid this by shifting using the BIT_ULL macro instead.
--- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/usb/peak_usb/pcan_usb_core.c +2 -2
@@ -156,7 +156,7 @@ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time)if (time_ref->ts_dev_1 < time_ref->ts_dev_2) {/* case when event time (tsw) wraps */ if (ts < time_ref->ts_dev_1) - delta_ts =1 << time_ref->adapter->ts_used_bits; + delta_ts =BIT_ULL (time_ref->adapter->ts_used_bits);/* Otherwise, sync time counter (ts_dev_2) has wrapped: * handle case when event time (tsn) hasn't.
@@ -168,7 +168,7 @@ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time)* tsn ts */ }else if (time_ref->ts_dev_1 < ts) { - delta_ts = -(1 << time_ref->adapter->ts_used_bits); + delta_ts = -BIT_ULL (time_ref->adapter->ts_used_bits); }/* add delay between last sync and event timestamps */
Signature · 1 line
2.29.2
Marc Kleine-Budde
maintainerPATCH 7/15 can: flexcan: flexcan_setup_stop_mode(): add missing "req_bit" to stop mode property comment
In reply to Marc Kleine-BuddeIn the patch
d9b081e3fc4b ("can: flexcan: remove ack_grp and ack_bit handling from driver")
the unused ack_grp and ack_bit were removed from the driver. However in the comment, the "req_bit" was accidentally removed, too.
This patch adds back the "req_bit" bit.
--- drivers/net/can/flexcan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/flexcan.c +1 -1
@@ -1852,7 +1852,7 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)return -EINVAL ;/* stop mode property format is: -* <&gpr req_gpr>. +* <&gpr req_gpr req_bit>. */ ret =of_property_read_u32_array (np,"fsl,stop-mode" , out_val,ARRAY_SIZE (out_val));
Signature · 1 line
2.29.2
Marc Kleine-Budde
maintainerPATCH 8/15 can: flexcan: fix failure handling of pm_runtime_get_sync()
In reply to Marc Kleine-BuddeFrom: Zhang Qilong <[email protected]>
pm_runtime_get_sync() will increment pm usage at first and it will resume the device later. If runtime of the device has error or device is in inaccessible state(or other error state), resume operation will fail. If we do not call put operation to decrease the reference, it will result in reference leak in the two functions flexcan_get_berr_counter() and flexcan_open().
Moreover, this device cannot enter the idle state and always stay busy or other non-idle state later. So we should fix it through adding pm_runtime_put_noidle().
--- drivers/net/can/flexcan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/can/flexcan.c +6 -2
@@ -728,8 +728,10 @@ static int flexcan_get_berr_counter(const struct net_device *dev,int err; err =pm_runtime_get_sync (priv->dev); -if (err <0 ) +if (err <0 ) { +pm_runtime_put_noidle (priv->dev);return err; + } err =__flexcan_get_berr_counter (dev, bec);
@@ -1654,8 +1656,10 @@ static int flexcan_open(struct net_device *dev) } err =pm_runtime_get_sync (priv->dev); -if (err <0 ) +if (err <0 ) { +pm_runtime_put_noidle (priv->dev);return err; + } err =open_candev (dev);if (err)
Signature · 1 line
2.29.2
Marc Kleine-Budde
maintainerPATCH 9/15 can: tcan4x5x: replace depends on REGMAP_SPI with depends on SPI
In reply to Marc Kleine-BuddeFrom: Enric Balletbo i Serra <[email protected]>
regmap is a library function that gets selected by drivers that need it. No driver modules should depend on it. Instead depends on SPI and select REGMAP_SPI. Depending on REGMAP_SPI makes this driver only build if another driver already selected REGMAP_SPI, as the symbol can't be selected through the menu kernel configuration.
--- drivers/net/can/m_can/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/can/m_can/Kconfig +2 -1
@@ -16,7 +16,8 @@ config CAN_M_CAN_PLATFORM config CAN_M_CAN_TCAN4X5X depends on CAN_M_CAN - depends on REGMAP_SPI + depends on SPI + select REGMAP_SPI tristate "TCAN4X5X M_CAN device" help Say Y here if you want support for Texas Instruments TCAN4x5x
Signature · 1 line
2.29.2
Marc Kleine-Budde
maintainerPATCH 10/15 can: tcan4x5x: tcan4x5x_can_probe(): add missing error checking for devm_regmap_init()
In reply to Marc Kleine-BuddeThis patch adds the missing error checking when initializing the regmap interface fails.
--- drivers/net/can/m_can/tcan4x5x.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/can/m_can/tcan4x5x.c +4 -0
@@ -487,6 +487,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi) priv->regmap =devm_regmap_init (&spi->dev, &tcan4x5x_bus, &spi->dev, &tcan4x5x_regmap); +if (IS_ERR (priv->regmap)) { + ret =PTR_ERR (priv->regmap); + goto out_clk; + } ret =tcan4x5x_power_enable (priv->power,1 );if (ret)
Signature · 1 line
2.29.2
Re: [net 10/15] can: tcan4x5x: tcan4x5x_can_probe(): add missing error checking for devm_regmap_init()
Marc
Quoted 16 lines · Marc Kleine-Budde
This patch adds the missing error checking when initializing the regmap interface fails.
Fixes 5443c226ba91 ("can: tcan4x5x: Add tcan4x5x driver to the kernel")Cc Dan Murphy <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>--- drivers/net/can/m_can/tcan4x5x.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/can/m_can/tcan4x5x.c +0
-0
drivers/net/can/m_can/tcan4x5x.c static int tcan4x5x_can_probe(struct spi_device *spi) · line 496
Quoted 10 lines
drivers/net/can/m_can/tcan4x5x.c +4
-0@@ -487,6 +487,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi) priv->regmap =devm_regmap_init (&spi->dev, &tcan4x5x_bus, &spi->dev, &tcan4x5x_regmap); +if (IS_ERR (priv->regmap)) { + ret =PTR_ERR (priv->regmap); + goto out_clk; + } ret =tcan4x5x_power_enable (priv->power,1 );if (ret)
Marc Kleine-Budde
maintainerPATCH 11/15 can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration
In reply to Marc Kleine-BuddeChange the order in tcan4x5x_can_remove() to be the exact inverse of tcan4x5x_can_probe(). First m_can_class_unregister(), then power down the device.
--- drivers/net/can/m_can/tcan4x5x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/m_can/tcan4x5x.c +2 -2
@@ -527,10 +527,10 @@ static int tcan4x5x_can_remove(struct spi_device *spi) {struct tcan4x5x_priv *priv =spi_get_drvdata (spi); -tcan4x5x_power_enable (priv->power,0 ); -m_can_class_unregister (priv->mcan_dev); +tcan4x5x_power_enable (priv->power,0 ); +return 0 ; }
Signature · 1 line
2.29.2
Re: [net 11/15] can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration
Marc
Quoted 19 lines · Marc Kleine-Budde
Change the order in
tcan4x5x_can_remove()to be the exact inverse oftcan4x5x_can_probe(). Firstm_can_class_unregister(), then power down the device.Fixes 5443c226ba91 ("can: tcan4x5x: Add tcan4x5x driver to the kernel")Cc Dan Murphy <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>--- drivers/net/can/m_can/tcan4x5x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/can/m_can/tcan4x5x.c +0
-0@@ -527,10 +527,10 @@ static int tcan4x5x_can_remove(struct spi_device *spi) {struct tcan4x5x_priv *priv =spi_get_drvdata (spi);
drivers/net/can/m_can/tcan4x5x.c static int tcan4x5x_can_remove(struct spi_device *spi) · line 536
Quoted 10 lines
drivers/net/can/m_can/tcan4x5x.c +2
-2-tcan4x5x_power_enable (priv->power,0 ); -m_can_class_unregister (priv->mcan_dev); +tcan4x5x_power_enable (priv->power,0 ); +return 0 ; }
Marc Kleine-Budde
maintainerRe: [net 11/15] can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration
Quoted 1 line · Dan Murphy
Reviewed-by Dan Murphy<[email protected]>
Thanks. The patches are already mainline.
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Marc Kleine-Budde
maintainerPATCH 12/15 can: m_can: m_can_handle_state_change(): fix state change
In reply to Marc Kleine-BuddeFrom: Wu Bo <[email protected]>
m_can_handle_state_change() is called with the new_state as an argument.
In the switch statements for CAN_STATE_ERROR_ACTIVE, the comment and the following code indicate that a CAN_STATE_ERROR_WARNING is handled.
This patch fixes this problem by changing the case to CAN_STATE_ERROR_WARNING.
--- drivers/net/can/m_can/m_can.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/m_can/m_can.c +2 -2
@@ -665,7 +665,7 @@ static int m_can_handle_state_change(struct net_device *dev,unsigned int ecr;switch (new_state) { -case CAN_STATE_ERROR_ACTIVE : +case CAN_STATE_ERROR_WARNING :/* error warning state */ cdev->can.can_stats.error_warning++; cdev->can.state =CAN_STATE_ERROR_WARNING ;
@@ -694,7 +694,7 @@ static int m_can_handle_state_change(struct net_device *dev,__m_can_get_berr_counter (dev, &bec);switch (new_state) { -case CAN_STATE_ERROR_ACTIVE : +case CAN_STATE_ERROR_WARNING :/* error warning state */ cf->can_id |=CAN_ERR_CRTL ; cf->data[1] = (bec.txerr > bec.rxerr) ?
Signature · 1 line
2.29.2
Re: [net 12/15] can: m_can: m_can_handle_state_change(): fix state change
Marc
Quoted 32 lines · Marc Kleine-Budde
From: Wu Bo <[email protected]>
m_can_handle_state_change()is called with thenew_stateas an argument.In the switch statements for
CAN_STATE_ERROR_ACTIVE, the comment and the following code indicate that aCAN_STATE_ERROR_WARNINGis handled.This patch fixes this problem by changing the case to
CAN_STATE_ERROR_WARNING.Signed-off-by Wu Bo <[email protected]>Cc Dan Murphy <[email protected]>Fixes e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")Signed-off-by Marc Kleine-Budde <[email protected]>--- drivers/net/can/m_can/m_can.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/can/m_can/m_can.c +1
-1@@ -665,7 +665,7 @@ static int m_can_handle_state_change(struct net_device *dev,unsigned int ecr;switch (new_state) { -case CAN_STATE_ERROR_ACTIVE : +case CAN_STATE_ERROR_WARNING :/* error warning state */ cdev->can.can_stats.error_warning++; cdev->can.state =CAN_STATE_ERROR_WARNING ;
drivers/net/can/m_can/m_can.c static int m_can_handle_state_change(struct net_device *dev, · line 700
Quoted 8 lines
drivers/net/can/m_can/m_can.c +1
-1@@ -694,7 +694,7 @@ static int m_can_handle_state_change(struct net_device *dev,__m_can_get_berr_counter (dev, &bec);switch (new_state) { -case CAN_STATE_ERROR_ACTIVE : +case CAN_STATE_ERROR_WARNING :/* error warning state */ cf->can_id |=CAN_ERR_CRTL ; cf->data[1] = (bec.txerr > bec.rxerr) ?
Marc Kleine-Budde
maintainerPATCH 13/15 can: m_can: m_can_class_free_dev(): introduce new function
In reply to Marc Kleine-BuddeFrom: Dan Murphy <[email protected]>
This patch creates a common function that peripherials can call to free the netdev device when failures occur.
--- drivers/net/can/m_can/m_can.c | 6 ++++++ drivers/net/can/m_can/m_can.h | 1 + 2 files changed, 7 insertions(+)
drivers/net/can/m_can/m_can.c +6 -0
@@ -1812,6 +1812,12 @@ struct m_can_classdev *m_can_class_allocate_dev(struct device *dev) }EXPORT_SYMBOL_GPL (m_can_class_allocate_dev); +void m_can_class_free_dev (struct net_device *net) +{ +free_candev (net); +} +EXPORT_SYMBOL_GPL (m_can_class_free_dev); +int m_can_class_register (struct m_can_classdev *m_can_dev) {int ret;
drivers/net/can/m_can/m_can.h +1 -0
@@ -99,6 +99,7 @@ struct m_can_classdev { };struct m_can_classdev *m_can_class_allocate_dev (struct device *dev); +void m_can_class_free_dev (struct net_device *net);int m_can_class_register (struct m_can_classdev *cdev);void m_can_class_unregister (struct m_can_classdev *cdev);int m_can_class_get_clocks (struct m_can_classdev *cdev);
Signature · 1 line
2.29.2
Marc Kleine-Budde
maintainerPATCH 14/15 can: m_can: Fix freeing of can device from peripherials
In reply to Marc Kleine-BuddeFrom: Dan Murphy <[email protected]>
Fix leaking netdev device from peripherial devices. The call to allocate the netdev device is made from and managed by the peripherial.
--- drivers/net/can/m_can/m_can.c | 3 --- drivers/net/can/m_can/m_can_platform.c | 23 +++++++++++++++-------- drivers/net/can/m_can/tcan4x5x.c | 26 ++++++++++++++++++-------- 3 files changed, 33 insertions(+), 19 deletions(-)
drivers/net/can/m_can/m_can.c +0 -3
@@ -1856,7 +1856,6 @@ int m_can_class_register(struct m_can_classdev *m_can_dev)if (ret) {if (m_can_dev->pm_clock_support)pm_runtime_disable (m_can_dev->dev); -free_candev (m_can_dev->net); }return ret;
@@ -1914,8 +1913,6 @@ void m_can_class_unregister(struct m_can_classdev *m_can_dev)unregister_candev (m_can_dev->net);m_can_clk_stop (m_can_dev); - -free_candev (m_can_dev->net); }EXPORT_SYMBOL_GPL (m_can_class_unregister);
drivers/net/can/m_can/m_can_platform.c +15 -8
@@ -67,32 +67,36 @@ static int m_can_plat_probe(struct platform_device *pdev)return -ENOMEM ; priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL ); -if (!priv) -return -ENOMEM ; +if (!priv) { + ret = -ENOMEM ; + goto probe_fail; + } mcan_class->device_data = priv; -m_can_class_get_clocks (mcan_class); + ret =m_can_class_get_clocks (mcan_class); +if (ret) + goto probe_fail; res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"m_can" ); addr =devm_ioremap_resource (&pdev->dev, res); irq =platform_get_irq_byname (pdev,"int0" );if (IS_ERR (addr) || irq <0 ) { ret = -EINVAL ; - goto failed_ret; + goto probe_fail; }/* message ram could be shared */ res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"message_ram" );if (!res) { ret = -ENODEV ; - goto failed_ret; + goto probe_fail; } mram_addr =devm_ioremap (&pdev->dev, res->start,resource_size (res));if (!mram_addr) { ret = -ENOMEM ; - goto failed_ret; + goto probe_fail; } priv->base = addr;
@@ -111,9 +115,10 @@ static int m_can_plat_probe(struct platform_device *pdev)m_can_init_ram (mcan_class); - ret =m_can_class_register (mcan_class); +return m_can_class_register (mcan_class); -failed_ret: +probe_fail: +m_can_class_free_dev (mcan_class->net);return ret; }
@@ -134,6 +139,8 @@ static int m_can_plat_remove(struct platform_device *pdev)m_can_class_unregister (mcan_class); +m_can_class_free_dev (mcan_class->net); +platform_set_drvdata (pdev,NULL );return 0 ;
drivers/net/can/m_can/tcan4x5x.c +18 -8
@@ -440,14 +440,18 @@ static int tcan4x5x_can_probe(struct spi_device *spi)return -ENOMEM ; priv =devm_kzalloc (&spi->dev,sizeof (*priv),GFP_KERNEL ); -if (!priv) -return -ENOMEM ; +if (!priv) { + ret = -ENOMEM ; + goto out_m_can_class_free_dev; + } priv->power =devm_regulator_get_optional (&spi->dev,"vsup" ); -if (PTR_ERR (priv->power) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; -else +if (PTR_ERR (priv->power) == -EPROBE_DEFER ) { + ret = -EPROBE_DEFER ; + goto out_m_can_class_free_dev; + }else { priv->power =NULL ; + } mcan_class->device_data = priv;
@@ -460,8 +464,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi) }/* Sanity check */ -if (freq <20000000 || freq >TCAN4X5X_EXT_CLK_DEF ) -return -ERANGE ; +if (freq <20000000 || freq >TCAN4X5X_EXT_CLK_DEF ) { + ret = -ERANGE ; + goto out_m_can_class_free_dev; + } priv->reg_offset =TCAN4X5X_MCAN_OFFSET ; priv->mram_start =TCAN4X5X_MRAM_START ;
@@ -518,8 +524,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi)clk_disable_unprepare (mcan_class->cclk);clk_disable_unprepare (mcan_class->hclk); } - + out_m_can_class_free_dev: +m_can_class_free_dev (mcan_class->net);dev_err (&spi->dev,"Probe failed, err=%d\n" , ret); +return ret; }
@@ -531,6 +539,8 @@ static int tcan4x5x_can_remove(struct spi_device *spi)tcan4x5x_power_enable (priv->power,0 ); +m_can_class_free_dev (priv->mcan_dev->net); +return 0 ; }
Signature · 1 line
2.29.2
Marc Kleine-Budde
maintainerPATCH 15/15 can: m_can: m_can_stop(): set device to software init mode before closing
In reply to Marc Kleine-BuddeFrom: Faiz Abbas <[email protected]>
There might be some requests pending in the buffer when the interface close sequence occurs. In some devices, these pending requests might lead to the module not shutting down properly when m_can_clk_stop() is called.
Therefore, move the device to init state before potentially powering it down.
--- drivers/net/can/m_can/m_can.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/can/m_can/m_can.c +3 -0
@@ -1414,6 +1414,9 @@ static void m_can_stop(struct net_device *dev)/* disable all interrupts */ m_can_disable_all_interrupts (cdev); +/* Set init mode to disengage from the network */ +m_can_config_endisable (cdev, true); +/* set the state as STOPPED */ cdev->can.state =CAN_STATE_STOPPED ; }
Signature · 1 line
2.29.2
Jakub Kicinski
maintainerQuoted 21 lines · On Sun, 15 Nov 2020 18:41:16 +0100 Marc Kleine-Budde wrote:
Anant Thazhemadam contributed two patches for the
AF_CANthat prevent potential access of uninitialized member incan_rcv()andcanfd_rcv().The next patch is by Alejandro Concepcion Rodriguez and changes
can_restart()to use the correct function to push a skb into the networking stack from process context.Zhang Qilong's patch fixes a memory leak in the error path of the ti_hecc's probe function.
A patch by me fixes
mcba_usb_start_xmit()function in themcba_usbdriver, to first fill the skb and then pass it tocan_put_echo_skb().Colin Ian King's patch fixes a potential integer overflow on shift in the
peak_usbdriver.The next two patches target the flexcan driver, a patch by me adds the missing "
req_bit" to the stop mode property comment (which was broken during net-next for v5.10). Zhang Qilong's patch fixes the failure handling ofpm_runtime_get_sync().
Quoted 10 lines
The next seven patches target the
m_candriver including the tcan4x5x spi driver glue code. Enric Balletbo i Serra's patch for the tcan4x5xKconfigfix theREGMAP_SPIdependency handling. A patch by me for the tcan4x5x driver'sprobe()function adds missing error handling to fordevm_regmap_init(), and intcan4x5x_can_remove()the order of deregistration is fixed. Wu Bo's patch for them_candriver fixes the state change handling inm_can_handle_state_change(). Two patches by Dan Murphy first introducem_can_class_free_dev()and then make use of it to fix the freeing of the can device. A patch by Faiz Abbas add a missing shutdown of the CAN controller in them_can_stop()function.
Pulled, thanks!