From: Markus Elfring <Markus.Elfring@web.de>
To: linux-usb@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org, Felix Gu <ustc.gu@gmail.com>,
Johan Hovold <johan@kernel.org>,
Niklas Neronin <niklas.neronin@linux.intel.com>
Subject: [PATCH] usb: xhci: Use common error handling code in two functions
Date: Wed, 10 Jun 2026 14:20:11 +0200 [thread overview]
Message-ID: <dd2f70a3-75ab-453b-a109-5632905d36ab@web.de> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 10 Jun 2026 14:10:24 +0200
Use additional labels so that a bit of exception handling can be better
reused at the end of two function implementations.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/usb/host/xhci-mem.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 997fe90f54e5..0e851d0c5bea 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -40,18 +40,15 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci,
return NULL;
seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma);
- if (!seg->trbs) {
- kfree(seg);
- return NULL;
- }
+ if (!seg->trbs)
+ goto free_seg;
if (max_packet) {
seg->bounce_buf = kzalloc_node(max_packet, flags,
dev_to_node(dev));
if (!seg->bounce_buf) {
dma_pool_free(xhci->segment_pool, seg->trbs, dma);
- kfree(seg);
- return NULL;
+ goto free_seg;
}
}
seg->num = num;
@@ -59,6 +56,10 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci,
seg->next = NULL;
return seg;
+
+free_seg:
+ kfree(seg);
+ return NULL;
}
static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg)
@@ -2309,19 +2310,21 @@ xhci_alloc_interrupter(struct xhci_hcd *xhci, unsigned int segs, gfp_t flags)
ir->event_ring = xhci_ring_alloc(xhci, segs, TYPE_EVENT, 0, flags);
if (!ir->event_ring) {
xhci_warn(xhci, "Failed to allocate interrupter event ring\n");
- kfree(ir);
- return NULL;
+ goto free_ir;
}
ret = xhci_alloc_erst(xhci, ir->event_ring, &ir->erst, flags);
if (ret) {
xhci_warn(xhci, "Failed to allocate interrupter erst\n");
xhci_ring_free(xhci, ir->event_ring);
- kfree(ir);
- return NULL;
+ goto free_ir;
}
return ir;
+
+free_ir:
+ kfree(ir);
+ return NULL;
}
void xhci_add_interrupter(struct xhci_hcd *xhci, unsigned int intr_num)
--
2.54.0
reply other threads:[~2026-06-10 12:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=dd2f70a3-75ab-453b-a109-5632905d36ab@web.de \
--to=markus.elfring@web.de \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
--cc=niklas.neronin@linux.intel.com \
--cc=ustc.gu@gmail.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