From: "David Wang" <00107082@163.com>
To: "Oliver Neukum" <oneukum@suse.com>
Cc: mathias.nyman@intel.com, gregkh@linuxfoundation.org,
stern@rowland.harvard.edu, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] USB: core: add a memory pool to urb for host-controller private data
Date: Wed, 14 May 2025 19:51:36 +0800 (CST) [thread overview]
Message-ID: <484fe5f7.9d28.196cea2c6db.Coremail.00107082@163.com> (raw)
In-Reply-To: <51fe78fb-5d73-458f-b3d1-fc84cd6c5869@suse.com>
At 2025-05-14 19:23:02, "Oliver Neukum" <oneukum@suse.com> wrote:
>
>
>On 13.05.25 13:38, David Wang wrote:
>> ---
>
>Hi,
>
>still an issue after a second review.
>I should have noticed earlier.
>
>> --- a/drivers/usb/core/urb.c
>> +++ b/drivers/usb/core/urb.c
>> @@ -23,6 +23,7 @@ static void urb_destroy(struct kref *kref)
>>
>> if (urb->transfer_flags & URB_FREE_BUFFER)
>> kfree(urb->transfer_buffer);
>> + kfree(urb->hcpriv_mempool);
>
>What if somebody uses usb_init_urb()?
I am not quite sure about the concern here, do you mean somebody create a urb,
and then usb_init_urb() here, and never use urb_destroy to release it?
That would cause memory leak if urb_destroy is not called......But is this really possible?.
>
>> kfree(urb);
>> }
>> @@ -1037,3 +1038,25 @@ int usb_anchor_empty(struct usb_anchor *anchor)
>>
>> EXPORT_SYMBOL_GPL(usb_anchor_empty);
>>
>> +/**
>> + * urb_hcpriv_mempool_zalloc - alloc memory from mempool for hcpriv
>> + * @urb: pointer to URB being used
>> + * @size: memory size requested by current host controller
>> + * @mem_flags: the type of memory to allocate
>> + *
>> + * Return: NULL if out of memory, otherwise memory are zeroed
>> + */
>> +void *urb_hcpriv_mempool_zalloc(struct urb *urb, size_t size, gfp_t mem_flags)
>> +{
>> + if (urb->hcpriv_mempool_size < size) {
>> + kfree(urb->hcpriv_mempool);
>> + urb->hcpriv_mempool_size = size;
>> + urb->hcpriv_mempool = kmalloc(size, mem_flags);
>
>That could use kzalloc().
The memory would be set to 0 before returning to user, via memset, no matter whether the memory is
newly alloced or just reused. I think using kmalloc is ok here.
Thanks
David
>
> Regards
> Oliver
next prev parent reply other threads:[~2025-05-14 11:52 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-12 15:07 [RFC] USB: core/xhci: add a buffer in urb for host controller private data David Wang
2025-05-12 15:34 ` Alan Stern
2025-05-12 16:19 ` David Wang
2025-05-13 5:54 ` [PATCH 1/2] USB: core: add a memory pool to urb for host-controller " David Wang
2025-05-13 8:11 ` Oliver Neukum
2025-05-13 8:23 ` David Wang
2025-05-13 8:46 ` Oliver Neukum
2025-05-13 8:53 ` David Wang
2025-05-13 9:49 ` David Wang
2025-05-13 11:02 ` Oliver Neukum
2025-05-13 11:12 ` David Wang
2025-05-13 5:55 ` [PATCH 2/2] USB: xhci: use urb hcpriv mempool for " David Wang
2025-05-13 8:21 ` Oliver Neukum
2025-05-13 8:31 ` David Wang
2025-05-13 9:00 ` Oliver Neukum
2025-05-13 9:27 ` [RFC] USB: core/xhci: add a buffer in urb for host controller " Mathias Nyman
2025-05-13 9:41 ` David Wang
2025-05-13 11:38 ` [PATCH v2 1/2] USB: core: add a memory pool to urb for host-controller " David Wang
2025-05-13 14:25 ` Alan Stern
2025-05-13 14:41 ` David Wang
2025-05-13 15:37 ` Alan Stern
2025-05-13 16:35 ` David Wang
2025-05-13 18:21 ` Alan Stern
2025-05-13 18:48 ` David Wang
2025-05-13 19:46 ` Alan Stern
2025-05-14 11:27 ` Oliver Neukum
2025-05-14 6:44 ` David Wang
2025-05-14 7:29 ` Greg KH
2025-05-14 8:50 ` David Wang
2025-05-14 9:34 ` Oliver Neukum
2025-05-17 9:09 ` David Wang
2025-05-14 11:23 ` Oliver Neukum
2025-05-14 11:51 ` David Wang [this message]
2025-05-14 12:03 ` Oliver Neukum
2025-05-14 12:14 ` David Wang
2025-05-16 17:13 ` David Wang
2025-05-13 11:38 ` [PATCH v2 2/2] USB: xhci: use urb hcpriv mempool for " David Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=484fe5f7.9d28.196cea2c6db.Coremail.00107082@163.com \
--to=00107082@163.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=oneukum@suse.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox