From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-07-30 07:05:34
Hello Jakub, hello David,
this is a pull request of 6 patches for net/master.
The first patch is by me and adds Yasushi SHOJI as a reviewer for the
Microchip CAN BUS Analyzer Tool driver.
Dan Carpenter's patch fixes a signedness bug in the hi311x driver.
Pavel Skripkin provides 4 patches, the first targets the mcba_usb
driver by adding the missing urb->transfer_dma initialization, which
was broken in a previous commit. The last 3 patches fix a memory leak
in the usb_8dev, ems_usb and esd_usb2 driver.
regards,
Marc
---
The following changes since commit fc16a5322ee6c30ea848818722eee5d352f8d127:
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf (2021-07-29 00:53:32 +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-5.14-20210730
for you to fetch changes up to 928150fad41ba16df7fcc9f7f945747d0f56cbb6:
can: esd_usb2: fix memory leak (2021-07-30 08:47:34 +0200)
----------------------------------------------------------------
linux-can-fixes-for-5.14-20210730
----------------------------------------------------------------
Dan Carpenter (1):
can: hi311x: fix a signedness bug in hi3110_cmd()
Marc Kleine-Budde (1):
MAINTAINERS: add Yasushi SHOJI as reviewer for the Microchip CAN BUS Analyzer Tool driver
Pavel Skripkin (4):
can: mcba_usb_start(): add missing urb->transfer_dma initialization
can: usb_8dev: fix memory leak
can: ems_usb: fix memory leak
can: esd_usb2: fix memory leak
MAINTAINERS | 6 ++++++
drivers/net/can/spi/hi311x.c | 2 +-
drivers/net/can/usb/ems_usb.c | 14 +++++++++++++-
drivers/net/can/usb/esd_usb2.c | 16 +++++++++++++++-
drivers/net/can/usb/mcba_usb.c | 2 ++
drivers/net/can/usb/usb_8dev.c | 15 +++++++++++++--
6 files changed, 50 insertions(+), 5 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-07-30 07:05:37
This patch adds Yasushi SHOJI as a reviewer for the Microchip CAN BUS
Analyzer Tool driver.
Link: https://lore.kernel.org/r/20210726111619.1023991-1-mkl@pengutronix.de
Acked-by: Yasushi SHOJI <yashi@spacecubics.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
MAINTAINERS | 6 ++++++
1 file changed, 6 insertions(+)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-07-30 07:05:39
From: Dan Carpenter <redacted>
The hi3110_cmd() is supposed to return zero on success and negative
error codes on failure, but it was accidentally declared as a u8 when
it needs to be an int type.
Fixes: 57e83fb9b746 ("can: hi311x: Add Holt HI-311x CAN driver")
Link: https://lore.kernel.org/r/20210729141246.GA1267@kili
Signed-off-by: Dan Carpenter <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/spi/hi311x.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-07-30 07:05:41
From: Pavel Skripkin <redacted>
In ems_usb_start() MAX_RX_URBS coherent buffers are allocated and
there is nothing, that frees them:
1) In callback function the urb is resubmitted and that's all
2) In disconnect function urbs are simply killed, but URB_FREE_BUFFER
is not set (see ems_usb_start) and this flag cannot be used with
coherent buffers.
So, all allocated buffers should be freed with usb_free_coherent()
explicitly.
Side note: This code looks like a copy-paste of other can drivers. The
same patch was applied to mcba_usb driver and it works nice with real
hardware. There is no change in functionality, only clean-up code for
coherent buffers.
Fixes: 702171adeed3 ("ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface")
Link: https://lore.kernel.org/r/59aa9fbc9a8cbf9af2bbd2f61a659c480b415800.1627404470.git.paskripkin@gmail.com
Cc: linux-stable <redacted>
Signed-off-by: Pavel Skripkin <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/ems_usb.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
@@ -255,6 +255,8 @@ struct ems_usb {unsignedintfree_slots;/* remember number of available slots */structems_cpc_msgactive_params;/* active controller parameters */+void*rxbuf[MAX_RX_URBS];+dma_addr_trxbuf_dma[MAX_RX_URBS];};staticvoidems_usb_read_interrupt_callback(structurb*urb)
@@ -587,6 +589,7 @@ static int ems_usb_start(struct ems_usb *dev)for(i=0;i<MAX_RX_URBS;i++){structurb*urb=NULL;u8*buf=NULL;+dma_addr_tbuf_dma;/* create a URB, and a buffer for it */urb=usb_alloc_urb(0,GFP_KERNEL);
@@ -596,7 +599,7 @@ static int ems_usb_start(struct ems_usb *dev)}buf=usb_alloc_coherent(dev->udev,RX_BUFFER_SIZE,GFP_KERNEL,-&urb->transfer_dma);+&buf_dma);if(!buf){netdev_err(netdev,"No memory left for USB buffer\n");usb_free_urb(urb);
@@ -604,6 +607,8 @@ static int ems_usb_start(struct ems_usb *dev)break;}+urb->transfer_dma=buf_dma;+usb_fill_bulk_urb(urb,dev->udev,usb_rcvbulkpipe(dev->udev,2),buf,RX_BUFFER_SIZE,ems_usb_read_bulk_callback,dev);
@@ -619,6 +624,9 @@ static int ems_usb_start(struct ems_usb *dev)break;}+dev->rxbuf[i]=buf;+dev->rxbuf_dma[i]=buf_dma;+/* Drop reference, USB core will take care of freeing it */usb_free_urb(urb);}
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-07-30 07:05:43
From: Pavel Skripkin <redacted>
In usb_8dev_start() MAX_RX_URBS coherent buffers are allocated and
there is nothing, that frees them:
1) In callback function the urb is resubmitted and that's all
2) In disconnect function urbs are simply killed, but URB_FREE_BUFFER
is not set (see usb_8dev_start) and this flag cannot be used with
coherent buffers.
So, all allocated buffers should be freed with usb_free_coherent()
explicitly.
Side note: This code looks like a copy-paste of other can drivers. The
same patch was applied to mcba_usb driver and it works nice with real
hardware. There is no change in functionality, only clean-up code for
coherent buffers.
Fixes: 0024d8ad1639 ("can: usb_8dev: Add support for USB2CAN interface from 8 devices")
Link: https://lore.kernel.org/r/d39b458cd425a1cf7f512f340224e6e9563b07bd.1627404470.git.paskripkin@gmail.com
Cc: linux-stable <redacted>
Signed-off-by: Pavel Skripkin <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/usb_8dev.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
@@ -733,6 +734,7 @@ static int usb_8dev_start(struct usb_8dev_priv *priv)for(i=0;i<MAX_RX_URBS;i++){structurb*urb=NULL;u8*buf;+dma_addr_tbuf_dma;/* create a URB, and a buffer for it */urb=usb_alloc_urb(0,GFP_KERNEL);
@@ -742,7 +744,7 @@ static int usb_8dev_start(struct usb_8dev_priv *priv)}buf=usb_alloc_coherent(priv->udev,RX_BUFFER_SIZE,GFP_KERNEL,-&urb->transfer_dma);+&buf_dma);if(!buf){netdev_err(netdev,"No memory left for USB buffer\n");usb_free_urb(urb);
@@ -750,6 +752,8 @@ static int usb_8dev_start(struct usb_8dev_priv *priv)break;}+urb->transfer_dma=buf_dma;+usb_fill_bulk_urb(urb,priv->udev,usb_rcvbulkpipe(priv->udev,USB_8DEV_ENDP_DATA_RX),
@@ -767,6 +771,9 @@ static int usb_8dev_start(struct usb_8dev_priv *priv)break;}+priv->rxbuf[i]=buf;+priv->rxbuf_dma[i]=buf_dma;+/* Drop reference, USB core will take care of freeing it */usb_free_urb(urb);}
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-07-30 07:05:46
From: Pavel Skripkin <redacted>
Yasushi reported, that his Microchip CAN Analyzer stopped working
since commit 91c02557174b ("can: mcba_usb: fix memory leak in
mcba_usb"). The problem was in missing urb->transfer_dma
initialization.
In my previous patch to this driver I refactored mcba_usb_start() code
to avoid leaking usb coherent buffers. To archive it, I passed local
stack variable to usb_alloc_coherent() and then saved it to private
array to correctly free all coherent buffers on ->close() call. But I
forgot to initialize urb->transfer_dma with variable passed to
usb_alloc_coherent().
All of this was causing device to not work, since dma addr 0 is not
valid and following log can be found on bug report page, which points
exactly to problem described above.
| DMAR: [DMA Write] Request device [00:14.0] PASID ffffffff fault addr 0 [fault reason 05] PTE Write access is not set
Fixes: 91c02557174b ("can: mcba_usb: fix memory leak in mcba_usb")
Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=990850
Link: https://lore.kernel.org/r/20210725103630.23864-1-paskripkin@gmail.com
Cc: linux-stable <redacted>
Reported-by: Yasushi SHOJI <redacted>
Signed-off-by: Pavel Skripkin <redacted>
Tested-by: Yasushi SHOJI <yashi@spacecubics.com>
[mkl: fixed typos in commit message - thanks Yasushi SHOJI]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/mcba_usb.c | 2 ++
1 file changed, 2 insertions(+)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-07-30 07:05:47
From: Pavel Skripkin <redacted>
In esd_usb2_setup_rx_urbs() MAX_RX_URBS coherent buffers are allocated
and there is nothing, that frees them:
1) In callback function the urb is resubmitted and that's all
2) In disconnect function urbs are simply killed, but URB_FREE_BUFFER
is not set (see esd_usb2_setup_rx_urbs) and this flag cannot be used
with coherent buffers.
So, all allocated buffers should be freed with usb_free_coherent()
explicitly.
Side note: This code looks like a copy-paste of other can drivers. The
same patch was applied to mcba_usb driver and it works nice with real
hardware. There is no change in functionality, only clean-up code for
coherent buffers.
Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device")
Link: https://lore.kernel.org/r/b31b096926dcb35998ad0271aac4b51770ca7cc8.1627404470.git.paskripkin@gmail.com
Cc: linux-stable <redacted>
Signed-off-by: Pavel Skripkin <redacted>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/esd_usb2.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
@@ -545,6 +547,7 @@ static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev)for(i=0;i<MAX_RX_URBS;i++){structurb*urb=NULL;u8*buf=NULL;+dma_addr_tbuf_dma;/* create a URB, and a buffer for it */urb=usb_alloc_urb(0,GFP_KERNEL);
@@ -554,7 +557,7 @@ static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev)}buf=usb_alloc_coherent(dev->udev,RX_BUFFER_SIZE,GFP_KERNEL,-&urb->transfer_dma);+&buf_dma);if(!buf){dev_warn(dev->udev->dev.parent,"No memory left for USB buffer\n");
@@ -562,6 +565,8 @@ static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev)gotofreeurb;}+urb->transfer_dma=buf_dma;+usb_fill_bulk_urb(urb,dev->udev,usb_rcvbulkpipe(dev->udev,1),buf,RX_BUFFER_SIZE,
@@ -574,8 +579,12 @@ static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev)usb_unanchor_urb(urb);usb_free_coherent(dev->udev,RX_BUFFER_SIZE,buf,urb->transfer_dma);+gotofreeurb;}+dev->rxbuf[i]=buf;+dev->rxbuf_dma[i]=buf_dma;+freeurb:/* Drop reference, USB core will take care of freeing it */usb_free_urb(urb);
From: Jakub Kicinski <kuba@kernel.org> Date: 2021-07-30 17:33:39
On Fri, 30 Jul 2021 09:05:20 +0200 Marc Kleine-Budde wrote:
The first patch is by me and adds Yasushi SHOJI as a reviewer for the
Microchip CAN BUS Analyzer Tool driver.
Dan Carpenter's patch fixes a signedness bug in the hi311x driver.
Pavel Skripkin provides 4 patches, the first targets the mcba_usb
driver by adding the missing urb->transfer_dma initialization, which
was broken in a previous commit. The last 3 patches fix a memory leak
in the usb_8dev, ems_usb and esd_usb2 driver.