Skip to contentSkip to conversation

pull-request: can 2022-11-24

PATCH Applied Marc Kleine-Budde 2 participants 10 messages Nov 24, 2022 – Nov 25, 2022

Subsystems (8)
lore
Share & tools
lore

Marc Kleine-Budde

author maintainer
#0 lore raw

cover pull-request: can 2022-11-24

Hello Jakub, hello David,

this is a pull request of 8 patches for net/master.

Ziyang Xuan contributes a patch for the can327, fixing a potential SKB leak when the netdev is down.

Heiko Schocher's patch for the sja1000 driver fixes the width of the definition of the OCR_MODE_MASK.

Zhang Changzhong contributes 4 patches. In the sja1000_isa, cc770, and m_can_pci drivers the error path in the probe() function and in case of the etas_es58x a function that is called by probe() are fixed.

Jiasheng Jiang add a missing check for the return value of the devm_clk_get() in the m_can driver.

Yasushi SHOJI's patch for the mcba_usb fixes setting of the external termination resistor.

regards,
Marc

---

The following changes since commit ad17c2a3f11b0f6b122e7842d8f7d9a5fcc7ac63:

octeontx2-af: Fix reference count issue in rvu_sdp_init() (2022-11-24 10:01:42 +0100)

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

for you to fetch changes up to 1a8e3bd25f1e789c8154e11ea24dc3ec5a4c1da0:

can: mcba_usb: Fix termination command argument (2022-11-24 16:26:48 +0100)

----------------------------------------------------------------
linux-can-fixes-for-6.1-20221124

----------------------------------------------------------------
Heiko Schocher (1):
can: sja1000: fix size of OCR_MODE_MASK define

Jiasheng Jiang (1):
can: m_can: Add check for devm_clk_get

Yasushi SHOJI (1):
can: mcba_usb: Fix termination command argument

Zhang Changzhong (4):
can: sja1000_isa: sja1000_isa_probe(): add missing free_sja1000dev()
can: cc770: cc770_isa_probe(): add missing free_cc770dev()
can: etas_es58x: es58x_init_netdev(): free netdev when register_candev()
can: m_can: pci: add missing m_can_class_free_dev() in probe/remove methods

Ziyang Xuan (1):
can: can327: can327_feed_frame_to_netdev(): fix potential skb leak when netdev is down

 drivers/net/can/can327.c                    |  4 +++-
 drivers/net/can/cc770/cc770_isa.c           | 10 ++++++----
 drivers/net/can/m_can/m_can.c               |  2 +-
 drivers/net/can/m_can/m_can_pci.c           |  9 ++++++---
 drivers/net/can/sja1000/sja1000_isa.c       | 10 ++++++----
 drivers/net/can/usb/etas_es58x/es58x_core.c |  5 ++++-
 drivers/net/can/usb/mcba_usb.c              | 10 +++++++---
 include/linux/can/platform/sja1000.h        |  2 +-
 8 files changed, 34 insertions(+), 18 deletions(-)
author maintainer
#1 lore raw

PATCH 1/8 can: can327: can327_feed_frame_to_netdev(): fix potential skb leak when netdev is down

From: Ziyang Xuan <[email protected]>

In can327_feed_frame_to_netdev(), it did not free the skb when netdev is down, and all callers of can327_feed_frame_to_netdev() did not free allocated skb too. That would trigger skb leak.

Fix it by adding kfree_skb() in can327_feed_frame_to_netdev() when netdev is down. Not tested, just compiled.

Fixes 43da2f07622f ("can: can327: CAN/ldisc driver for ELM327 based OBD-II adapters")
---
 drivers/net/can/can327.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/can/can327.c +3 -1
index 094197780776..ed3d0b8989a0 100644
@@ -263,8 +263,10 @@ static void can327_feed_frame_to_netdev(struct can327 *elm, struct sk_buff *skb)
 {
 	lockdep_assert_held(&elm->lock);
 
-	if (!netif_running(elm->dev))
+	if (!netif_running(elm->dev)) {
+		kfree_skb(skb);
 		return;
+	}
 
 	/* Queue for NAPI pickup.
 	 * rx-offload will update stats and LEDs for us.

base-commit: ad17c2a3f11b0f6b122e7842d8f7d9a5fcc7ac63

Signature · 1 line
2.35.1
#2 lore raw

Re: [PATCH net 1/8] can: can327: can327_feed_frame_to_netdev(): fix potential skb leak when netdev is down

This series was applied to netdev/net.git (master) by Marc Kleine-Budde <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by Marc Kleine-Budde <[email protected]>:

Quoted 10 lines · On Thu, 24 Nov 2022 20:57:01 +0100 you wrote:

From: Ziyang Xuan <[email protected]>

In can327_feed_frame_to_netdev(), it did not free the skb when netdev is down, and all callers of can327_feed_frame_to_netdev() did not free allocated skb too. That would trigger skb leak.

Fix it by adding kfree_skb() in can327_feed_frame_to_netdev() when netdev is down. Not tested, just compiled.

[...]

Here is the summary with links:
- [net,1/8] can: can327: can327_feed_frame_to_netdev(): fix potential skb leak when netdev is down

    https://git.kernel.org/netdev/net/c/8fa452cfafed
  - [net,2/8] can: sja1000: fix size of OCR_MODE_MASK define
    https://git.kernel.org/netdev/net/c/26e8f6a75248
  - [net,3/8] can: sja1000_isa: sja1000_isa_probe(): add missing free_sja1000dev()
    https://git.kernel.org/netdev/net/c/92dfd9310a71
  - [net,4/8] can: cc770: cc770_isa_probe(): add missing free_cc770dev()
    https://git.kernel.org/netdev/net/c/62ec89e74099
  - [net,5/8] can: etas_es58x: es58x_init_netdev(): free netdev when register_candev()
    https://git.kernel.org/netdev/net/c/709cb2f9ed20
  - [net,6/8] can: m_can: pci: add missing m_can_class_free_dev() in probe/remove methods
    https://git.kernel.org/netdev/net/c/1eca1d4cc21b
  - [net,7/8] can: m_can: Add check for devm_clk_get
    https://git.kernel.org/netdev/net/c/68b4f9e0bdd0
  - [net,8/8] can: mcba_usb: Fix termination command argument
    https://git.kernel.org/netdev/net/c/1a8e3bd25f1e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
author maintainer
#3 lore raw

PATCH 2/8 can: sja1000: fix size of OCR_MODE_MASK define

In reply to Marc Kleine-Budde

From: Heiko Schocher <[email protected]>

bitfield mode in ocr register has only 2 bits not 3, so correct the OCR_MODE_MASK define.

---
 include/linux/can/platform/sja1000.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/can/platform/sja1000.h +1 -1
index 5755ae5a4712..6a869682c120 100644
@@ -14,7 +14,7 @@
 #define OCR_MODE_TEST     0x01
 #define OCR_MODE_NORMAL   0x02
 #define OCR_MODE_CLOCK    0x03
-#define OCR_MODE_MASK     0x07
+#define OCR_MODE_MASK     0x03
 #define OCR_TX0_INVERT    0x04
 #define OCR_TX0_PULLDOWN  0x08
 #define OCR_TX0_PULLUP    0x10
Signature · 1 line
2.35.1
author maintainer
#4 lore raw

PATCH 3/8 can: sja1000_isa: sja1000_isa_probe(): add missing free_sja1000dev()

In reply to Marc Kleine-Budde

From: Zhang Changzhong <[email protected]>

Add the missing free_sja1000dev() before return from sja1000_isa_probe() in the register_sja1000dev() error handling case.

In addition, remove blanks before goto labels.

Fixes 2a6ba39ad6a2 ("can: sja1000: legacy SJA1000 ISA bus driver")
---
 drivers/net/can/sja1000/sja1000_isa.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/can/sja1000/sja1000_isa.c +6 -4
index d513fac50718..db3e767d5320 100644
@@ -202,22 +202,24 @@ static int sja1000_isa_probe(struct platform_device *pdev)
 	if (err) {
 		dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
 			DRV_NAME, err);
-		goto exit_unmap;
+		goto exit_free;
 	}
 
 	dev_info(&pdev->dev, "%s device registered (reg_base=0x%p, irq=%d)\n",
 		 DRV_NAME, priv->reg_base, dev->irq);
 	return 0;
 
- exit_unmap:
+exit_free:
+	free_sja1000dev(dev);
+exit_unmap:
 	if (mem[idx])
 		iounmap(base);
- exit_release:
+exit_release:
 	if (mem[idx])
 		release_mem_region(mem[idx], iosize);
 	else
 		release_region(port[idx], iosize);
- exit:
+exit:
 	return err;
 }
 
Signature · 1 line
2.35.1
author maintainer
#5 lore raw

PATCH 4/8 can: cc770: cc770_isa_probe(): add missing free_cc770dev()

In reply to Marc Kleine-Budde

From: Zhang Changzhong <[email protected]>

Add the missing free_cc770dev() before return from cc770_isa_probe() in the register_cc770dev() error handling case.

In addition, remove blanks before goto labels.

Fixes 7e02e5433e00 ("can: cc770: legacy CC770 ISA bus driver")
---
 drivers/net/can/cc770/cc770_isa.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/can/cc770/cc770_isa.c +6 -4
index 194c86e0f340..8f6dccd5a587 100644
@@ -264,22 +264,24 @@ static int cc770_isa_probe(struct platform_device *pdev)
 	if (err) {
 		dev_err(&pdev->dev,
 			"couldn't register device (err=%d)\n", err);
-		goto exit_unmap;
+		goto exit_free;
 	}
 
 	dev_info(&pdev->dev, "device registered (reg_base=0x%p, irq=%d)\n",
 		 priv->reg_base, dev->irq);
 	return 0;
 
- exit_unmap:
+exit_free:
+	free_cc770dev(dev);
+exit_unmap:
 	if (mem[idx])
 		iounmap(base);
- exit_release:
+exit_release:
 	if (mem[idx])
 		release_mem_region(mem[idx], iosize);
 	else
 		release_region(port[idx], iosize);
- exit:
+exit:
 	return err;
 }
 
Signature · 1 line
2.35.1
author maintainer
#6 lore raw

PATCH 5/8 can: etas_es58x: es58x_init_netdev(): free netdev when register_candev()

In reply to Marc Kleine-Budde

From: Zhang Changzhong <[email protected]>

In case of register_candev() fails, clear es58x_dev->netdev[channel_idx] and add free_candev(). Otherwise es58x_free_netdevs() will unregister the netdev that has never been registered.

Fixes 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
---
 drivers/net/can/usb/etas_es58x/es58x_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/can/usb/etas_es58x/es58x_core.c +4 -1
index 25f863b4f5f0..ddb7c5735c9a 100644
@@ -2091,8 +2091,11 @@ static int es58x_init_netdev(struct es58x_device *es58x_dev, int channel_idx)
 	netdev->dev_port = channel_idx;
 
 	ret = register_candev(netdev);
-	if (ret)
+	if (ret) {
+		es58x_dev->netdev[channel_idx] = NULL;
+		free_candev(netdev);
 		return ret;
+	}
 
 	netdev_queue_set_dql_min_limit(netdev_get_tx_queue(netdev, 0),
 				       es58x_dev->param->dql_min_limit);
Signature · 1 line
2.35.1
author maintainer
#7 lore raw

PATCH 6/8 can: m_can: pci: add missing m_can_class_free_dev() in probe/remove methods

In reply to Marc Kleine-Budde

From: Zhang Changzhong <[email protected]>

In m_can_pci_remove() and error handling path of m_can_pci_probe(), m_can_class_free_dev() should be called to free resource allocated by m_can_class_allocate_dev(), otherwise there will be memleak.

Fixes cab7ffc0324f ("can: m_can: add PCI glue driver for Intel Elkhart Lake")
---
 drivers/net/can/m_can/m_can_pci.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/can/m_can/m_can_pci.c +6 -3
index 8f184a852a0a..f2219aa2824b 100644
@@ -120,7 +120,7 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 
 	ret = pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_ALL_TYPES);
 	if (ret < 0)
-		return ret;
+		goto err_free_dev;
 
 	mcan_class->dev = &pci->dev;
 	mcan_class->net->irq = pci_irq_vector(pci, 0);
@@ -132,7 +132,7 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 
 	ret = m_can_class_register(mcan_class);
 	if (ret)
-		goto err;
+		goto err_free_irq;
 
 	/* Enable interrupt control at CAN wrapper IP */
 	writel(0x1, base + CTL_CSR_INT_CTL_OFFSET);
@@ -144,8 +144,10 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 
 	return 0;
 
-err:
+err_free_irq:
 	pci_free_irq_vectors(pci);
+err_free_dev:
+	m_can_class_free_dev(mcan_class->net);
 	return ret;
 }
 
@@ -161,6 +163,7 @@ static void m_can_pci_remove(struct pci_dev *pci)
 	writel(0x0, priv->base + CTL_CSR_INT_CTL_OFFSET);
 
 	m_can_class_unregister(mcan_class);
+	m_can_class_free_dev(mcan_class->net);
 	pci_free_irq_vectors(pci);
 }
 
Signature · 1 line
2.35.1
author maintainer
#8 lore raw

PATCH 7/8 can: m_can: Add check for devm_clk_get

In reply to Marc Kleine-Budde

From: Jiasheng Jiang <[email protected]>

Since the devm_clk_get may return error,
it should be better to add check for the cdev->hclk, as same as cdev->cclk.

Fixes f524f829b75a ("can: m_can: Create a m_can platform framework")
---
 drivers/net/can/m_can/m_can.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/m_can/m_can.c +1 -1
index 00d11e95fd98..e5575d2755e4 100644
@@ -1909,7 +1909,7 @@ int m_can_class_get_clocks(struct m_can_classdev *cdev)
 	cdev->hclk = devm_clk_get(cdev->dev, "hclk");
 	cdev->cclk = devm_clk_get(cdev->dev, "cclk");
 
-	if (IS_ERR(cdev->cclk)) {
+	if (IS_ERR(cdev->hclk) || IS_ERR(cdev->cclk)) {
 		dev_err(cdev->dev, "no clock found\n");
 		ret = -ENODEV;
 	}
Signature · 1 line
2.35.1
author maintainer
#9 lore raw

PATCH 8/8 can: mcba_usb: Fix termination command argument

In reply to Marc Kleine-Budde

From: Yasushi SHOJI <[email protected]>

Microchip USB Analyzer can activate the internal termination resistors by setting the "termination" option ON, or OFF to to deactivate them. As I've observed, both with my oscilloscope and captured USB packets below, you must send "0" to turn it ON, and "1" to turn it OFF.

From the schematics in the user's guide, I can confirm that you must drive the CAN_RES signal LOW "0" to activate the resistors.

Reverse the argument value of usb_msg.termination to fix this.

These are the two commands sequence, ON then OFF.

Quoted 7 lines
No.     Time           Source                Destination           Protocol Length Info
      1 0.000000       host                  1.3.1                 USB      46     URB_BULK out

Frame 1: 46 bytes on wire (368 bits), 46 bytes captured (368 bits) USB URB
Leftover Capture Data: a80000000000000000000000000000000000a8

Quoted 6 lines
No.     Time           Source                Destination           Protocol Length Info
      2 4.372547       host                  1.3.1                 USB      46     URB_BULK out

Frame 2: 46 bytes on wire (368 bits), 46 bytes captured (368 bits) USB URB
Leftover Capture Data: a80100000000000000000000000000000000a9

---
 drivers/net/can/usb/mcba_usb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/can/usb/mcba_usb.c +7 -3
index 218b098b261d..47619e9cb005 100644
@@ -47,6 +47,10 @@
 #define MCBA_VER_REQ_USB 1
 #define MCBA_VER_REQ_CAN 2
 
+/* Drive the CAN_RES signal LOW "0" to activate R24 and R25 */
+#define MCBA_VER_TERMINATION_ON 0
+#define MCBA_VER_TERMINATION_OFF 1
+
 #define MCBA_SIDL_EXID_MASK 0x8
 #define MCBA_DLC_MASK 0xf
 #define MCBA_DLC_RTR_MASK 0x40
@@ -463,7 +467,7 @@ static void mcba_usb_process_ka_usb(struct mcba_priv *priv,
 		priv->usb_ka_first_pass = false;
 	}
 
-	if (msg->termination_state)
+	if (msg->termination_state == MCBA_VER_TERMINATION_ON)
 		priv->can.termination = MCBA_TERMINATION_ENABLED;
 	else
 		priv->can.termination = MCBA_TERMINATION_DISABLED;
@@ -785,9 +789,9 @@ static int mcba_set_termination(struct net_device *netdev, u16 term)
 	};
 
 	if (term == MCBA_TERMINATION_ENABLED)
-		usb_msg.termination = 1;
+		usb_msg.termination = MCBA_VER_TERMINATION_ON;
 	else
-		usb_msg.termination = 0;
+		usb_msg.termination = MCBA_VER_TERMINATION_OFF;
 
 	mcba_usb_xmit_cmd(priv, (struct mcba_usb_msg *)&usb_msg);
 
Signature · 1 line
2.35.1