Bcc:
Subject: Re: [PATCH v2] can: mcba_usb: Fix memory leak when cancelling urb Reply-To:
In-Reply-To: <CACtPs=FB_=JMEymLHE0_ko4ZF5zj9NBCHkRC7O3tj6pkSp3oiA@mail.gmail.com>
Quoted 38 lines · Minh Bùi Quang
Quoted 31 lines · Bui Quang Minh
Quoted 14 lines · Oliver Neukum
Am Montag, den 11.01.2021, 10:49 +0000 schrieb Bui Quang Minh:
Quoted 13 lines
In
mcba_usb_read_bulk_callback(), when we don't resubmit or fails to resubmit the urb, we need to deallocate the transfer buffer that is allocated inmcba_usb_start().Reported-by [email protected]Signed-off-by Bui Quang Minh <[email protected]>---
v1: add memory leak fix when not resubmitting urb
v2: add memory leak fix when failing to resubmit urbdrivers/net/can/usb/mcba_usb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)Quoted 14 lines
drivers/net/can/usb/mcba_usb.c static void mcba_usb_read_bulk_callback(struct urb *urb) · line 590
Quoted 12 lines
drivers/net/can/usb/mcba_usb.c +2
-0@@ -584,6 +584,8 @@ static void mcba_usb_read_bulk_callback(struct urb *urb)case -EPIPE :case -EPROTO :case -ESHUTDOWN : +usb_free_coherent (urb->dev, urb->transfer_buffer_length, + urb->transfer_buffer, urb->transfer_dma);return ;Can you call
usb_free_coherent()in what can be hard IRQ context?Quoted 5 lines
You are right, I digged in the code and saw some comments that on some architectures,
usb_free_coherent()cannot be called in hard IRQ context. I see theusb_free_coherent()is called inwrite_bulk_callbacktoo. I will send a patch that usesusb_anchorto keep track of these urbs and cleanup the transfer buffer later indisconnect().
Quoted 12 lines
Hi, I have sent a version 3 patch. However, I found out that
usb_free_coherent()is ok in this situation. Inusb_free_coherent(), if the buffer is allocated viadma_alloc_coherent()inusb_alloc_coherent(),dma_free_coherent()is called. Indma_free_coherent(),ops->free()may be called in some cases which may contains calls tovunmap()that is not permitted in interrupt context. However, inusb_alloc_coherent(), buffer can be allocated from dma pool if the size is less
than 2048 and the buffer size inmcba_usbis obviously less than 2048. As a result,usb_free_coherent()will at most fall in the path that callsdma_pool_free(), which is
safe. Am I right?
Hi, I'm CC'ing CAN network driver maintainers so we can discuss the patch properly.
Thanks,
Quang Minh.