All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 0/9] pull-request: can 2021-12-07
@ 2021-12-07 10:24 Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free Marc Kleine-Budde
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel

Hello Jakub, hello David,

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

The 1st patch is by Vincent Mailhol and fixes a use after free in the
pch_can driver.

Dan Carpenter fixes a use after free in the ems_pcmcia sja1000 driver.

The remaining 7 patches target the m_can driver. Brian Silverman
contributes a patch to disable and ignore the ELO interrupt, which is
currently not handled in the driver and may lead to an interrupt
storm. Vincent Mailhol's patch fixes a memory leak in the error path
of the m_can_read_fifo() function. The remaining patches are
contributed by Matthias Schiffer, first a iomap_read_fifo() and
iomap_write_fifo() functions are fixed in the PCI glue driver, then
the clock rate for the Intel Ekhart Lake platform is fixed, the last 3
patches add support for the custom bit timings on the Elkhart Lake
platform.

regards,
Marc

---

The following changes since commit 4dbb0dad8e63fcd0b5a117c2861d2abe7ff5f186:

  devlink: fix netns refcount leak in devlink_nl_cmd_reload() (2021-12-06 16:56:32 -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.16-20211207

for you to fetch changes up to ea4c1787685dbf9842046f05b6390b6901ee6ba2:

  can: m_can: pci: use custom bit timings for Elkhart Lake (2021-12-07 09:51:41 +0100)

----------------------------------------------------------------
linux-can-fixes-for-5.16-20211207

----------------------------------------------------------------
Brian Silverman (1):
      can: m_can: Disable and ignore ELO interrupt

Dan Carpenter (1):
      can: sja1000: fix use after free in ems_pcmcia_add_card()

Matthias Schiffer (5):
      can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo()
      can: m_can: pci: fix incorrect reference clock rate
      Revert "can: m_can: remove support for custom bit timing"
      can: m_can: make custom bittiming fields const
      can: m_can: pci: use custom bit timings for Elkhart Lake

Vincent Mailhol (2):
      can: pch_can: pch_can_rx_normal: fix use after free
      can: m_can: m_can_read_fifo: fix memory leak in error branch

 drivers/net/can/m_can/m_can.c        | 42 +++++++++++++++---------
 drivers/net/can/m_can/m_can.h        |  3 ++
 drivers/net/can/m_can/m_can_pci.c    | 62 ++++++++++++++++++++++++++++++++----
 drivers/net/can/pch_can.c            |  2 +-
 drivers/net/can/sja1000/ems_pcmcia.c |  7 +++-
 5 files changed, 93 insertions(+), 23 deletions(-)



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free
  2021-12-07 10:24 [PATCH net 0/9] pull-request: can 2021-12-07 Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 18:40   ` patchwork-bot+netdevbpf
  2021-12-07 10:24 ` [PATCH net 2/9] can: sja1000: fix use after free in ems_pcmcia_add_card() Marc Kleine-Budde
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 11+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Vincent Mailhol, stable,
	Marc Kleine-Budde

From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

After calling netif_receive_skb(skb), dereferencing skb is unsafe.
Especially, the can_frame cf which aliases skb memory is dereferenced
just after the call netif_receive_skb(skb).

Reordering the lines solves the issue.

Fixes: b21d18b51b31 ("can: Topcliff: Add PCH_CAN driver.")
Link: https://lore.kernel.org/all/20211123111654.621610-1-mailhol.vincent@wanadoo.fr
Cc: stable@vger.kernel.org
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/pch_can.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/pch_can.c b/drivers/net/can/pch_can.c
index 92a54a5fd4c5..964c8a09226a 100644
--- a/drivers/net/can/pch_can.c
+++ b/drivers/net/can/pch_can.c
@@ -692,11 +692,11 @@ static int pch_can_rx_normal(struct net_device *ndev, u32 obj_num, int quota)
 			cf->data[i + 1] = data_reg >> 8;
 		}
 
-		netif_receive_skb(skb);
 		rcv_pkts++;
 		stats->rx_packets++;
 		quota--;
 		stats->rx_bytes += cf->len;
+		netif_receive_skb(skb);
 
 		pch_fifo_thresh(priv, obj_num);
 		obj_num++;

base-commit: 4dbb0dad8e63fcd0b5a117c2861d2abe7ff5f186
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net 2/9] can: sja1000: fix use after free in ems_pcmcia_add_card()
  2021-12-07 10:24 [PATCH net 0/9] pull-request: can 2021-12-07 Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 3/9] can: m_can: Disable and ignore ELO interrupt Marc Kleine-Budde
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Dan Carpenter, stable,
	Oliver Hartkopp, Marc Kleine-Budde

From: Dan Carpenter <dan.carpenter@oracle.com>

If the last channel is not available then "dev" is freed.  Fortunately,
we can just use "pdev->irq" instead.

Also we should check if at least one channel was set up.

Fixes: fd734c6f25ae ("can/sja1000: add driver for EMS PCMCIA card")
Link: https://lore.kernel.org/all/20211124145041.GB13656@kili
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/sja1000/ems_pcmcia.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/sja1000/ems_pcmcia.c b/drivers/net/can/sja1000/ems_pcmcia.c
index e21b169c14c0..4642b6d4aaf7 100644
--- a/drivers/net/can/sja1000/ems_pcmcia.c
+++ b/drivers/net/can/sja1000/ems_pcmcia.c
@@ -234,7 +234,12 @@ static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base)
 			free_sja1000dev(dev);
 	}
 
-	err = request_irq(dev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,
+	if (!card->channels) {
+		err = -ENODEV;
+		goto failure_cleanup;
+	}
+
+	err = request_irq(pdev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,
 			  DRV_NAME, card);
 	if (!err)
 		return 0;
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net 3/9] can: m_can: Disable and ignore ELO interrupt
  2021-12-07 10:24 [PATCH net 0/9] pull-request: can 2021-12-07 Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 2/9] can: sja1000: fix use after free in ems_pcmcia_add_card() Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 4/9] can: m_can: m_can_read_fifo: fix memory leak in error branch Marc Kleine-Budde
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Brian Silverman, stable,
	Marc Kleine-Budde

From: Brian Silverman <brian.silverman@bluerivertech.com>

With the design of this driver, this condition is often triggered.
However, the counter that this interrupt indicates an overflow is never
read either, so overflowing is harmless.

On my system, when a CAN bus starts flapping up and down, this locks up
the whole system with lots of interrupts and printks.

Specifically, this interrupt indicates the CEL field of ECR has
overflowed. All reads of ECR mask out CEL.

Fixes: e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")
Link: https://lore.kernel.org/all/20211129222628.7490-1-brian.silverman@bluerivertech.com
Cc: stable@vger.kernel.org
Signed-off-by: Brian Silverman <brian.silverman@bluerivertech.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 2470c47b2e31..91be87c4f4d3 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -204,16 +204,16 @@ enum m_can_reg {
 
 /* Interrupts for version 3.0.x */
 #define IR_ERR_LEC_30X	(IR_STE	| IR_FOE | IR_ACKE | IR_BE | IR_CRCE)
-#define IR_ERR_BUS_30X	(IR_ERR_LEC_30X | IR_WDI | IR_ELO | IR_BEU | \
-			 IR_BEC | IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | \
-			 IR_RF1L | IR_RF0L)
+#define IR_ERR_BUS_30X	(IR_ERR_LEC_30X | IR_WDI | IR_BEU | IR_BEC | \
+			 IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | IR_RF1L | \
+			 IR_RF0L)
 #define IR_ERR_ALL_30X	(IR_ERR_STATE | IR_ERR_BUS_30X)
 
 /* Interrupts for version >= 3.1.x */
 #define IR_ERR_LEC_31X	(IR_PED | IR_PEA)
-#define IR_ERR_BUS_31X      (IR_ERR_LEC_31X | IR_WDI | IR_ELO | IR_BEU | \
-			 IR_BEC | IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | \
-			 IR_RF1L | IR_RF0L)
+#define IR_ERR_BUS_31X      (IR_ERR_LEC_31X | IR_WDI | IR_BEU | IR_BEC | \
+			 IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | IR_RF1L | \
+			 IR_RF0L)
 #define IR_ERR_ALL_31X	(IR_ERR_STATE | IR_ERR_BUS_31X)
 
 /* Interrupt Line Select (ILS) */
@@ -810,8 +810,6 @@ static void m_can_handle_other_err(struct net_device *dev, u32 irqstatus)
 {
 	if (irqstatus & IR_WDI)
 		netdev_err(dev, "Message RAM Watchdog event due to missing READY\n");
-	if (irqstatus & IR_ELO)
-		netdev_err(dev, "Error Logging Overflow\n");
 	if (irqstatus & IR_BEU)
 		netdev_err(dev, "Bit Error Uncorrected\n");
 	if (irqstatus & IR_BEC)
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net 4/9] can: m_can: m_can_read_fifo: fix memory leak in error branch
  2021-12-07 10:24 [PATCH net 0/9] pull-request: can 2021-12-07 Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2021-12-07 10:24 ` [PATCH net 3/9] can: m_can: Disable and ignore ELO interrupt Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 5/9] can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo() Marc Kleine-Budde
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Vincent Mailhol, stable,
	Matt Kline, Marc Kleine-Budde

From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

In m_can_read_fifo(), if the second call to m_can_fifo_read() fails,
the function jump to the out_fail label and returns without calling
m_can_receive_skb(). This means that the skb previously allocated by
alloc_can_skb() is not freed. In other terms, this is a memory leak.

This patch adds a goto label to destroy the skb if an error occurs.

Issue was found with GCC -fanalyzer, please follow the link below for
details.

Fixes: e39381770ec9 ("can: m_can: Disable IRQs on FIFO bus errors")
Link: https://lore.kernel.org/all/20211107050755.70655-1-mailhol.vincent@wanadoo.fr
Cc: stable@vger.kernel.org
Cc: Matt Kline <matt@bitbashing.io>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 91be87c4f4d3..e330b4c121bf 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -517,7 +517,7 @@ static int m_can_read_fifo(struct net_device *dev, u32 rxfs)
 		err = m_can_fifo_read(cdev, fgi, M_CAN_FIFO_DATA,
 				      cf->data, DIV_ROUND_UP(cf->len, 4));
 		if (err)
-			goto out_fail;
+			goto out_free_skb;
 	}
 
 	/* acknowledge rx fifo 0 */
@@ -532,6 +532,8 @@ static int m_can_read_fifo(struct net_device *dev, u32 rxfs)
 
 	return 0;
 
+out_free_skb:
+	kfree_skb(skb);
 out_fail:
 	netdev_err(dev, "FIFO read returned %d\n", err);
 	return err;
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net 5/9] can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo()
  2021-12-07 10:24 [PATCH net 0/9] pull-request: can 2021-12-07 Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2021-12-07 10:24 ` [PATCH net 4/9] can: m_can: m_can_read_fifo: fix memory leak in error branch Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 6/9] can: m_can: pci: fix incorrect reference clock rate Marc Kleine-Budde
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Matthias Schiffer, stable,
	Matt Kline, Jarkko Nikula, Marc Kleine-Budde

From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>

The same fix that was previously done in m_can_platform in commit
99d173fbe894 ("can: m_can: fix iomap_read_fifo() and iomap_write_fifo()")
is required in m_can_pci as well to make iomap_read_fifo() and
iomap_write_fifo() work for val_count > 1.

Fixes: 812270e5445b ("can: m_can: Batch FIFO writes during CAN transmit")
Fixes: 1aa6772f64b4 ("can: m_can: Batch FIFO reads during CAN receive")
Link: https://lore.kernel.org/all/20211118144011.10921-1-matthias.schiffer@ew.tq-group.com
Cc: stable@vger.kernel.org
Cc: Matt Kline <matt@bitbashing.io>
Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can_pci.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/m_can/m_can_pci.c b/drivers/net/can/m_can/m_can_pci.c
index 89cc3d41e952..d72c294ac4d3 100644
--- a/drivers/net/can/m_can/m_can_pci.c
+++ b/drivers/net/can/m_can/m_can_pci.c
@@ -42,8 +42,13 @@ static u32 iomap_read_reg(struct m_can_classdev *cdev, int reg)
 static int iomap_read_fifo(struct m_can_classdev *cdev, int offset, void *val, size_t val_count)
 {
 	struct m_can_pci_priv *priv = cdev_to_priv(cdev);
+	void __iomem *src = priv->base + offset;
 
-	ioread32_rep(priv->base + offset, val, val_count);
+	while (val_count--) {
+		*(unsigned int *)val = ioread32(src);
+		val += 4;
+		src += 4;
+	}
 
 	return 0;
 }
@@ -61,8 +66,13 @@ static int iomap_write_fifo(struct m_can_classdev *cdev, int offset,
 			    const void *val, size_t val_count)
 {
 	struct m_can_pci_priv *priv = cdev_to_priv(cdev);
+	void __iomem *dst = priv->base + offset;
 
-	iowrite32_rep(priv->base + offset, val, val_count);
+	while (val_count--) {
+		iowrite32(*(unsigned int *)val, dst);
+		val += 4;
+		dst += 4;
+	}
 
 	return 0;
 }
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net 6/9] can: m_can: pci: fix incorrect reference clock rate
  2021-12-07 10:24 [PATCH net 0/9] pull-request: can 2021-12-07 Marc Kleine-Budde
                   ` (4 preceding siblings ...)
  2021-12-07 10:24 ` [PATCH net 5/9] can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo() Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 7/9] Revert "can: m_can: remove support for custom bit timing" Marc Kleine-Budde
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Matthias Schiffer, stable,
	Jarkko Nikula, Marc Kleine-Budde

From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>

When testing the CAN controller on our Ekhart Lake hardware, we
determined that all communication was running with twice the configured
bitrate. Changing the reference clock rate from 100MHz to 200MHz fixed
this. Intel's support has confirmed to us that 200MHz is indeed the
correct clock rate.

Fixes: cab7ffc0324f ("can: m_can: add PCI glue driver for Intel Elkhart Lake")
Link: https://lore.kernel.org/all/c9cf3995f45c363e432b3ae8eb1275e54f009fc8.1636967198.git.matthias.schiffer@ew.tq-group.com
Cc: stable@vger.kernel.org
Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/m_can_pci.c b/drivers/net/can/m_can/m_can_pci.c
index d72c294ac4d3..8f184a852a0a 100644
--- a/drivers/net/can/m_can/m_can_pci.c
+++ b/drivers/net/can/m_can/m_can_pci.c
@@ -18,7 +18,7 @@
 
 #define M_CAN_PCI_MMIO_BAR		0
 
-#define M_CAN_CLOCK_FREQ_EHL		100000000
+#define M_CAN_CLOCK_FREQ_EHL		200000000
 #define CTL_CSR_INT_CTL_OFFSET		0x508
 
 struct m_can_pci_priv {
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net 7/9] Revert "can: m_can: remove support for custom bit timing"
  2021-12-07 10:24 [PATCH net 0/9] pull-request: can 2021-12-07 Marc Kleine-Budde
                   ` (5 preceding siblings ...)
  2021-12-07 10:24 ` [PATCH net 6/9] can: m_can: pci: fix incorrect reference clock rate Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 8/9] can: m_can: make custom bittiming fields const Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 9/9] can: m_can: pci: use custom bit timings for Elkhart Lake Marc Kleine-Budde
  8 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Matthias Schiffer, Marc Kleine-Budde

From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>

The timing limits specified by the Elkhart Lake CPU datasheets do not
match the defaults. Let's reintroduce the support for custom bit timings.

This reverts commit 0ddd83fbebbc5537f9d180d31f659db3564be708.

Link: https://lore.kernel.org/all/00c9e2596b1a548906921a574d4ef7a03c0dace0.1636967198.git.matthias.schiffer@ew.tq-group.com
Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can.c | 24 ++++++++++++++++++------
 drivers/net/can/m_can/m_can.h |  3 +++
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index e330b4c121bf..c2a8421e7845 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1494,20 +1494,32 @@ static int m_can_dev_setup(struct m_can_classdev *cdev)
 	case 30:
 		/* CAN_CTRLMODE_FD_NON_ISO is fixed with M_CAN IP v3.0.x */
 		can_set_static_ctrlmode(dev, CAN_CTRLMODE_FD_NON_ISO);
-		cdev->can.bittiming_const = &m_can_bittiming_const_30X;
-		cdev->can.data_bittiming_const = &m_can_data_bittiming_const_30X;
+		cdev->can.bittiming_const = cdev->bit_timing ?
+			cdev->bit_timing : &m_can_bittiming_const_30X;
+
+		cdev->can.data_bittiming_const = cdev->data_timing ?
+			cdev->data_timing :
+			&m_can_data_bittiming_const_30X;
 		break;
 	case 31:
 		/* CAN_CTRLMODE_FD_NON_ISO is fixed with M_CAN IP v3.1.x */
 		can_set_static_ctrlmode(dev, CAN_CTRLMODE_FD_NON_ISO);
-		cdev->can.bittiming_const = &m_can_bittiming_const_31X;
-		cdev->can.data_bittiming_const = &m_can_data_bittiming_const_31X;
+		cdev->can.bittiming_const = cdev->bit_timing ?
+			cdev->bit_timing : &m_can_bittiming_const_31X;
+
+		cdev->can.data_bittiming_const = cdev->data_timing ?
+			cdev->data_timing :
+			&m_can_data_bittiming_const_31X;
 		break;
 	case 32:
 	case 33:
 		/* Support both MCAN version v3.2.x and v3.3.0 */
-		cdev->can.bittiming_const = &m_can_bittiming_const_31X;
-		cdev->can.data_bittiming_const = &m_can_data_bittiming_const_31X;
+		cdev->can.bittiming_const = cdev->bit_timing ?
+			cdev->bit_timing : &m_can_bittiming_const_31X;
+
+		cdev->can.data_bittiming_const = cdev->data_timing ?
+			cdev->data_timing :
+			&m_can_data_bittiming_const_31X;
 
 		cdev->can.ctrlmode_supported |=
 			(m_can_niso_supported(cdev) ?
diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h
index d18b515e6ccc..ad063b101411 100644
--- a/drivers/net/can/m_can/m_can.h
+++ b/drivers/net/can/m_can/m_can.h
@@ -85,6 +85,9 @@ struct m_can_classdev {
 	struct sk_buff *tx_skb;
 	struct phy *transceiver;
 
+	struct can_bittiming_const *bit_timing;
+	struct can_bittiming_const *data_timing;
+
 	struct m_can_ops *ops;
 
 	int version;
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net 8/9] can: m_can: make custom bittiming fields const
  2021-12-07 10:24 [PATCH net 0/9] pull-request: can 2021-12-07 Marc Kleine-Budde
                   ` (6 preceding siblings ...)
  2021-12-07 10:24 ` [PATCH net 7/9] Revert "can: m_can: remove support for custom bit timing" Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 9/9] can: m_can: pci: use custom bit timings for Elkhart Lake Marc Kleine-Budde
  8 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Matthias Schiffer, Marc Kleine-Budde

From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>

The assigned timing structs will be defined a const anyway, so we can
avoid a few casts by declaring the struct fields as const as well.

Link: https://lore.kernel.org/all/4508fa4e639164b2584c49a065d90c78a91fa568.1636967198.git.matthias.schiffer@ew.tq-group.com
Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h
index ad063b101411..2c5d40997168 100644
--- a/drivers/net/can/m_can/m_can.h
+++ b/drivers/net/can/m_can/m_can.h
@@ -85,8 +85,8 @@ struct m_can_classdev {
 	struct sk_buff *tx_skb;
 	struct phy *transceiver;
 
-	struct can_bittiming_const *bit_timing;
-	struct can_bittiming_const *data_timing;
+	const struct can_bittiming_const *bit_timing;
+	const struct can_bittiming_const *data_timing;
 
 	struct m_can_ops *ops;
 
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net 9/9] can: m_can: pci: use custom bit timings for Elkhart Lake
  2021-12-07 10:24 [PATCH net 0/9] pull-request: can 2021-12-07 Marc Kleine-Budde
                   ` (7 preceding siblings ...)
  2021-12-07 10:24 ` [PATCH net 8/9] can: m_can: make custom bittiming fields const Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  8 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Matthias Schiffer, Marc Kleine-Budde

From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>

The relevant datasheet [1] specifies nonstandard limits for the bit timing
parameters. While it is unclear what the exact effect of violating these
limits is, it seems like a good idea to adhere to the documentation.

[1] Intel Atom® x6000E Series, and Intel® Pentium® and Celeron® N and J
    Series Processors for IoT Applications Datasheet,
    Volume 2 (Book 3 of 3), July 2021, Revision 001

Fixes: cab7ffc0324f ("can: m_can: add PCI glue driver for Intel Elkhart Lake")
Link: https://lore.kernel.org/all/9eba5d7c05a48ead4024ffa6e5926f191d8c6b38.1636967198.git.matthias.schiffer@ew.tq-group.com
Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can_pci.c | 48 ++++++++++++++++++++++++++++---
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/m_can/m_can_pci.c b/drivers/net/can/m_can/m_can_pci.c
index 8f184a852a0a..b56a54d6c5a9 100644
--- a/drivers/net/can/m_can/m_can_pci.c
+++ b/drivers/net/can/m_can/m_can_pci.c
@@ -18,9 +18,14 @@
 
 #define M_CAN_PCI_MMIO_BAR		0
 
-#define M_CAN_CLOCK_FREQ_EHL		200000000
 #define CTL_CSR_INT_CTL_OFFSET		0x508
 
+struct m_can_pci_config {
+	const struct can_bittiming_const *bit_timing;
+	const struct can_bittiming_const *data_timing;
+	unsigned int clock_freq;
+};
+
 struct m_can_pci_priv {
 	struct m_can_classdev cdev;
 
@@ -84,9 +89,40 @@ static struct m_can_ops m_can_pci_ops = {
 	.read_fifo = iomap_read_fifo,
 };
 
+static const struct can_bittiming_const m_can_bittiming_const_ehl = {
+	.name = KBUILD_MODNAME,
+	.tseg1_min = 2,		/* Time segment 1 = prop_seg + phase_seg1 */
+	.tseg1_max = 64,
+	.tseg2_min = 1,		/* Time segment 2 = phase_seg2 */
+	.tseg2_max = 128,
+	.sjw_max = 128,
+	.brp_min = 1,
+	.brp_max = 512,
+	.brp_inc = 1,
+};
+
+static const struct can_bittiming_const m_can_data_bittiming_const_ehl = {
+	.name = KBUILD_MODNAME,
+	.tseg1_min = 2,		/* Time segment 1 = prop_seg + phase_seg1 */
+	.tseg1_max = 16,
+	.tseg2_min = 1,		/* Time segment 2 = phase_seg2 */
+	.tseg2_max = 8,
+	.sjw_max = 4,
+	.brp_min = 1,
+	.brp_max = 32,
+	.brp_inc = 1,
+};
+
+static const struct m_can_pci_config m_can_pci_ehl = {
+	.bit_timing = &m_can_bittiming_const_ehl,
+	.data_timing = &m_can_data_bittiming_const_ehl,
+	.clock_freq = 200000000,
+};
+
 static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 {
 	struct device *dev = &pci->dev;
+	const struct m_can_pci_config *cfg;
 	struct m_can_classdev *mcan_class;
 	struct m_can_pci_priv *priv;
 	void __iomem *base;
@@ -114,6 +150,8 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 	if (!mcan_class)
 		return -ENOMEM;
 
+	cfg = (const struct m_can_pci_config *)id->driver_data;
+
 	priv = cdev_to_priv(mcan_class);
 
 	priv->base = base;
@@ -125,7 +163,9 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
 	mcan_class->dev = &pci->dev;
 	mcan_class->net->irq = pci_irq_vector(pci, 0);
 	mcan_class->pm_clock_support = 1;
-	mcan_class->can.clock.freq = id->driver_data;
+	mcan_class->bit_timing = cfg->bit_timing;
+	mcan_class->data_timing = cfg->data_timing;
+	mcan_class->can.clock.freq = cfg->clock_freq;
 	mcan_class->ops = &m_can_pci_ops;
 
 	pci_set_drvdata(pci, mcan_class);
@@ -178,8 +218,8 @@ static SIMPLE_DEV_PM_OPS(m_can_pci_pm_ops,
 			 m_can_pci_suspend, m_can_pci_resume);
 
 static const struct pci_device_id m_can_pci_id_table[] = {
-	{ PCI_VDEVICE(INTEL, 0x4bc1), M_CAN_CLOCK_FREQ_EHL, },
-	{ PCI_VDEVICE(INTEL, 0x4bc2), M_CAN_CLOCK_FREQ_EHL, },
+	{ PCI_VDEVICE(INTEL, 0x4bc1), (kernel_ulong_t)&m_can_pci_ehl, },
+	{ PCI_VDEVICE(INTEL, 0x4bc2), (kernel_ulong_t)&m_can_pci_ehl, },
 	{  }	/* Terminating Entry */
 };
 MODULE_DEVICE_TABLE(pci, m_can_pci_id_table);
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free
  2021-12-07 10:24 ` [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free Marc Kleine-Budde
@ 2021-12-07 18:40   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-07 18:40 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: netdev, davem, kuba, linux-can, kernel, mailhol.vincent, stable

Hello:

This series was applied to netdev/net.git (master)
by Marc Kleine-Budde <mkl@pengutronix.de>:

On Tue,  7 Dec 2021 11:24:12 +0100 you wrote:
> From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
> 
> After calling netif_receive_skb(skb), dereferencing skb is unsafe.
> Especially, the can_frame cf which aliases skb memory is dereferenced
> just after the call netif_receive_skb(skb).
> 
> Reordering the lines solves the issue.
> 
> [...]

Here is the summary with links:
  - [net,1/9] can: pch_can: pch_can_rx_normal: fix use after free
    https://git.kernel.org/netdev/net/c/94cddf1e9227
  - [net,2/9] can: sja1000: fix use after free in ems_pcmcia_add_card()
    https://git.kernel.org/netdev/net/c/3ec6ca6b1a8e
  - [net,3/9] can: m_can: Disable and ignore ELO interrupt
    https://git.kernel.org/netdev/net/c/f58ac1adc76b
  - [net,4/9] can: m_can: m_can_read_fifo: fix memory leak in error branch
    https://git.kernel.org/netdev/net/c/31cb32a590d6
  - [net,5/9] can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo()
    https://git.kernel.org/netdev/net/c/d737de2d7cc3
  - [net,6/9] can: m_can: pci: fix incorrect reference clock rate
    https://git.kernel.org/netdev/net/c/8c03b8bff765
  - [net,7/9] Revert "can: m_can: remove support for custom bit timing"
    https://git.kernel.org/netdev/net/c/ea768b2ffec6
  - [net,8/9] can: m_can: make custom bittiming fields const
    https://git.kernel.org/netdev/net/c/ea22ba40debe
  - [net,9/9] can: m_can: pci: use custom bit timings for Elkhart Lake
    https://git.kernel.org/netdev/net/c/ea4c1787685d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-12-07 18:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-07 10:24 [PATCH net 0/9] pull-request: can 2021-12-07 Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free Marc Kleine-Budde
2021-12-07 18:40   ` patchwork-bot+netdevbpf
2021-12-07 10:24 ` [PATCH net 2/9] can: sja1000: fix use after free in ems_pcmcia_add_card() Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 3/9] can: m_can: Disable and ignore ELO interrupt Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 4/9] can: m_can: m_can_read_fifo: fix memory leak in error branch Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 5/9] can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo() Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 6/9] can: m_can: pci: fix incorrect reference clock rate Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 7/9] Revert "can: m_can: remove support for custom bit timing" Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 8/9] can: m_can: make custom bittiming fields const Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 9/9] can: m_can: pci: use custom bit timings for Elkhart Lake Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.