summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-08-09 00:00:25 -0400
committerIan Moffett <ian@osmora.org>2025-08-09 00:02:00 -0400
commit807bfd213ad37c3fabb90f9d9388e74934a1a85c (patch)
tree07a083d1091538d53735eb9036f7a7a0484b1c7a
parent3537d35f0dd3fad8a819578adeca75ed120b5966 (diff)
kernel: xhci: Ensure portno is valid for portsc
In the previous implementation, passing 0 or values higher than 'hc->maxports' would not be filtered and would result in underflow/overflow Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/dev/usb/xhci.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/sys/dev/usb/xhci.c b/sys/dev/usb/xhci.c
index 2206bb7..5a8da86 100644
--- a/sys/dev/usb/xhci.c
+++ b/sys/dev/usb/xhci.c
@@ -71,11 +71,16 @@ xhci_intr(void *sf)
static inline uint32_t *
xhci_get_portsc(struct xhci_hc *hc, uint8_t portno)
{
- if (portno > hc->maxports) {
- portno = hc->maxports;
+ if (portno >= hc->maxports) {
+ return NULL;
}
- return PTR_OFFSET(hc->opregs, 0x400 + (0x10 * (portno - 1)));
+ /* Zero based */
+ if (portno > 0) {
+ --portno;
+ }
+
+ return PTR_OFFSET(hc->opregs, 0x400 + (0x10 * portno));
}
static int
@@ -408,6 +413,9 @@ xhci_init_ports(struct xhci_hc *hc)
for (size_t i = 1; i < hc->maxports; ++i) {
portsc_p = xhci_get_portsc(hc, i);
+ if (portsc_p == NULL) {
+ continue;
+ }
portsc = mmio_read32(portsc_p);
/*