All of lore.kernel.org
 help / color / mirror / Atom feed
* pull-request: can 2017-10-19
@ 2017-10-19 11:19 Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 01/11] can: flexcan: fix state transition regression Marc Kleine-Budde
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel

Hello David,

this is a pull request of 11 patches for the upcoming 4.14 release.

There are 6 patches by ZHU Yi for the flexcan driver, that work around
the CAN error handling state transition problems found in various
incarnations of the flexcan IP core.

The patch by Colin Ian King fixes a potential NULL pointer deref in the
CAN broad cast manager (bcm). One patch by me replaces a direct deref of a RCU
protected pointer by rcu_access_pointer. My second patch adds missing
OOM error handling in af_can. A patch by Stefan Mätje for the esd_usb2
driver fixes the dlc in received RTR frames. And the last patch is by
Wolfgang Grandegger, it fixes a busy loop in the gs_usb driver in case
it runs out of TX contexts.

regards,
Marc

---

The following changes since commit 28e33f9d78eefe98ea86673ab31e988b37a9a738:

  bpf: disallow arithmetic operations on context pointer (2017-10-18 13:21:13 +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-4.14-20171019

for you to fetch changes up to 97819f943063b622eca44d3644067c190dc75039:

  can: gs_usb: fix busy loop if no more TX context is available (2017-10-19 13:05:54 +0200)

----------------------------------------------------------------
linux-can-fixes-for-4.14-20171019

----------------------------------------------------------------
Colin Ian King (1):
      can: bcm: check for null sk before deferencing it via the call to sock_net

Marc Kleine-Budde (2):
      can: af_can: do not access proto_tab directly use rcu_access_pointer instead
      can: af_can: can_pernet_init(): add missing error handling for kzalloc returning NULL

Stefan Mätje (1):
      can: esd_usb2: Fix can_dlc value for received RTR, frames

Wolfgang Grandegger (1):
      can: gs_usb: fix busy loop if no more TX context is available

ZHU Yi (ST-FIR/ENG1-Zhu) (6):
      can: flexcan: fix state transition regression
      can: flexcan: rename legacy error state quirk
      can: flexcan: implement error passive state quirk
      can: flexcan: fix i.MX6 state transition issue
      can: flexcan: fix i.MX28 state transition issue
      can: flexcan: fix p1010 state transition issue

 drivers/net/can/flexcan.c      | 91 +++++++++++++++++++++++++++++++++++-------
 drivers/net/can/usb/esd_usb2.c |  2 +-
 drivers/net/can/usb/gs_usb.c   | 10 +----
 net/can/af_can.c               | 20 ++++++++--
 net/can/bcm.c                  |  5 ++-
 5 files changed, 98 insertions(+), 30 deletions(-)

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

* [PATCH 01/11] can: flexcan: fix state transition regression
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
@ 2017-10-19 11:19 ` Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 02/11] can: flexcan: rename legacy error state quirk Marc Kleine-Budde
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, ZHU Yi (ST-FIR/ENG1-Zhu),
	Zhu Yi, Mark Jonas, linux-stable, Marc Kleine-Budde

From: "ZHU Yi (ST-FIR/ENG1-Zhu)" <Yi.Zhu5@cn.bosch.com>

Update state upon any interrupt to report correct state transitions in
case the flexcan core enabled the broken error state quirk fix.

Signed-off-by: Zhu Yi <yi.zhu5@cn.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Acked-by: Wolfgang Grandegger <wg@grandegger.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v4.11
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/flexcan.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 13f0f219d8aa..df4bfb83024c 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -765,8 +765,9 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 		flexcan_write(reg_esr & FLEXCAN_ESR_ALL_INT, &regs->esr);
 	}
 
-	/* state change interrupt */
-	if (reg_esr & FLEXCAN_ESR_ERR_STATE)
+	/* state change interrupt or broken error state quirk fix is enabled */
+	if ((reg_esr & FLEXCAN_ESR_ERR_STATE) ||
+	    (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_ERR_STATE))
 		flexcan_irq_state(dev, reg_esr);
 
 	/* bus error IRQ - handle if bus error reporting is activated */
-- 
2.14.2


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

* [PATCH 02/11] can: flexcan: rename legacy error state quirk
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 01/11] can: flexcan: fix state transition regression Marc Kleine-Budde
@ 2017-10-19 11:19 ` Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 03/11] can: flexcan: implement error passive " Marc Kleine-Budde
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, ZHU Yi (ST-FIR/ENG1-Zhu),
	Zhu Yi, Mark Jonas, linux-stable, Marc Kleine-Budde

From: "ZHU Yi (ST-FIR/ENG1-Zhu)" <Yi.Zhu5@cn.bosch.com>

Rename FLEXCAN_QUIRK_BROKEN_ERR_STATE to FLEXCAN_QUIRK_BROKEN_WERR_STATE
for better description of the missing [TR]WRN_INT quirk.

Signed-off-by: Zhu Yi <yi.zhu5@cn.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Acked-by: Wolfgang Grandegger <wg@grandegger.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v4.11
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/flexcan.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index df4bfb83024c..e163c55e737b 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -193,7 +193,7 @@
  *
  * Some SOCs do not have the RX_WARN & TX_WARN interrupt line connected.
  */
-#define FLEXCAN_QUIRK_BROKEN_ERR_STATE	BIT(1) /* [TR]WRN_INT not connected */
+#define FLEXCAN_QUIRK_BROKEN_WERR_STATE	BIT(1) /* [TR]WRN_INT not connected */
 #define FLEXCAN_QUIRK_DISABLE_RXFG	BIT(2) /* Disable RX FIFO Global mask */
 #define FLEXCAN_QUIRK_ENABLE_EACEN_RRS	BIT(3) /* Enable EACEN and RRS bit in ctrl2 */
 #define FLEXCAN_QUIRK_DISABLE_MECR	BIT(4) /* Disable Memory error detection */
@@ -281,7 +281,7 @@ struct flexcan_priv {
 };
 
 static const struct flexcan_devtype_data fsl_p1010_devtype_data = {
-	.quirks = FLEXCAN_QUIRK_BROKEN_ERR_STATE,
+	.quirks = FLEXCAN_QUIRK_BROKEN_WERR_STATE,
 };
 
 static const struct flexcan_devtype_data fsl_imx28_devtype_data;
@@ -767,7 +767,7 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 
 	/* state change interrupt or broken error state quirk fix is enabled */
 	if ((reg_esr & FLEXCAN_ESR_ERR_STATE) ||
-	    (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_ERR_STATE))
+	    (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_WERR_STATE))
 		flexcan_irq_state(dev, reg_esr);
 
 	/* bus error IRQ - handle if bus error reporting is activated */
@@ -888,7 +888,7 @@ static int flexcan_chip_start(struct net_device *dev)
 	 * on most Flexcan cores, too. Otherwise we don't get
 	 * any error warning or passive interrupts.
 	 */
-	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_ERR_STATE ||
+	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_WERR_STATE ||
 	    priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
 		reg_ctrl |= FLEXCAN_CTRL_ERR_MSK;
 	else
-- 
2.14.2


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

* [PATCH 03/11] can: flexcan: implement error passive state quirk
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 01/11] can: flexcan: fix state transition regression Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 02/11] can: flexcan: rename legacy error state quirk Marc Kleine-Budde
@ 2017-10-19 11:19 ` Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 04/11] can: flexcan: fix i.MX6 state transition issue Marc Kleine-Budde
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, ZHU Yi (ST-FIR/ENG1-Zhu),
	Zhu Yi, Mark Jonas, linux-stable, Marc Kleine-Budde

From: "ZHU Yi (ST-FIR/ENG1-Zhu)" <Yi.Zhu5@cn.bosch.com>

Add FLEXCAN_QUIRK_BROKEN_PERR_STATE for better description of the
missing error passive interrupt quirk.

Error interrupt flooding may happen if the broken error state quirk fix
is enabled. For example, in case there is singled out node on the bus
and the node sends a frame, then error interrupt flooding happens and
will not stop because the node cannot go to bus off. The flooding will
stop after another node connected to the bus again.

If high bitrate configured on the low end system, then the flooding
may causes performance issue, hence, this patch mitigates this by:
1. disable error interrupt upon error passive state transition
2. re-enable error interrupt upon error warning state transition
3. disable/enable error interrupt upon error active state transition
   depends on FLEXCAN_QUIRK_BROKEN_WERR_STATE

In this way, the driver is still able to report correct state
transitions without additional latency. When there are bus problems,
flooding of error interrupts is limited to the number of frames required
to change state from error warning to error passive if the core has
[TR]WRN_INT connected (FLEXCAN_QUIRK_BROKEN_WERR_STATE is not enabled),
otherwise, the flooding is limited to the number of frames required to
change state from error active to error passive.

Signed-off-by: Zhu Yi <yi.zhu5@cn.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Acked-by: Wolfgang Grandegger <wg@grandegger.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v4.11
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/flexcan.c | 75 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 66 insertions(+), 9 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index e163c55e737b..c83a09fa4166 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -182,14 +182,14 @@
 /* FLEXCAN hardware feature flags
  *
  * Below is some version info we got:
- *    SOC   Version   IP-Version  Glitch- [TR]WRN_INT Memory err RTR re-
- *                                Filter? connected?  detection  ception in MB
- *   MX25  FlexCAN2  03.00.00.00     no        no         no        no
- *   MX28  FlexCAN2  03.00.04.00    yes       yes         no        no
- *   MX35  FlexCAN2  03.00.00.00     no        no         no        no
- *   MX53  FlexCAN2  03.00.00.00    yes        no         no        no
- *   MX6s  FlexCAN3  10.00.12.00    yes       yes         no       yes
- *   VF610 FlexCAN3  ?               no       yes        yes       yes?
+ *    SOC   Version   IP-Version  Glitch- [TR]WRN_INT IRQ Err Memory err RTR re-
+ *                                Filter? connected?  Passive detection  ception in MB
+ *   MX25  FlexCAN2  03.00.00.00     no        no         ?       no        no
+ *   MX28  FlexCAN2  03.00.04.00    yes       yes        no       no        no
+ *   MX35  FlexCAN2  03.00.00.00     no        no         ?       no        no
+ *   MX53  FlexCAN2  03.00.00.00    yes        no        no       no        no
+ *   MX6s  FlexCAN3  10.00.12.00    yes       yes        no       no       yes
+ *   VF610 FlexCAN3  ?               no       yes         ?      yes       yes?
  *
  * Some SOCs do not have the RX_WARN & TX_WARN interrupt line connected.
  */
@@ -198,6 +198,7 @@
 #define FLEXCAN_QUIRK_ENABLE_EACEN_RRS	BIT(3) /* Enable EACEN and RRS bit in ctrl2 */
 #define FLEXCAN_QUIRK_DISABLE_MECR	BIT(4) /* Disable Memory error detection */
 #define FLEXCAN_QUIRK_USE_OFF_TIMESTAMP	BIT(5) /* Use timestamp based offloading */
+#define FLEXCAN_QUIRK_BROKEN_PERR_STATE	BIT(6) /* No interrupt for error passive */
 
 /* Structure of the message buffer */
 struct flexcan_mb {
@@ -335,6 +336,22 @@ static inline void flexcan_write(u32 val, void __iomem *addr)
 }
 #endif
 
+static inline void flexcan_error_irq_enable(const struct flexcan_priv *priv)
+{
+	struct flexcan_regs __iomem *regs = priv->regs;
+	u32 reg_ctrl = (priv->reg_ctrl_default | FLEXCAN_CTRL_ERR_MSK);
+
+	flexcan_write(reg_ctrl, &regs->ctrl);
+}
+
+static inline void flexcan_error_irq_disable(const struct flexcan_priv *priv)
+{
+	struct flexcan_regs __iomem *regs = priv->regs;
+	u32 reg_ctrl = (priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_MSK);
+
+	flexcan_write(reg_ctrl, &regs->ctrl);
+}
+
 static inline int flexcan_transceiver_enable(const struct flexcan_priv *priv)
 {
 	if (!priv->reg_xceiver)
@@ -713,6 +730,7 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 	struct flexcan_regs __iomem *regs = priv->regs;
 	irqreturn_t handled = IRQ_NONE;
 	u32 reg_iflag1, reg_esr;
+	enum can_state last_state = priv->can.state;
 
 	reg_iflag1 = flexcan_read(&regs->iflag1);
 
@@ -767,7 +785,8 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 
 	/* state change interrupt or broken error state quirk fix is enabled */
 	if ((reg_esr & FLEXCAN_ESR_ERR_STATE) ||
-	    (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_WERR_STATE))
+	    (priv->devtype_data->quirks & (FLEXCAN_QUIRK_BROKEN_WERR_STATE |
+	                                   FLEXCAN_QUIRK_BROKEN_PERR_STATE)))
 		flexcan_irq_state(dev, reg_esr);
 
 	/* bus error IRQ - handle if bus error reporting is activated */
@@ -775,6 +794,44 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 	    (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING))
 		flexcan_irq_bus_err(dev, reg_esr);
 
+	/* availability of error interrupt among state transitions in case
+	 * bus error reporting is de-activated and
+	 * FLEXCAN_QUIRK_BROKEN_PERR_STATE is enabled:
+	 *  +--------------------------------------------------------------+
+	 *  | +----------------------------------------------+ [stopped /  |
+	 *  | |                                              |  sleeping] -+
+	 *  +-+-> active <-> warning <-> passive -> bus off -+
+	 *        ___________^^^^^^^^^^^^_______________________________
+	 *        disabled(1)  enabled             disabled
+	 *
+	 * (1): enabled if FLEXCAN_QUIRK_BROKEN_WERR_STATE is enabled
+	 */
+	if ((last_state != priv->can.state) &&
+	    (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_PERR_STATE) &&
+	    !(priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)) {
+		switch (priv->can.state) {
+		case CAN_STATE_ERROR_ACTIVE:
+			if (priv->devtype_data->quirks &
+			    FLEXCAN_QUIRK_BROKEN_WERR_STATE)
+				flexcan_error_irq_enable(priv);
+			else
+				flexcan_error_irq_disable(priv);
+			break;
+
+		case CAN_STATE_ERROR_WARNING:
+			flexcan_error_irq_enable(priv);
+			break;
+
+		case CAN_STATE_ERROR_PASSIVE:
+		case CAN_STATE_BUS_OFF:
+			flexcan_error_irq_disable(priv);
+			break;
+
+		default:
+			break;
+		}
+	}
+
 	return handled;
 }
 
-- 
2.14.2

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

* [PATCH 04/11] can: flexcan: fix i.MX6 state transition issue
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2017-10-19 11:19 ` [PATCH 03/11] can: flexcan: implement error passive " Marc Kleine-Budde
@ 2017-10-19 11:19 ` Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 05/11] can: flexcan: fix i.MX28 " Marc Kleine-Budde
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, ZHU Yi (ST-FIR/ENG1-Zhu),
	Zhu Yi, Mark Jonas, linux-stable, Marc Kleine-Budde

From: "ZHU Yi (ST-FIR/ENG1-Zhu)" <Yi.Zhu5@cn.bosch.com>

Enable FLEXCAN_QUIRK_BROKEN_PERR_STATE for i.MX6 to report correct state
transitions.

Signed-off-by: Zhu Yi <yi.zhu5@cn.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Acked-by: Wolfgang Grandegger <wg@grandegger.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v4.11
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/flexcan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index c83a09fa4166..d6ad12744ff1 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -289,7 +289,7 @@ static const struct flexcan_devtype_data fsl_imx28_devtype_data;
 
 static const struct flexcan_devtype_data fsl_imx6q_devtype_data = {
 	.quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
-		FLEXCAN_QUIRK_USE_OFF_TIMESTAMP,
+		FLEXCAN_QUIRK_USE_OFF_TIMESTAMP | FLEXCAN_QUIRK_BROKEN_PERR_STATE,
 };
 
 static const struct flexcan_devtype_data fsl_vf610_devtype_data = {
-- 
2.14.2

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

* [PATCH 05/11] can: flexcan: fix i.MX28 state transition issue
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2017-10-19 11:19 ` [PATCH 04/11] can: flexcan: fix i.MX6 state transition issue Marc Kleine-Budde
@ 2017-10-19 11:19 ` Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 06/11] can: flexcan: fix p1010 " Marc Kleine-Budde
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, ZHU Yi (ST-FIR/ENG1-Zhu),
	Wolfgang Grandegger, Zhu Yi, Mark Jonas, linux-stable,
	Marc Kleine-Budde

From: "ZHU Yi (ST-FIR/ENG1-Zhu)" <Yi.Zhu5@cn.bosch.com>

Enable FLEXCAN_QUIRK_BROKEN_PERR_STATE for i.MX28 to report correct
state transitions, especially to error passive.

Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
Signed-off-by: Zhu Yi <yi.zhu5@cn.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v4.11
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/flexcan.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index d6ad12744ff1..ed544c44848f 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -285,7 +285,9 @@ static const struct flexcan_devtype_data fsl_p1010_devtype_data = {
 	.quirks = FLEXCAN_QUIRK_BROKEN_WERR_STATE,
 };
 
-static const struct flexcan_devtype_data fsl_imx28_devtype_data;
+static const struct flexcan_devtype_data fsl_imx28_devtype_data = {
+	.quirks = FLEXCAN_QUIRK_BROKEN_PERR_STATE,
+};
 
 static const struct flexcan_devtype_data fsl_imx6q_devtype_data = {
 	.quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
-- 
2.14.2

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

* [PATCH 06/11] can: flexcan: fix p1010 state transition issue
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
                   ` (4 preceding siblings ...)
  2017-10-19 11:19 ` [PATCH 05/11] can: flexcan: fix i.MX28 " Marc Kleine-Budde
@ 2017-10-19 11:19 ` Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 07/11] can: bcm: check for null sk before deferencing it via the call to sock_net Marc Kleine-Budde
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, ZHU Yi (ST-FIR/ENG1-Zhu),
	Zhu Yi, Mark Jonas, linux-stable, Marc Kleine-Budde

From: "ZHU Yi (ST-FIR/ENG1-Zhu)" <Yi.Zhu5@cn.bosch.com>

Enable FLEXCAN_QUIRK_BROKEN_WERR_STATE and
FLEXCAN_QUIRK_BROKEN_PERR_STATE for p1010 to report correct state
transitions.

Signed-off-by: Zhu Yi <yi.zhu5@cn.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Acked-by: Wolfgang Grandegger <wg@grandegger.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v4.11
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/flexcan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index ed544c44848f..a13a4896a8bd 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -282,7 +282,8 @@ struct flexcan_priv {
 };
 
 static const struct flexcan_devtype_data fsl_p1010_devtype_data = {
-	.quirks = FLEXCAN_QUIRK_BROKEN_WERR_STATE,
+	.quirks = FLEXCAN_QUIRK_BROKEN_WERR_STATE |
+		FLEXCAN_QUIRK_BROKEN_PERR_STATE,
 };
 
 static const struct flexcan_devtype_data fsl_imx28_devtype_data = {
-- 
2.14.2


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

* [PATCH 07/11] can: bcm: check for null sk before deferencing it via the call to sock_net
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
                   ` (5 preceding siblings ...)
  2017-10-19 11:19 ` [PATCH 06/11] can: flexcan: fix p1010 " Marc Kleine-Budde
@ 2017-10-19 11:19 ` Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 08/11] can: af_can: do not access proto_tab directly use rcu_access_pointer instead Marc Kleine-Budde
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Colin Ian King, Marc Kleine-Budde

From: Colin Ian King <colin.king@canonical.com>

The assignment of net via call sock_net will dereference sk. This
is performed before a sanity null check on sk, so there could be
a potential null dereference on the sock_net call if sk is null.
Fix this by assigning net after the sk null check. Also replace
the sk == NULL with the more usual !sk idiom.

Detected by CoverityScan CID#1431862 ("Dereference before null check")

Fixes: 384317ef4187 ("can: network namespace support for CAN_BCM protocol")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/bcm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/can/bcm.c b/net/can/bcm.c
index 47a8748d953a..13690334efa3 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -1493,13 +1493,14 @@ static int bcm_init(struct sock *sk)
 static int bcm_release(struct socket *sock)
 {
 	struct sock *sk = sock->sk;
-	struct net *net = sock_net(sk);
+	struct net *net;
 	struct bcm_sock *bo;
 	struct bcm_op *op, *next;
 
-	if (sk == NULL)
+	if (!sk)
 		return 0;
 
+	net = sock_net(sk);
 	bo = bcm_sk(sk);
 
 	/* remove bcm_ops, timer, rx_unregister(), etc. */
-- 
2.14.2

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

* [PATCH 08/11] can: af_can: do not access proto_tab directly use rcu_access_pointer instead
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
                   ` (6 preceding siblings ...)
  2017-10-19 11:19 ` [PATCH 07/11] can: bcm: check for null sk before deferencing it via the call to sock_net Marc Kleine-Budde
@ 2017-10-19 11:19 ` Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 09/11] can: af_can: can_pernet_init(): add missing error handling for kzalloc returning NULL Marc Kleine-Budde
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Marc Kleine-Budde

"proto_tab" is a RCU protected array, when directly accessing the array,
sparse throws these warnings:

  CHECK   /srv/work/frogger/socketcan/linux/net/can/af_can.c
net/can/af_can.c:115:14: error: incompatible types in comparison expression (different address spaces)
net/can/af_can.c:795:17: error: incompatible types in comparison expression (different address spaces)
net/can/af_can.c:816:9: error: incompatible types in comparison expression (different address spaces)

This patch fixes the problem by using rcu_access_pointer() and
annotating "proto_tab" array as __rcu.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/af_can.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/can/af_can.c b/net/can/af_can.c
index 88edac0f3e36..eb1ad74b40f4 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -78,7 +78,7 @@ MODULE_PARM_DESC(stats_timer, "enable timer for statistics (default:on)");
 static struct kmem_cache *rcv_cache __read_mostly;
 
 /* table of registered CAN protocols */
-static const struct can_proto *proto_tab[CAN_NPROTO] __read_mostly;
+static const struct can_proto __rcu *proto_tab[CAN_NPROTO] __read_mostly;
 static DEFINE_MUTEX(proto_tab_lock);
 
 static atomic_t skbcounter = ATOMIC_INIT(0);
@@ -788,7 +788,7 @@ int can_proto_register(const struct can_proto *cp)
 
 	mutex_lock(&proto_tab_lock);
 
-	if (proto_tab[proto]) {
+	if (rcu_access_pointer(proto_tab[proto])) {
 		pr_err("can: protocol %d already registered\n", proto);
 		err = -EBUSY;
 	} else
@@ -812,7 +812,7 @@ void can_proto_unregister(const struct can_proto *cp)
 	int proto = cp->protocol;
 
 	mutex_lock(&proto_tab_lock);
-	BUG_ON(proto_tab[proto] != cp);
+	BUG_ON(rcu_access_pointer(proto_tab[proto]) != cp);
 	RCU_INIT_POINTER(proto_tab[proto], NULL);
 	mutex_unlock(&proto_tab_lock);
 
-- 
2.14.2

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

* [PATCH 09/11] can: af_can: can_pernet_init(): add missing error handling for kzalloc returning NULL
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
                   ` (7 preceding siblings ...)
  2017-10-19 11:19 ` [PATCH 08/11] can: af_can: do not access proto_tab directly use rcu_access_pointer instead Marc Kleine-Budde
@ 2017-10-19 11:19 ` Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 10/11] can: esd_usb2: Fix can_dlc value for received RTR, frames Marc Kleine-Budde
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Marc Kleine-Budde, linux-stable

This patch adds the missing check and error handling for out-of-memory
situations, when kzalloc cannot allocate memory.

Fixes: cb5635a36776 ("can: complete initial namespace support")
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/af_can.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/net/can/af_can.c b/net/can/af_can.c
index eb1ad74b40f4..ecd5c703d11e 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -875,9 +875,14 @@ static int can_pernet_init(struct net *net)
 	spin_lock_init(&net->can.can_rcvlists_lock);
 	net->can.can_rx_alldev_list =
 		kzalloc(sizeof(struct dev_rcv_lists), GFP_KERNEL);
-
+	if (!net->can.can_rx_alldev_list)
+		goto out;
 	net->can.can_stats = kzalloc(sizeof(struct s_stats), GFP_KERNEL);
+	if (!net->can.can_stats)
+		goto out_free_alldev_list;
 	net->can.can_pstats = kzalloc(sizeof(struct s_pstats), GFP_KERNEL);
+	if (!net->can.can_pstats)
+		goto out_free_can_stats;
 
 	if (IS_ENABLED(CONFIG_PROC_FS)) {
 		/* the statistics are updated every second (timer triggered) */
@@ -892,6 +897,13 @@ static int can_pernet_init(struct net *net)
 	}
 
 	return 0;
+
+ out_free_can_stats:
+	kfree(net->can.can_stats);
+ out_free_alldev_list:
+	kfree(net->can.can_rx_alldev_list);
+ out:
+	return -ENOMEM;
 }
 
 static void can_pernet_exit(struct net *net)
-- 
2.14.2

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

* [PATCH 10/11] can: esd_usb2: Fix can_dlc value for received RTR, frames
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
                   ` (8 preceding siblings ...)
  2017-10-19 11:19 ` [PATCH 09/11] can: af_can: can_pernet_init(): add missing error handling for kzalloc returning NULL Marc Kleine-Budde
@ 2017-10-19 11:19 ` Marc Kleine-Budde
  2017-10-19 11:19 ` [PATCH 11/11] can: gs_usb: fix busy loop if no more TX context is available Marc Kleine-Budde
  2017-10-21  1:30 ` pull-request: can 2017-10-19 David Miller
  11 siblings, 0 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Stefan Mätje, Stefan Mätje,
	linux-stable, Marc Kleine-Budde

From: Stefan Mätje <Stefan.Maetje@esd.eu>

The dlc member of the struct rx_msg contains also the ESD_RTR flag to
mark received RTR frames. Without the fix the can_dlc value for received
RTR frames would always be set to 8 by get_can_dlc() instead of the
received value.

Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device")
Signed-off-by: Stefan Mätje <stefan.maetje@esd.eu>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/esd_usb2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c
index be928ce62d32..9fdb0f0bfa06 100644
--- a/drivers/net/can/usb/esd_usb2.c
+++ b/drivers/net/can/usb/esd_usb2.c
@@ -333,7 +333,7 @@ static void esd_usb2_rx_can_msg(struct esd_usb2_net_priv *priv,
 		}
 
 		cf->can_id = id & ESD_IDMASK;
-		cf->can_dlc = get_can_dlc(msg->msg.rx.dlc);
+		cf->can_dlc = get_can_dlc(msg->msg.rx.dlc & ~ESD_RTR);
 
 		if (id & ESD_EXTID)
 			cf->can_id |= CAN_EFF_FLAG;
-- 
2.14.2

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

* [PATCH 11/11] can: gs_usb: fix busy loop if no more TX context is available
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
                   ` (9 preceding siblings ...)
  2017-10-19 11:19 ` [PATCH 10/11] can: esd_usb2: Fix can_dlc value for received RTR, frames Marc Kleine-Budde
@ 2017-10-19 11:19 ` Marc Kleine-Budde
  2017-10-21  1:30 ` pull-request: can 2017-10-19 David Miller
  11 siblings, 0 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2017-10-19 11:19 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Wolfgang Grandegger, linux-stable,
	Marc Kleine-Budde

From: Wolfgang Grandegger <wg@grandegger.com>

If sending messages with no cable connected, it quickly happens that
there is no more TX context available. Then "gs_can_start_xmit()"
returns with "NETDEV_TX_BUSY" and the upper layer does retry
immediately keeping the CPU busy. To fix that issue, I moved
"atomic_dec(&dev->active_tx_urbs)" from "gs_usb_xmit_callback()" to
the TX done handling in "gs_usb_receive_bulk_callback()". Renaming
"active_tx_urbs" to "active_tx_contexts" and moving it into
"gs_[alloc|free]_tx_context()" would also make sense.

Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/gs_usb.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index afcc1312dbaf..68ac3e88a8ce 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -375,6 +375,8 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
 
 		gs_free_tx_context(txc);
 
+		atomic_dec(&dev->active_tx_urbs);
+
 		netif_wake_queue(netdev);
 	}
 
@@ -463,14 +465,6 @@ static void gs_usb_xmit_callback(struct urb *urb)
 			  urb->transfer_buffer_length,
 			  urb->transfer_buffer,
 			  urb->transfer_dma);
-
-	atomic_dec(&dev->active_tx_urbs);
-
-	if (!netif_device_present(netdev))
-		return;
-
-	if (netif_queue_stopped(netdev))
-		netif_wake_queue(netdev);
 }
 
 static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
-- 
2.14.2

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

* Re: pull-request: can 2017-10-19
  2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
                   ` (10 preceding siblings ...)
  2017-10-19 11:19 ` [PATCH 11/11] can: gs_usb: fix busy loop if no more TX context is available Marc Kleine-Budde
@ 2017-10-21  1:30 ` David Miller
  11 siblings, 0 replies; 13+ messages in thread
From: David Miller @ 2017-10-21  1:30 UTC (permalink / raw)
  To: mkl; +Cc: netdev, linux-can, kernel

From: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Thu, 19 Oct 2017 13:19:34 +0200

> this is a pull request of 11 patches for the upcoming 4.14 release.
> 
> There are 6 patches by ZHU Yi for the flexcan driver, that work around
> the CAN error handling state transition problems found in various
> incarnations of the flexcan IP core.
> 
> The patch by Colin Ian King fixes a potential NULL pointer deref in the
> CAN broad cast manager (bcm). One patch by me replaces a direct deref of a RCU
> protected pointer by rcu_access_pointer. My second patch adds missing
> OOM error handling in af_can. A patch by Stefan Mätje for the esd_usb2
> driver fixes the dlc in received RTR frames. And the last patch is by
> Wolfgang Grandegger, it fixes a busy loop in the gs_usb driver in case
> it runs out of TX contexts.

Pulled, thanks.

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

end of thread, other threads:[~2017-10-21  1:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-19 11:19 pull-request: can 2017-10-19 Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 01/11] can: flexcan: fix state transition regression Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 02/11] can: flexcan: rename legacy error state quirk Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 03/11] can: flexcan: implement error passive " Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 04/11] can: flexcan: fix i.MX6 state transition issue Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 05/11] can: flexcan: fix i.MX28 " Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 06/11] can: flexcan: fix p1010 " Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 07/11] can: bcm: check for null sk before deferencing it via the call to sock_net Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 08/11] can: af_can: do not access proto_tab directly use rcu_access_pointer instead Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 09/11] can: af_can: can_pernet_init(): add missing error handling for kzalloc returning NULL Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 10/11] can: esd_usb2: Fix can_dlc value for received RTR, frames Marc Kleine-Budde
2017-10-19 11:19 ` [PATCH 11/11] can: gs_usb: fix busy loop if no more TX context is available Marc Kleine-Budde
2017-10-21  1:30 ` pull-request: can 2017-10-19 David Miller

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.