Skip to content

Commit 8d67041

Browse files
committed
Merge tag 'linux-can-fixes-for-5.14-20210730' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2021-07-30 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. * tag 'linux-can-fixes-for-5.14-20210730' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: can: esd_usb2: fix memory leak can: ems_usb: fix memory leak can: usb_8dev: fix memory leak can: mcba_usb_start(): add missing urb->transfer_dma initialization can: hi311x: fix a signedness bug in hi3110_cmd() MAINTAINERS: add Yasushi SHOJI as reviewer for the Microchip CAN BUS Analyzer Tool driver ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 028a717 + 928150f commit 8d67041

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

MAINTAINERS

+6
Original file line numberDiff line numberDiff line change
@@ -11327,6 +11327,12 @@ W: https://linuxtv.org
1132711327
T: git git://linuxtv.org/media_tree.git
1132811328
F: drivers/media/radio/radio-maxiradio*
1132911329

11330+
MCAB MICROCHIP CAN BUS ANALYZER TOOL DRIVER
11331+
R: Yasushi SHOJI <[email protected]>
11332+
11333+
S: Maintained
11334+
F: drivers/net/can/usb/mcba_usb.c
11335+
1133011336
MCAN MMIO DEVICE DRIVER
1133111337
M: Chandrasekar Ramakrishnan <[email protected]>
1133211338

drivers/net/can/spi/hi311x.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static int hi3110_spi_trans(struct spi_device *spi, int len)
218218
return ret;
219219
}
220220

221-
static u8 hi3110_cmd(struct spi_device *spi, u8 command)
221+
static int hi3110_cmd(struct spi_device *spi, u8 command)
222222
{
223223
struct hi3110_priv *priv = spi_get_drvdata(spi);
224224

drivers/net/can/usb/ems_usb.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ struct ems_usb {
255255
unsigned int free_slots; /* remember number of available slots */
256256

257257
struct ems_cpc_msg active_params; /* active controller parameters */
258+
void *rxbuf[MAX_RX_URBS];
259+
dma_addr_t rxbuf_dma[MAX_RX_URBS];
258260
};
259261

260262
static void ems_usb_read_interrupt_callback(struct urb *urb)
@@ -587,6 +589,7 @@ static int ems_usb_start(struct ems_usb *dev)
587589
for (i = 0; i < MAX_RX_URBS; i++) {
588590
struct urb *urb = NULL;
589591
u8 *buf = NULL;
592+
dma_addr_t buf_dma;
590593

591594
/* create a URB, and a buffer for it */
592595
urb = usb_alloc_urb(0, GFP_KERNEL);
@@ -596,14 +599,16 @@ static int ems_usb_start(struct ems_usb *dev)
596599
}
597600

598601
buf = usb_alloc_coherent(dev->udev, RX_BUFFER_SIZE, GFP_KERNEL,
599-
&urb->transfer_dma);
602+
&buf_dma);
600603
if (!buf) {
601604
netdev_err(netdev, "No memory left for USB buffer\n");
602605
usb_free_urb(urb);
603606
err = -ENOMEM;
604607
break;
605608
}
606609

610+
urb->transfer_dma = buf_dma;
611+
607612
usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, 2),
608613
buf, RX_BUFFER_SIZE,
609614
ems_usb_read_bulk_callback, dev);
@@ -619,6 +624,9 @@ static int ems_usb_start(struct ems_usb *dev)
619624
break;
620625
}
621626

627+
dev->rxbuf[i] = buf;
628+
dev->rxbuf_dma[i] = buf_dma;
629+
622630
/* Drop reference, USB core will take care of freeing it */
623631
usb_free_urb(urb);
624632
}
@@ -684,6 +692,10 @@ static void unlink_all_urbs(struct ems_usb *dev)
684692

685693
usb_kill_anchored_urbs(&dev->rx_submitted);
686694

695+
for (i = 0; i < MAX_RX_URBS; ++i)
696+
usb_free_coherent(dev->udev, RX_BUFFER_SIZE,
697+
dev->rxbuf[i], dev->rxbuf_dma[i]);
698+
687699
usb_kill_anchored_urbs(&dev->tx_submitted);
688700
atomic_set(&dev->active_tx_urbs, 0);
689701

drivers/net/can/usb/esd_usb2.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ struct esd_usb2 {
195195
int net_count;
196196
u32 version;
197197
int rxinitdone;
198+
void *rxbuf[MAX_RX_URBS];
199+
dma_addr_t rxbuf_dma[MAX_RX_URBS];
198200
};
199201

200202
struct esd_usb2_net_priv {
@@ -545,6 +547,7 @@ static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev)
545547
for (i = 0; i < MAX_RX_URBS; i++) {
546548
struct urb *urb = NULL;
547549
u8 *buf = NULL;
550+
dma_addr_t buf_dma;
548551

549552
/* create a URB, and a buffer for it */
550553
urb = usb_alloc_urb(0, GFP_KERNEL);
@@ -554,14 +557,16 @@ static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev)
554557
}
555558

556559
buf = usb_alloc_coherent(dev->udev, RX_BUFFER_SIZE, GFP_KERNEL,
557-
&urb->transfer_dma);
560+
&buf_dma);
558561
if (!buf) {
559562
dev_warn(dev->udev->dev.parent,
560563
"No memory left for USB buffer\n");
561564
err = -ENOMEM;
562565
goto freeurb;
563566
}
564567

568+
urb->transfer_dma = buf_dma;
569+
565570
usb_fill_bulk_urb(urb, dev->udev,
566571
usb_rcvbulkpipe(dev->udev, 1),
567572
buf, RX_BUFFER_SIZE,
@@ -574,8 +579,12 @@ static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev)
574579
usb_unanchor_urb(urb);
575580
usb_free_coherent(dev->udev, RX_BUFFER_SIZE, buf,
576581
urb->transfer_dma);
582+
goto freeurb;
577583
}
578584

585+
dev->rxbuf[i] = buf;
586+
dev->rxbuf_dma[i] = buf_dma;
587+
579588
freeurb:
580589
/* Drop reference, USB core will take care of freeing it */
581590
usb_free_urb(urb);
@@ -663,6 +672,11 @@ static void unlink_all_urbs(struct esd_usb2 *dev)
663672
int i, j;
664673

665674
usb_kill_anchored_urbs(&dev->rx_submitted);
675+
676+
for (i = 0; i < MAX_RX_URBS; ++i)
677+
usb_free_coherent(dev->udev, RX_BUFFER_SIZE,
678+
dev->rxbuf[i], dev->rxbuf_dma[i]);
679+
666680
for (i = 0; i < dev->net_count; i++) {
667681
priv = dev->nets[i];
668682
if (priv) {

drivers/net/can/usb/mcba_usb.c

+2
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ static int mcba_usb_start(struct mcba_priv *priv)
653653
break;
654654
}
655655

656+
urb->transfer_dma = buf_dma;
657+
656658
usb_fill_bulk_urb(urb, priv->udev,
657659
usb_rcvbulkpipe(priv->udev, MCBA_USB_EP_IN),
658660
buf, MCBA_USB_RX_BUFF_SIZE,

drivers/net/can/usb/usb_8dev.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ struct usb_8dev_priv {
137137
u8 *cmd_msg_buffer;
138138

139139
struct mutex usb_8dev_cmd_lock;
140-
140+
void *rxbuf[MAX_RX_URBS];
141+
dma_addr_t rxbuf_dma[MAX_RX_URBS];
141142
};
142143

143144
/* tx frame */
@@ -733,6 +734,7 @@ static int usb_8dev_start(struct usb_8dev_priv *priv)
733734
for (i = 0; i < MAX_RX_URBS; i++) {
734735
struct urb *urb = NULL;
735736
u8 *buf;
737+
dma_addr_t buf_dma;
736738

737739
/* create a URB, and a buffer for it */
738740
urb = usb_alloc_urb(0, GFP_KERNEL);
@@ -742,14 +744,16 @@ static int usb_8dev_start(struct usb_8dev_priv *priv)
742744
}
743745

744746
buf = usb_alloc_coherent(priv->udev, RX_BUFFER_SIZE, GFP_KERNEL,
745-
&urb->transfer_dma);
747+
&buf_dma);
746748
if (!buf) {
747749
netdev_err(netdev, "No memory left for USB buffer\n");
748750
usb_free_urb(urb);
749751
err = -ENOMEM;
750752
break;
751753
}
752754

755+
urb->transfer_dma = buf_dma;
756+
753757
usb_fill_bulk_urb(urb, priv->udev,
754758
usb_rcvbulkpipe(priv->udev,
755759
USB_8DEV_ENDP_DATA_RX),
@@ -767,6 +771,9 @@ static int usb_8dev_start(struct usb_8dev_priv *priv)
767771
break;
768772
}
769773

774+
priv->rxbuf[i] = buf;
775+
priv->rxbuf_dma[i] = buf_dma;
776+
770777
/* Drop reference, USB core will take care of freeing it */
771778
usb_free_urb(urb);
772779
}
@@ -836,6 +843,10 @@ static void unlink_all_urbs(struct usb_8dev_priv *priv)
836843

837844
usb_kill_anchored_urbs(&priv->rx_submitted);
838845

846+
for (i = 0; i < MAX_RX_URBS; ++i)
847+
usb_free_coherent(priv->udev, RX_BUFFER_SIZE,
848+
priv->rxbuf[i], priv->rxbuf_dma[i]);
849+
839850
usb_kill_anchored_urbs(&priv->tx_submitted);
840851
atomic_set(&priv->active_tx_urbs, 0);
841852

0 commit comments

Comments
 (0)