From: Niklas Neronin <niklas.neronin@linux.intel.com>
To: mathias.nyman@linux.intel.com
Cc: linux-usb@vger.kernel.org,
Niklas Neronin <niklas.neronin@linux.intel.com>
Subject: [PATCH 08/11] usb: xhci: remove error handling from xhci_add_interrupter()
Date: Fri, 11 Apr 2025 12:11:52 +0300 [thread overview]
Message-ID: <20250411091155.3386971-9-niklas.neronin@linux.intel.com> (raw)
In-Reply-To: <20250411091155.3386971-1-niklas.neronin@linux.intel.com>
Remove redundant error handling from xhci_add_interrupter() instead of
trying to accommodate them in future changes.
======== Reasoning for the removal ========
Function xhci_add_interrupter() is invoked in two scenarios:
Primary Interrupter Setup (ID 0):
The maximum number of interrupters is always greater than zero, and the
primary interrupter is always allocated as part of the driver's
initialization process. In case of failure, the xHCI driver errors and
exits.
Secondary Interrupter Creation (ID >= 1):
The interrupter is pre-allocated, and an empty slot is identified before
invoking xhci_add_interrupter().
In both cases, the existing error handling within xhci_add_interrupter() is
redundant and unnecessary.
Upcoming Changes:
In the subsequent commit, interrupter initialization will move from
xhci_mem_init() to xhci_init(). This change is necessary to facilitate
the ability to restart the xHCI driver without re-allocating memory.
As a result, the allocated interrupter must be stored in the interrupters
pointer array before initialization.
Consequently, xhci_create_secondary_interrupter() would need to handle
pointer removal for allocated 'interrupters' array upon failure, although
xhci_add_interrupter() will never fail.
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
drivers/usb/host/xhci-mem.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 1b05704a1852..ce632a288c41 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2282,24 +2282,13 @@ xhci_alloc_interrupter(struct xhci_hcd *xhci, unsigned int segs, gfp_t flags)
return ir;
}
-static int
+static void
xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir,
unsigned int intr_num)
{
u64 erst_base;
u32 erst_size;
- if (intr_num >= xhci->max_interrupters) {
- xhci_warn(xhci, "Can't add interrupter %d, max interrupters %d\n",
- intr_num, xhci->max_interrupters);
- return -EINVAL;
- }
-
- if (xhci->interrupters[intr_num]) {
- xhci_warn(xhci, "Interrupter %d\n already set up", intr_num);
- return -EINVAL;
- }
-
xhci->interrupters[intr_num] = ir;
ir->intr_num = intr_num;
ir->ir_set = &xhci->run_regs->ir_set[intr_num];
@@ -2320,8 +2309,6 @@ xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir,
/* Set the event ring dequeue address of this interrupter */
xhci_set_hc_event_deq(xhci, ir);
-
- return 0;
}
struct xhci_interrupter *
@@ -2331,7 +2318,7 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs,
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
struct xhci_interrupter *ir;
unsigned int i;
- int err = -ENOSPC;
+ int err;
if (!xhci->interrupters || xhci->max_interrupters <= 1)
return NULL;
@@ -2345,14 +2332,14 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs,
/* Find available secondary interrupter, interrupter 0 is reserved for primary */
for (i = 1; i < xhci->max_interrupters; i++) {
if (xhci->interrupters[i] == NULL) {
- err = xhci_add_interrupter(xhci, ir, i);
+ xhci_add_interrupter(xhci, ir, i);
break;
}
}
spin_unlock_irq(&xhci->lock);
- if (err) {
+ if (i == xhci->max_interrupters) {
xhci_warn(xhci, "Failed to add secondary interrupter, max interrupters %d\n",
xhci->max_interrupters);
xhci_free_interrupter(xhci, ir);
@@ -2452,8 +2439,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
if (!ir)
goto fail;
- if (xhci_add_interrupter(xhci, ir, 0))
- goto fail;
+ xhci_add_interrupter(xhci, ir, 0);
ir->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX;
--
2.47.2
next prev parent reply other threads:[~2025-04-11 9:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 9:11 [PATCH 00/11] usb: xhci: decouple allocation and initialization Niklas Neronin
2025-04-11 9:11 ` [PATCH 01/11] usb: xhci: relocate pre-allocation initialization Niklas Neronin
2025-04-11 9:11 ` [PATCH 02/11] usb: xhci: move device slot enabling register write Niklas Neronin
2025-04-11 9:11 ` [PATCH 03/11] usb: xhci: move command ring pointer write Niklas Neronin
2025-04-11 9:11 ` [PATCH 04/11] usb: xhci: refactor xhci_set_cmd_ring_deq() Niklas Neronin
2025-04-11 9:11 ` [PATCH 05/11] usb: xhci: move DCBAA pointer write Niklas Neronin
2025-04-11 15:05 ` Sergey Shtylyov
2025-04-11 9:11 ` [PATCH 06/11] usb: xhci: move doorbell array pointer assignment Niklas Neronin
2025-04-11 9:11 ` [PATCH 07/11] usb: xhci: move enabling of USB 3 device notifications Niklas Neronin
2025-04-11 9:11 ` Niklas Neronin [this message]
2025-04-11 9:11 ` [PATCH 09/11] usb: xhci: move initialization of the primary interrupter Niklas Neronin
2025-04-11 9:11 ` [PATCH 10/11] usb: xhci: add individual allocation checks in xhci_mem_init() Niklas Neronin
2025-04-11 9:11 ` [PATCH 11/11] usb: xhci: cleanup xhci_mem_init() Niklas Neronin
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=20250411091155.3386971-9-niklas.neronin@linux.intel.com \
--to=niklas.neronin@linux.intel.com \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.