From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
Jianglei Nie <niejianglei2021@163.com>,
Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 1/6] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info()
Date: Wed, 21 Sep 2022 15:34:45 +0300 [thread overview]
Message-ID: <20220921123450.671459-2-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20220921123450.671459-1-mathias.nyman@linux.intel.com>
From: Jianglei Nie <niejianglei2021@163.com>
xhci_alloc_stream_info() allocates stream context array for stream_info
->stream_ctx_array with xhci_alloc_stream_ctx(). When some error occurs,
stream_info->stream_ctx_array is not released, which will lead to a
memory leak.
We can fix it by releasing the stream_info->stream_ctx_array with
xhci_free_stream_ctx() on the error path to avoid the potential memory
leak.
Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci-mem.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 8c19e151a945..9e56aa28efcd 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -641,7 +641,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
num_stream_ctxs, &stream_info->ctx_array_dma,
mem_flags);
if (!stream_info->stream_ctx_array)
- goto cleanup_ctx;
+ goto cleanup_ring_array;
memset(stream_info->stream_ctx_array, 0,
sizeof(struct xhci_stream_ctx)*num_stream_ctxs);
@@ -702,6 +702,11 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
}
xhci_free_command(xhci, stream_info->free_streams_command);
cleanup_ctx:
+ xhci_free_stream_ctx(xhci,
+ stream_info->num_stream_ctxs,
+ stream_info->stream_ctx_array,
+ stream_info->ctx_array_dma);
+cleanup_ring_array:
kfree(stream_info->stream_rings);
cleanup_info:
kfree(stream_info);
--
2.25.1
next prev parent reply other threads:[~2022-09-21 12:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-21 12:34 [PATCH 0/6] xhci features and fixes for usb-next Mathias Nyman
2022-09-21 12:34 ` Mathias Nyman [this message]
2022-09-21 12:34 ` [PATCH 2/6] xhci: dbc: Fix memory leak in xhci_alloc_dbc() Mathias Nyman
2022-09-21 12:34 ` [PATCH 3/6] xhci: Don't show warning for reinit on known broken suspend Mathias Nyman
2022-09-21 12:34 ` [PATCH 4/6] xhci: show fault reason for a failed enable slot command Mathias Nyman
2022-09-21 12:34 ` [PATCH 5/6] xhci: remove unused command member from struct xhci_hcd struct Mathias Nyman
2022-09-21 12:34 ` [PATCH 6/6] xhci: remove unused lpm_failed_dev member from struct xhci_hcd Mathias Nyman
2022-09-22 12:08 ` [PATCH 0/6] xhci features and fixes for usb-next Greg KH
2022-09-22 12:43 ` Mathias Nyman
2022-09-22 12:52 ` Greg KH
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=20220921123450.671459-2-mathias.nyman@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=niejianglei2021@163.com \
/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