All of lore.kernel.org
 help / color / mirror / Atom feed
* pull-request: can 2020-01-02
@ 2020-01-02 16:09 Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 1/9] can: tcan4x5x: tcan4x5x_can_probe(): get the device out of standby before register access Marc Kleine-Budde
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2020-01-02 16:09 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel

Hello David,

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

The first 5 patches target all the tcan4x5x driver. The first 3 patches
of them are by Dan Murphy and Sean Nyekjaer and improve the device
initialization (power on, reset and get device out of standby before
register access). The next patch is by Dan Murphy and disables the INH
pin device-state if the GPIO is unavailable. The last patch for the
tcan4x5x driver is by Gustavo A. R. Silva and fixes an inconsistent
PTR_ERR check in the tcan4x5x_parse_config() function.

The next patch is by Oliver Hartkopp and targets the generic CAN device
infrastructure. It ensures that an initialized headroom in outgoing CAN
sk_buffs (e.g. if injected by AF_PACKET).

The last 2 patches are by Johan Hovold and fix the kvaser_usb and gs_usb
drivers by always using the current alternate setting not blindly the
first one.

regards,
Marc

---

The following changes since commit 738d2902773e30939a982c8df7a7f94293659810:

  Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net (2019-12-31 11:14:58 -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.5-20200102

for you to fetch changes up to 2d77bd61a2927be8f4e00d9478fe6996c47e8d45:

  can: mscan: mscan_rx_poll(): fix rx path lockup when returning from polling to irq mode (2020-01-02 15:34:27 +0100)

----------------------------------------------------------------
linux-can-fixes-for-5.5-20200102

----------------------------------------------------------------
Dan Murphy (2):
      can: tcan4x5x: tcan4x5x_can_probe(): turn on the power before parsing the config
      can: tcan4x5x: tcan4x5x_parse_config(): Disable the INH pin device-state GPIO is unavailable

Florian Faber (1):
      can: mscan: mscan_rx_poll(): fix rx path lockup when returning from polling to irq mode

Gustavo A. R. Silva (1):
      can: tcan4x5x: tcan4x5x_parse_config(): fix inconsistent IS_ERR and PTR_ERR

Johan Hovold (2):
      can: kvaser_usb: fix interface sanity check
      can: gs_usb: gs_usb_probe(): use descriptors of current altsetting

Oliver Hartkopp (1):
      can: can_dropped_invalid_skb(): ensure an initialized headroom in outgoing CAN sk_buffs

Sean Nyekjaer (2):
      can: tcan4x5x: tcan4x5x_can_probe(): get the device out of standby before register access
      can: tcan4x5x: tcan4x5x_parse_config(): reset device before register access

 drivers/net/can/m_can/tcan4x5x.c                  | 63 +++++++++++++++++++----
 drivers/net/can/mscan/mscan.c                     | 21 ++++----
 drivers/net/can/usb/gs_usb.c                      |  4 +-
 drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c |  2 +-
 drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c  |  2 +-
 include/linux/can/dev.h                           | 34 ++++++++++++
 6 files changed, 101 insertions(+), 25 deletions(-)

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

* [PATCH 1/9] can: tcan4x5x: tcan4x5x_can_probe(): get the device out of standby before register access
  2020-01-02 16:09 pull-request: can 2020-01-02 Marc Kleine-Budde
@ 2020-01-02 16:09 ` Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 2/9] can: tcan4x5x: tcan4x5x_can_probe(): turn on the power before parsing the config Marc Kleine-Budde
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2020-01-02 16:09 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Sean Nyekjaer, stable, Dan Murphy,
	Marc Kleine-Budde

From: Sean Nyekjaer <sean@geanix.com>

The m_can tries to detect if Non ISO Operation is available while in
standby mode, this function results in the following error:

| tcan4x5x spi2.0 (unnamed net_device) (uninitialized): Failed to init module
| tcan4x5x spi2.0: m_can device registered (irq=84, version=32)
| tcan4x5x spi2.0 can2: TCAN4X5X successfully initialized.

When the tcan device comes out of reset it goes in standby mode. The
m_can driver tries to access the control register but fails due to the
device being in standby mode.

So this patch will put the tcan device in normal mode before the m_can
driver does the initialization.

Fixes: 5443c226ba91 ("can: tcan4x5x: Add tcan4x5x driver to the kernel")
Cc: stable@vger.kernel.org
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
Acked-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/tcan4x5x.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x.c
index 4e1789ea2bc3..c9fb864fcfa1 100644
--- a/drivers/net/can/m_can/tcan4x5x.c
+++ b/drivers/net/can/m_can/tcan4x5x.c
@@ -457,6 +457,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 
 	tcan4x5x_power_enable(priv->power, 1);
 
+	ret = tcan4x5x_init(mcan_class);
+	if (ret)
+		goto out_power;
+
 	ret = m_can_class_register(mcan_class);
 	if (ret)
 		goto out_power;
-- 
2.24.1

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

* [PATCH 2/9] can: tcan4x5x: tcan4x5x_can_probe(): turn on the power before parsing the config
  2020-01-02 16:09 pull-request: can 2020-01-02 Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 1/9] can: tcan4x5x: tcan4x5x_can_probe(): get the device out of standby before register access Marc Kleine-Budde
@ 2020-01-02 16:09 ` Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 3/9] can: tcan4x5x: tcan4x5x_parse_config(): reset device before register access Marc Kleine-Budde
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2020-01-02 16:09 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Dan Murphy, Marc Kleine-Budde

From: Dan Murphy <dmurphy@ti.com>

The tcan4x5x_parse_config() function now performs action on the device
either reading or writing and a reset. If the devive has a switchable
power supppy (i.e. regulator is managed) it needs to be turned on.

So turn on the regulator if available. If the parsing fails, turn off
the regulator.

Fixes: 2de497356955 ("can: tcan45x: Make wake-up GPIO an optional GPIO")
Signed-off-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/tcan4x5x.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x.c
index c9fb864fcfa1..a69476f5aec6 100644
--- a/drivers/net/can/m_can/tcan4x5x.c
+++ b/drivers/net/can/m_can/tcan4x5x.c
@@ -374,11 +374,6 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
 	if (IS_ERR(tcan4x5x->device_state_gpio))
 		tcan4x5x->device_state_gpio = NULL;
 
-	tcan4x5x->power = devm_regulator_get_optional(cdev->dev,
-						      "vsup");
-	if (PTR_ERR(tcan4x5x->power) == -EPROBE_DEFER)
-		return -EPROBE_DEFER;
-
 	return 0;
 }
 
@@ -412,6 +407,12 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 	if (!priv)
 		return -ENOMEM;
 
+	priv->power = devm_regulator_get_optional(&spi->dev, "vsup");
+	if (PTR_ERR(priv->power) == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+	else
+		priv->power = NULL;
+
 	mcan_class->device_data = priv;
 
 	m_can_class_get_clocks(mcan_class);
@@ -451,11 +452,13 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
 	priv->regmap = devm_regmap_init(&spi->dev, &tcan4x5x_bus,
 					&spi->dev, &tcan4x5x_regmap);
 
-	ret = tcan4x5x_parse_config(mcan_class);
+	ret = tcan4x5x_power_enable(priv->power, 1);
 	if (ret)
 		goto out_clk;
 
-	tcan4x5x_power_enable(priv->power, 1);
+	ret = tcan4x5x_parse_config(mcan_class);
+	if (ret)
+		goto out_power;
 
 	ret = tcan4x5x_init(mcan_class);
 	if (ret)
-- 
2.24.1

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

* [PATCH 3/9] can: tcan4x5x: tcan4x5x_parse_config(): reset device before register access
  2020-01-02 16:09 pull-request: can 2020-01-02 Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 1/9] can: tcan4x5x: tcan4x5x_can_probe(): get the device out of standby before register access Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 2/9] can: tcan4x5x: tcan4x5x_can_probe(): turn on the power before parsing the config Marc Kleine-Budde
@ 2020-01-02 16:09 ` Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 4/9] can: tcan4x5x: tcan4x5x_parse_config(): Disable the INH pin device-state GPIO is unavailable Marc Kleine-Budde
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2020-01-02 16:09 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Sean Nyekjaer, Marc Kleine-Budde

From: Sean Nyekjaer <sean@geanix.com>

It's a good idea to reset a ip-block/spi device before using it, this
patch will reset the device.

And a generic reset function if needed elsewhere.

Signed-off-by: Sean Nyekjaer <sean@geanix.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/tcan4x5x.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x.c
index a69476f5aec6..ee22e39f131b 100644
--- a/drivers/net/can/m_can/tcan4x5x.c
+++ b/drivers/net/can/m_can/tcan4x5x.c
@@ -166,6 +166,28 @@ static void tcan4x5x_check_wake(struct tcan4x5x_priv *priv)
 	}
 }
 
+static int tcan4x5x_reset(struct tcan4x5x_priv *priv)
+{
+	int ret = 0;
+
+	if (priv->reset_gpio) {
+		gpiod_set_value(priv->reset_gpio, 1);
+
+		/* tpulse_width minimum 30us */
+		usleep_range(30, 100);
+		gpiod_set_value(priv->reset_gpio, 0);
+	} else {
+		ret = regmap_write(priv->regmap, TCAN4X5X_CONFIG,
+				   TCAN4X5X_SW_RESET);
+		if (ret)
+			return ret;
+	}
+
+	usleep_range(700, 1000);
+
+	return ret;
+}
+
 static int regmap_spi_gather_write(void *context, const void *reg,
 				   size_t reg_len, const void *val,
 				   size_t val_len)
@@ -351,6 +373,7 @@ static int tcan4x5x_disable_wake(struct m_can_classdev *cdev)
 static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
 {
 	struct tcan4x5x_priv *tcan4x5x = cdev->device_data;
+	int ret;
 
 	tcan4x5x->device_wake_gpio = devm_gpiod_get(cdev->dev, "device-wake",
 						    GPIOD_OUT_HIGH);
@@ -366,7 +389,9 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
 	if (IS_ERR(tcan4x5x->reset_gpio))
 		tcan4x5x->reset_gpio = NULL;
 
-	usleep_range(700, 1000);
+	ret = tcan4x5x_reset(tcan4x5x);
+	if (ret)
+		return ret;
 
 	tcan4x5x->device_state_gpio = devm_gpiod_get_optional(cdev->dev,
 							      "device-state",
-- 
2.24.1

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

* [PATCH 4/9] can: tcan4x5x: tcan4x5x_parse_config(): Disable the INH pin device-state GPIO is unavailable
  2020-01-02 16:09 pull-request: can 2020-01-02 Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2020-01-02 16:09 ` [PATCH 3/9] can: tcan4x5x: tcan4x5x_parse_config(): reset device before register access Marc Kleine-Budde
@ 2020-01-02 16:09 ` Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 5/9] can: tcan4x5x: tcan4x5x_parse_config(): fix inconsistent IS_ERR and PTR_ERR Marc Kleine-Budde
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2020-01-02 16:09 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Dan Murphy, Marc Kleine-Budde

From: Dan Murphy <dmurphy@ti.com>

If the device state GPIO is not connected to the host then disable the
INH output from the TCAN device per section 8.3.5 of the data sheet.

Signed-off-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/tcan4x5x.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x.c
index ee22e39f131b..a413e7548546 100644
--- a/drivers/net/can/m_can/tcan4x5x.c
+++ b/drivers/net/can/m_can/tcan4x5x.c
@@ -102,6 +102,7 @@
 #define TCAN4X5X_MODE_NORMAL BIT(7)
 
 #define TCAN4X5X_DISABLE_WAKE_MSK	(BIT(31) | BIT(30))
+#define TCAN4X5X_DISABLE_INH_MSK	BIT(9)
 
 #define TCAN4X5X_SW_RESET BIT(2)
 
@@ -370,6 +371,14 @@ static int tcan4x5x_disable_wake(struct m_can_classdev *cdev)
 				  TCAN4X5X_DISABLE_WAKE_MSK, 0x00);
 }
 
+static int tcan4x5x_disable_state(struct m_can_classdev *cdev)
+{
+	struct tcan4x5x_priv *tcan4x5x = cdev->device_data;
+
+	return regmap_update_bits(tcan4x5x->regmap, TCAN4X5X_CONFIG,
+				  TCAN4X5X_DISABLE_INH_MSK, 0x01);
+}
+
 static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
 {
 	struct tcan4x5x_priv *tcan4x5x = cdev->device_data;
@@ -396,8 +405,10 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
 	tcan4x5x->device_state_gpio = devm_gpiod_get_optional(cdev->dev,
 							      "device-state",
 							      GPIOD_IN);
-	if (IS_ERR(tcan4x5x->device_state_gpio))
+	if (IS_ERR(tcan4x5x->device_state_gpio)) {
 		tcan4x5x->device_state_gpio = NULL;
+		tcan4x5x_disable_state(cdev);
+	}
 
 	return 0;
 }
-- 
2.24.1

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

* [PATCH 5/9] can: tcan4x5x: tcan4x5x_parse_config(): fix inconsistent IS_ERR and PTR_ERR
  2020-01-02 16:09 pull-request: can 2020-01-02 Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2020-01-02 16:09 ` [PATCH 4/9] can: tcan4x5x: tcan4x5x_parse_config(): Disable the INH pin device-state GPIO is unavailable Marc Kleine-Budde
@ 2020-01-02 16:09 ` Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 6/9] can: can_dropped_invalid_skb(): ensure an initialized headroom in outgoing CAN sk_buffs Marc Kleine-Budde
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2020-01-02 16:09 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Gustavo A. R. Silva, Dan Murphy,
	Marc Kleine-Budde

From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>

Fix inconsistent IS_ERR and PTR_ERR in tcan4x5x_parse_config().

The proper pointer to be passed as argument is tcan4x5x->device_wake_gpio.

This bug was detected with the help of Coccinelle.

Fixes: 2de497356955 ("can: tcan45x: Make wake-up GPIO an optional GPIO")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Acked-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/tcan4x5x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x.c
index a413e7548546..eacd428e07e9 100644
--- a/drivers/net/can/m_can/tcan4x5x.c
+++ b/drivers/net/can/m_can/tcan4x5x.c
@@ -387,7 +387,7 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
 	tcan4x5x->device_wake_gpio = devm_gpiod_get(cdev->dev, "device-wake",
 						    GPIOD_OUT_HIGH);
 	if (IS_ERR(tcan4x5x->device_wake_gpio)) {
-		if (PTR_ERR(tcan4x5x->power) == -EPROBE_DEFER)
+		if (PTR_ERR(tcan4x5x->device_wake_gpio) == -EPROBE_DEFER)
 			return -EPROBE_DEFER;
 
 		tcan4x5x_disable_wake(cdev);
-- 
2.24.1

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

* [PATCH 6/9] can: can_dropped_invalid_skb(): ensure an initialized headroom in outgoing CAN sk_buffs
  2020-01-02 16:09 pull-request: can 2020-01-02 Marc Kleine-Budde
                   ` (4 preceding siblings ...)
  2020-01-02 16:09 ` [PATCH 5/9] can: tcan4x5x: tcan4x5x_parse_config(): fix inconsistent IS_ERR and PTR_ERR Marc Kleine-Budde
@ 2020-01-02 16:09 ` Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 7/9] can: kvaser_usb: fix interface sanity check Marc Kleine-Budde
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2020-01-02 16:09 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Oliver Hartkopp,
	syzbot+b02ff0707a97e4e79ebb, linux-stable, Marc Kleine-Budde

From: Oliver Hartkopp <socketcan@hartkopp.net>

KMSAN sysbot detected a read access to an untinitialized value in the
headroom of an outgoing CAN related sk_buff. When using CAN sockets this
area is filled appropriately - but when using a packet socket this
initialization is missing.

The problematic read access occurs in the CAN receive path which can
only be triggered when the sk_buff is sent through a (virtual) CAN
interface. So we check in the sending path whether we need to perform
the missing initializations.

Fixes: d3b58c47d330d ("can: replace timestamp as unique skb attribute")
Reported-by: syzbot+b02ff0707a97e4e79ebb@syzkaller.appspotmail.com
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-by: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: linux-stable <stable@vger.kernel.org> # >= v4.1
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 include/linux/can/dev.h | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 9b3c720a31b1..5e3d45525bd3 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -18,6 +18,7 @@
 #include <linux/can/error.h>
 #include <linux/can/led.h>
 #include <linux/can/netlink.h>
+#include <linux/can/skb.h>
 #include <linux/netdevice.h>
 
 /*
@@ -91,6 +92,36 @@ struct can_priv {
 #define get_can_dlc(i)		(min_t(__u8, (i), CAN_MAX_DLC))
 #define get_canfd_dlc(i)	(min_t(__u8, (i), CANFD_MAX_DLC))
 
+/* Check for outgoing skbs that have not been created by the CAN subsystem */
+static inline bool can_skb_headroom_valid(struct net_device *dev,
+					  struct sk_buff *skb)
+{
+	/* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */
+	if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv)))
+		return false;
+
+	/* af_packet does not apply CAN skb specific settings */
+	if (skb->ip_summed == CHECKSUM_NONE) {
+		/* init headroom */
+		can_skb_prv(skb)->ifindex = dev->ifindex;
+		can_skb_prv(skb)->skbcnt = 0;
+
+		skb->ip_summed = CHECKSUM_UNNECESSARY;
+
+		/* preform proper loopback on capable devices */
+		if (dev->flags & IFF_ECHO)
+			skb->pkt_type = PACKET_LOOPBACK;
+		else
+			skb->pkt_type = PACKET_HOST;
+
+		skb_reset_mac_header(skb);
+		skb_reset_network_header(skb);
+		skb_reset_transport_header(skb);
+	}
+
+	return true;
+}
+
 /* Drop a given socketbuffer if it does not contain a valid CAN frame. */
 static inline bool can_dropped_invalid_skb(struct net_device *dev,
 					  struct sk_buff *skb)
@@ -108,6 +139,9 @@ static inline bool can_dropped_invalid_skb(struct net_device *dev,
 	} else
 		goto inval_skb;
 
+	if (!can_skb_headroom_valid(dev, skb))
+		goto inval_skb;
+
 	return false;
 
 inval_skb:
-- 
2.24.1

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

* [PATCH 7/9] can: kvaser_usb: fix interface sanity check
  2020-01-02 16:09 pull-request: can 2020-01-02 Marc Kleine-Budde
                   ` (5 preceding siblings ...)
  2020-01-02 16:09 ` [PATCH 6/9] can: can_dropped_invalid_skb(): ensure an initialized headroom in outgoing CAN sk_buffs Marc Kleine-Budde
@ 2020-01-02 16:09 ` Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 8/9] can: gs_usb: gs_usb_probe(): use descriptors of current altsetting Marc Kleine-Budde
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2020-01-02 16:09 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Johan Hovold, stable, Jimmy Assarsson,
	Christer Beskow, Nicklas Johansson, Martin Henriksson,
	Marc Kleine-Budde

From: Johan Hovold <johan@kernel.org>

Make sure to use the current alternate setting when verifying the
interface descriptors to avoid binding to an invalid interface.

Failing to do so could cause the driver to misbehave or trigger a WARN()
in usb_submit_urb() that kernels with panic_on_warn set would choke on.

Fixes: aec5fb2268b7 ("can: kvaser_usb: Add support for Kvaser USB hydra family")
Cc: stable <stable@vger.kernel.org>     # 4.19
Cc: Jimmy Assarsson <extja@kvaser.com>
Cc: Christer Beskow <chbe@kvaser.com>
Cc: Nicklas Johansson <extnj@kvaser.com>
Cc: Martin Henriksson <mh@kvaser.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 2 +-
 drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
index 5fc0be564274..7ab87a758754 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
@@ -1590,7 +1590,7 @@ static int kvaser_usb_hydra_setup_endpoints(struct kvaser_usb *dev)
 	struct usb_endpoint_descriptor *ep;
 	int i;
 
-	iface_desc = &dev->intf->altsetting[0];
+	iface_desc = dev->intf->cur_altsetting;
 
 	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
 		ep = &iface_desc->endpoint[i].desc;
diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
index ae4c37e1bb75..1b9957f12459 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
@@ -1310,7 +1310,7 @@ static int kvaser_usb_leaf_setup_endpoints(struct kvaser_usb *dev)
 	struct usb_endpoint_descriptor *endpoint;
 	int i;
 
-	iface_desc = &dev->intf->altsetting[0];
+	iface_desc = dev->intf->cur_altsetting;
 
 	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
 		endpoint = &iface_desc->endpoint[i].desc;
-- 
2.24.1

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

* [PATCH 8/9] can: gs_usb: gs_usb_probe(): use descriptors of current altsetting
  2020-01-02 16:09 pull-request: can 2020-01-02 Marc Kleine-Budde
                   ` (6 preceding siblings ...)
  2020-01-02 16:09 ` [PATCH 7/9] can: kvaser_usb: fix interface sanity check Marc Kleine-Budde
@ 2020-01-02 16:09 ` Marc Kleine-Budde
  2020-01-02 16:09 ` [PATCH 9/9] can: mscan: mscan_rx_poll(): fix rx path lockup when returning from polling to irq mode Marc Kleine-Budde
  2020-01-03  0:41 ` pull-request: can 2020-01-02 David Miller
  9 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2020-01-02 16:09 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Johan Hovold, Marc Kleine-Budde

From: Johan Hovold <johan@kernel.org>

Make sure to always use the descriptors of the current alternate setting
to avoid future issues when accessing fields that may differ between
settings.

Signed-off-by: Johan Hovold <johan@kernel.org>
Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devices")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/gs_usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 2f74f6704c12..a4b4b742c80c 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -918,7 +918,7 @@ static int gs_usb_probe(struct usb_interface *intf,
 			     GS_USB_BREQ_HOST_FORMAT,
 			     USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
 			     1,
-			     intf->altsetting[0].desc.bInterfaceNumber,
+			     intf->cur_altsetting->desc.bInterfaceNumber,
 			     hconf,
 			     sizeof(*hconf),
 			     1000);
@@ -941,7 +941,7 @@ static int gs_usb_probe(struct usb_interface *intf,
 			     GS_USB_BREQ_DEVICE_CONFIG,
 			     USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
 			     1,
-			     intf->altsetting[0].desc.bInterfaceNumber,
+			     intf->cur_altsetting->desc.bInterfaceNumber,
 			     dconf,
 			     sizeof(*dconf),
 			     1000);
-- 
2.24.1

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

* [PATCH 9/9] can: mscan: mscan_rx_poll(): fix rx path lockup when returning from polling to irq mode
  2020-01-02 16:09 pull-request: can 2020-01-02 Marc Kleine-Budde
                   ` (7 preceding siblings ...)
  2020-01-02 16:09 ` [PATCH 8/9] can: gs_usb: gs_usb_probe(): use descriptors of current altsetting Marc Kleine-Budde
@ 2020-01-02 16:09 ` Marc Kleine-Budde
  2020-01-03  0:41 ` pull-request: can 2020-01-02 David Miller
  9 siblings, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2020-01-02 16:09 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Florian Faber, linux-stable, Marc Kleine-Budde

From: Florian Faber <faber@faberman.de>

Under load, the RX side of the mscan driver can get stuck while TX still
works. Restarting the interface locks up the system. This behaviour
could be reproduced reliably on a MPC5121e based system.

The patch fixes the return value of the NAPI polling function (should be
the number of processed packets, not constant 1) and the condition under
which IRQs are enabled again after polling is finished.

With this patch, no more lockups were observed over a test period of ten
days.

Fixes: afa17a500a36 ("net/can: add driver for mscan family & mpc52xx_mscan")
Signed-off-by: Florian Faber <faber@faberman.de>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/mscan/mscan.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/net/can/mscan/mscan.c b/drivers/net/can/mscan/mscan.c
index 8caf7af0dee2..99101d7027a8 100644
--- a/drivers/net/can/mscan/mscan.c
+++ b/drivers/net/can/mscan/mscan.c
@@ -381,13 +381,12 @@ static int mscan_rx_poll(struct napi_struct *napi, int quota)
 	struct net_device *dev = napi->dev;
 	struct mscan_regs __iomem *regs = priv->reg_base;
 	struct net_device_stats *stats = &dev->stats;
-	int npackets = 0;
-	int ret = 1;
+	int work_done = 0;
 	struct sk_buff *skb;
 	struct can_frame *frame;
 	u8 canrflg;
 
-	while (npackets < quota) {
+	while (work_done < quota) {
 		canrflg = in_8(&regs->canrflg);
 		if (!(canrflg & (MSCAN_RXF | MSCAN_ERR_IF)))
 			break;
@@ -408,18 +407,18 @@ static int mscan_rx_poll(struct napi_struct *napi, int quota)
 
 		stats->rx_packets++;
 		stats->rx_bytes += frame->can_dlc;
-		npackets++;
+		work_done++;
 		netif_receive_skb(skb);
 	}
 
-	if (!(in_8(&regs->canrflg) & (MSCAN_RXF | MSCAN_ERR_IF))) {
-		napi_complete(&priv->napi);
-		clear_bit(F_RX_PROGRESS, &priv->flags);
-		if (priv->can.state < CAN_STATE_BUS_OFF)
-			out_8(&regs->canrier, priv->shadow_canrier);
-		ret = 0;
+	if (work_done < quota) {
+		if (likely(napi_complete_done(&priv->napi, work_done))) {
+			clear_bit(F_RX_PROGRESS, &priv->flags);
+			if (priv->can.state < CAN_STATE_BUS_OFF)
+				out_8(&regs->canrier, priv->shadow_canrier);
+		}
 	}
-	return ret;
+	return work_done;
 }
 
 static irqreturn_t mscan_isr(int irq, void *dev_id)
-- 
2.24.1

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

* Re: pull-request: can 2020-01-02
  2020-01-02 16:09 pull-request: can 2020-01-02 Marc Kleine-Budde
                   ` (8 preceding siblings ...)
  2020-01-02 16:09 ` [PATCH 9/9] can: mscan: mscan_rx_poll(): fix rx path lockup when returning from polling to irq mode Marc Kleine-Budde
@ 2020-01-03  0:41 ` David Miller
  9 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2020-01-03  0:41 UTC (permalink / raw)
  To: mkl; +Cc: netdev, linux-can, kernel

From: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Thu,  2 Jan 2020 17:09:25 +0100

> this is a pull request of 9 patches for net/master.
> 
> The first 5 patches target all the tcan4x5x driver. The first 3 patches
> of them are by Dan Murphy and Sean Nyekjaer and improve the device
> initialization (power on, reset and get device out of standby before
> register access). The next patch is by Dan Murphy and disables the INH
> pin device-state if the GPIO is unavailable. The last patch for the
> tcan4x5x driver is by Gustavo A. R. Silva and fixes an inconsistent
> PTR_ERR check in the tcan4x5x_parse_config() function.
> 
> The next patch is by Oliver Hartkopp and targets the generic CAN device
> infrastructure. It ensures that an initialized headroom in outgoing CAN
> sk_buffs (e.g. if injected by AF_PACKET).
> 
> The last 2 patches are by Johan Hovold and fix the kvaser_usb and gs_usb
> drivers by always using the current alternate setting not blindly the
> first one.

Pulled, thanks Marc.

 

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

end of thread, other threads:[~2020-01-03  0:41 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-02 16:09 pull-request: can 2020-01-02 Marc Kleine-Budde
2020-01-02 16:09 ` [PATCH 1/9] can: tcan4x5x: tcan4x5x_can_probe(): get the device out of standby before register access Marc Kleine-Budde
2020-01-02 16:09 ` [PATCH 2/9] can: tcan4x5x: tcan4x5x_can_probe(): turn on the power before parsing the config Marc Kleine-Budde
2020-01-02 16:09 ` [PATCH 3/9] can: tcan4x5x: tcan4x5x_parse_config(): reset device before register access Marc Kleine-Budde
2020-01-02 16:09 ` [PATCH 4/9] can: tcan4x5x: tcan4x5x_parse_config(): Disable the INH pin device-state GPIO is unavailable Marc Kleine-Budde
2020-01-02 16:09 ` [PATCH 5/9] can: tcan4x5x: tcan4x5x_parse_config(): fix inconsistent IS_ERR and PTR_ERR Marc Kleine-Budde
2020-01-02 16:09 ` [PATCH 6/9] can: can_dropped_invalid_skb(): ensure an initialized headroom in outgoing CAN sk_buffs Marc Kleine-Budde
2020-01-02 16:09 ` [PATCH 7/9] can: kvaser_usb: fix interface sanity check Marc Kleine-Budde
2020-01-02 16:09 ` [PATCH 8/9] can: gs_usb: gs_usb_probe(): use descriptors of current altsetting Marc Kleine-Budde
2020-01-02 16:09 ` [PATCH 9/9] can: mscan: mscan_rx_poll(): fix rx path lockup when returning from polling to irq mode Marc Kleine-Budde
2020-01-03  0:41 ` pull-request: can 2020-01-02 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.