linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* pull-request: can 2020-11-30
@ 2020-11-30 12:53 Marc Kleine-Budde
  2020-11-30 12:53 ` [net 1/5] can: m_can: tcan4x5x_can_probe(): fix error path: remove erroneous clk_disable_unprepare() Marc Kleine-Budde
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2020-11-30 12:53 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel

Hello Jakub, hello David,

here's a pull request of 5 patches for net/master.

The first patch is by me an target the tcan4x5x bindings for the m_can driver.
It fixes the error path in the tcan4x5x_can_probe() function.

The next two patches are by Jeroen Hofstee and makes the lost of arbitration
error counters of sja1000 and the sun4i drivers consistent with the other
drivers.

Zhang Qilong contributes two patch that clean up the error path in the c_can
and kvaser_pciefd drivers.

regards,
Marc

---

The following changes since commit 4d521943f76bd0d1e68ea5e02df7aadd30b2838a:

  dt-bindings: net: correct interrupt flags in examples (2020-11-28 14:47:56 -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-20201130

for you to fetch changes up to 13a84cf37a4cf1155a41684236c2314eb40cd65c:

  can: kvaser_pciefd: kvaser_pciefd_open(): fix error handling (2020-11-30 12:43:55 +0100)

----------------------------------------------------------------
linux-can-fixes-for-5.10-20201130

----------------------------------------------------------------
Jeroen Hofstee (2):
      can: sja1000: sja1000_err(): don't count arbitration lose as an error
      can: sun4i_can: sun4i_can_err(): don't count arbitration lose as an error

Marc Kleine-Budde (1):
      can: m_can: tcan4x5x_can_probe(): fix error path: remove erroneous clk_disable_unprepare()

Zhang Qilong (2):
      can: c_can: c_can_power_up(): fix error handling
      can: kvaser_pciefd: kvaser_pciefd_open(): fix error handling

 drivers/net/can/c_can/c_can.c     | 18 ++++++++++++++----
 drivers/net/can/kvaser_pciefd.c   |  4 +++-
 drivers/net/can/m_can/tcan4x5x.c  | 11 +++--------
 drivers/net/can/sja1000/sja1000.c |  1 -
 drivers/net/can/sun4i_can.c       |  1 -
 5 files changed, 20 insertions(+), 15 deletions(-)



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

* [net 1/5] can: m_can: tcan4x5x_can_probe(): fix error path: remove erroneous clk_disable_unprepare()
  2020-11-30 12:53 pull-request: can 2020-11-30 Marc Kleine-Budde
@ 2020-11-30 12:53 ` Marc Kleine-Budde
  2020-11-30 12:53 ` [net 2/5] can: sja1000: sja1000_err(): don't count arbitration lose as an error Marc Kleine-Budde
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2020-11-30 12:53 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Marc Kleine-Budde

The clocks mcan_class->cclk and mcan_class->hclk are not prepared by any call
during tcan4x5x_can_probe(), so remove erroneous clk_disable_unprepare() on
them.

Fixes: 5443c226ba91 ("can: tcan4x5x: Add tcan4x5x driver to the kernel")
Link: http://lore.kernel.org/r/20201130114252.215334-1-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/tcan4x5x.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x.c
index e5d7d85e0b6d..7347ab39c5b6 100644
--- a/drivers/net/can/m_can/tcan4x5x.c
+++ b/drivers/net/can/m_can/tcan4x5x.c
@@ -489,18 +489,18 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 	spi->bits_per_word = 32;
 	ret = spi_setup(spi);
 	if (ret)
-		goto out_clk;
+		goto out_m_can_class_free_dev;
 
 	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;
+		goto out_m_can_class_free_dev;
 	}
 
 	ret = tcan4x5x_power_enable(priv->power, 1);
 	if (ret)
-		goto out_clk;
+		goto out_m_can_class_free_dev;
 
 	ret = tcan4x5x_parse_config(mcan_class);
 	if (ret)
@@ -519,11 +519,6 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 
 out_power:
 	tcan4x5x_power_enable(priv->power, 0);
-out_clk:
-	if (!IS_ERR(mcan_class->cclk)) {
-		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);

base-commit: 4d521943f76bd0d1e68ea5e02df7aadd30b2838a
-- 
2.29.2



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

* [net 2/5] can: sja1000: sja1000_err(): don't count arbitration lose as an error
  2020-11-30 12:53 pull-request: can 2020-11-30 Marc Kleine-Budde
  2020-11-30 12:53 ` [net 1/5] can: m_can: tcan4x5x_can_probe(): fix error path: remove erroneous clk_disable_unprepare() Marc Kleine-Budde
@ 2020-11-30 12:53 ` Marc Kleine-Budde
  2020-11-30 12:53 ` [net 3/5] can: sun4i_can: sun4i_can_err(): " Marc Kleine-Budde
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2020-11-30 12:53 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Jeroen Hofstee, Marc Kleine-Budde

From: Jeroen Hofstee <jhofstee@victronenergy.com>

Losing arbitration is normal in a CAN-bus network, it means that a higher
priority frame is being send and the pending message will be retried later.
Hence most driver only increment arbitration_lost, but the sja1000 driver also
incremeants tx_error, causing errors to be reported on a normal functioning
CAN-bus. So stop counting them as errors.

Fixes: 8935f57e68c4 ("can: sja1000: fix network statistics update")
Signed-off-by: Jeroen Hofstee <jhofstee@victronenergy.com>
Link: https://lore.kernel.org/r/20201127095941.21609-1-jhofstee@victronenergy.com
[mkl: split into two seperate patches]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/sja1000/sja1000.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index 9f107798f904..25a4d7d0b349 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -474,7 +474,6 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
 		netdev_dbg(dev, "arbitration lost interrupt\n");
 		alc = priv->read_reg(priv, SJA1000_ALC);
 		priv->can.can_stats.arbitration_lost++;
-		stats->tx_errors++;
 		cf->can_id |= CAN_ERR_LOSTARB;
 		cf->data[0] = alc & 0x1f;
 	}
-- 
2.29.2



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

* [net 3/5] can: sun4i_can: sun4i_can_err(): don't count arbitration lose as an error
  2020-11-30 12:53 pull-request: can 2020-11-30 Marc Kleine-Budde
  2020-11-30 12:53 ` [net 1/5] can: m_can: tcan4x5x_can_probe(): fix error path: remove erroneous clk_disable_unprepare() Marc Kleine-Budde
  2020-11-30 12:53 ` [net 2/5] can: sja1000: sja1000_err(): don't count arbitration lose as an error Marc Kleine-Budde
@ 2020-11-30 12:53 ` Marc Kleine-Budde
  2020-11-30 12:53 ` [net 4/5] can: c_can: c_can_power_up(): fix error handling Marc Kleine-Budde
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2020-11-30 12:53 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Jeroen Hofstee, Marc Kleine-Budde

From: Jeroen Hofstee <jhofstee@victronenergy.com>

Losing arbitration is normal in a CAN-bus network, it means that a higher
priority frame is being send and the pending message will be retried later.
Hence most driver only increment arbitration_lost, but the sun4i driver also
incremeants tx_error, causing errors to be reported on a normal functioning
CAN-bus. So stop counting them as errors.

Fixes: 0738eff14d81 ("can: Allwinner A10/A20 CAN Controller support - Kernel module")
Signed-off-by: Jeroen Hofstee <jhofstee@victronenergy.com>
Link: https://lore.kernel.org/r/20201127095941.21609-1-jhofstee@victronenergy.com
[mkl: split into two seperate patches]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/sun4i_can.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c
index e2c6cf4b2228..b3f2f4fe5ee0 100644
--- a/drivers/net/can/sun4i_can.c
+++ b/drivers/net/can/sun4i_can.c
@@ -604,7 +604,6 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)
 		netdev_dbg(dev, "arbitration lost interrupt\n");
 		alc = readl(priv->base + SUN4I_REG_STA_ADDR);
 		priv->can.can_stats.arbitration_lost++;
-		stats->tx_errors++;
 		if (likely(skb)) {
 			cf->can_id |= CAN_ERR_LOSTARB;
 			cf->data[0] = (alc >> 8) & 0x1f;
-- 
2.29.2



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

* [net 4/5] can: c_can: c_can_power_up(): fix error handling
  2020-11-30 12:53 pull-request: can 2020-11-30 Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2020-11-30 12:53 ` [net 3/5] can: sun4i_can: sun4i_can_err(): " Marc Kleine-Budde
@ 2020-11-30 12:53 ` Marc Kleine-Budde
  2020-11-30 12:53 ` [net 5/5] can: kvaser_pciefd: kvaser_pciefd_open(): " Marc Kleine-Budde
  2020-12-01  3:08 ` pull-request: can 2020-11-30 Jakub Kicinski
  5 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2020-11-30 12:53 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Zhang Qilong, Marc Kleine-Budde

From: Zhang Qilong <zhangqilong3@huawei.com>

In the error handling in c_can_power_up(), there are two bugs:

1) c_can_pm_runtime_get_sync() will increase usage counter if device is not
   empty. Forgetting to call c_can_pm_runtime_put_sync() will result in a
   reference leak here.

2) c_can_reset_ram() operation will set start bit when enable is true. We
   should clear it in the error handling.

We fix it by adding c_can_pm_runtime_put_sync() for 1), and
c_can_reset_ram(enable is false) for 2) in the error handling.

Fixes: 8212003260c60 ("can: c_can: Add d_can suspend resume support")
Fixes: 52cde85acc23f ("can: c_can: Add d_can raminit support")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Link: https://lore.kernel.org/r/20201128133922.3276973-2-zhangqilong3@huawei.com
[mkl: return "0" instead of "ret"]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/c_can/c_can.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index 1ccdbe89585b..1a9e9b9a4bf6 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -1295,12 +1295,22 @@ int c_can_power_up(struct net_device *dev)
 				time_after(time_out, jiffies))
 		cpu_relax();
 
-	if (time_after(jiffies, time_out))
-		return -ETIMEDOUT;
+	if (time_after(jiffies, time_out)) {
+		ret = -ETIMEDOUT;
+		goto err_out;
+	}
 
 	ret = c_can_start(dev);
-	if (!ret)
-		c_can_irq_control(priv, true);
+	if (ret)
+		goto err_out;
+
+	c_can_irq_control(priv, true);
+
+	return 0;
+
+err_out:
+	c_can_reset_ram(priv, false);
+	c_can_pm_runtime_put_sync(priv);
 
 	return ret;
 }
-- 
2.29.2



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

* [net 5/5] can: kvaser_pciefd: kvaser_pciefd_open(): fix error handling
  2020-11-30 12:53 pull-request: can 2020-11-30 Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2020-11-30 12:53 ` [net 4/5] can: c_can: c_can_power_up(): fix error handling Marc Kleine-Budde
@ 2020-11-30 12:53 ` Marc Kleine-Budde
  2020-12-01  3:08 ` pull-request: can 2020-11-30 Jakub Kicinski
  5 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2020-11-30 12:53 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Zhang Qilong, Marc Kleine-Budde

From: Zhang Qilong <zhangqilong3@huawei.com>

If kvaser_pciefd_bus_on() failed, we should call close_candev() to avoid
reference leak.

Fixes: 26ad340e582d3 ("can: kvaser_pciefd: Add driver for Kvaser PCIEcan devices")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Link: https://lore.kernel.org/r/20201128133922.3276973-3-zhangqilong3@huawei.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/kvaser_pciefd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/kvaser_pciefd.c b/drivers/net/can/kvaser_pciefd.c
index 72acd1ba162d..43151dd6cb1c 100644
--- a/drivers/net/can/kvaser_pciefd.c
+++ b/drivers/net/can/kvaser_pciefd.c
@@ -692,8 +692,10 @@ static int kvaser_pciefd_open(struct net_device *netdev)
 		return err;
 
 	err = kvaser_pciefd_bus_on(can);
-	if (err)
+	if (err) {
+		close_candev(netdev);
 		return err;
+	}
 
 	return 0;
 }
-- 
2.29.2



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

* Re: pull-request: can 2020-11-30
  2020-11-30 12:53 pull-request: can 2020-11-30 Marc Kleine-Budde
                   ` (4 preceding siblings ...)
  2020-11-30 12:53 ` [net 5/5] can: kvaser_pciefd: kvaser_pciefd_open(): " Marc Kleine-Budde
@ 2020-12-01  3:08 ` Jakub Kicinski
  5 siblings, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2020-12-01  3:08 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, davem, linux-can, kernel

On Mon, 30 Nov 2020 13:53:02 +0100 Marc Kleine-Budde wrote:
> Hello Jakub, hello David,
> 
> here's a pull request of 5 patches for net/master.
> 
> The first patch is by me an target the tcan4x5x bindings for the m_can driver.
> It fixes the error path in the tcan4x5x_can_probe() function.
> 
> The next two patches are by Jeroen Hofstee and makes the lost of arbitration
> error counters of sja1000 and the sun4i drivers consistent with the other
> drivers.
> 
> Zhang Qilong contributes two patch that clean up the error path in the c_can
> and kvaser_pciefd drivers.

Pulled, thanks!

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

end of thread, other threads:[~2020-12-01  3:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30 12:53 pull-request: can 2020-11-30 Marc Kleine-Budde
2020-11-30 12:53 ` [net 1/5] can: m_can: tcan4x5x_can_probe(): fix error path: remove erroneous clk_disable_unprepare() Marc Kleine-Budde
2020-11-30 12:53 ` [net 2/5] can: sja1000: sja1000_err(): don't count arbitration lose as an error Marc Kleine-Budde
2020-11-30 12:53 ` [net 3/5] can: sun4i_can: sun4i_can_err(): " Marc Kleine-Budde
2020-11-30 12:53 ` [net 4/5] can: c_can: c_can_power_up(): fix error handling Marc Kleine-Budde
2020-11-30 12:53 ` [net 5/5] can: kvaser_pciefd: kvaser_pciefd_open(): " Marc Kleine-Budde
2020-12-01  3:08 ` pull-request: can 2020-11-30 Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).