* [PATCH] usb: xhci: Use common error handling code in two functions
@ 2026-06-10 12:20 Markus Elfring
0 siblings, 0 replies; only message in thread
From: Markus Elfring @ 2026-06-10 12:20 UTC (permalink / raw)
To: linux-usb, Greg Kroah-Hartman, Mathias Nyman
Cc: LKML, kernel-janitors, Felix Gu, Johan Hovold, Niklas Neronin
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-06-10 12:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-10 12:20 [PATCH] usb: xhci: Use common error handling code in two functions Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox