From 260316209d0c3b781d1ae483372958434da70689 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 9 May 2025 22:13:09 -0400 Subject: kernel: ahci: Improve HBA port scan logic Signed-off-by: Ian Moffett --- sys/dev/ic/ahci.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sys/dev/ic/ahci.c b/sys/dev/ic/ahci.c index c0c6fec..4500a29 100644 --- a/sys/dev/ic/ahci.c +++ b/sys/dev/ic/ahci.c @@ -273,7 +273,7 @@ static int ahci_hba_scan(struct ahci_hba *hba) { struct hba_memspace *abar = hba->io; - uint32_t pi, i = 0; + uint32_t pi; size_t len; len = hba->nports * sizeof(struct hba_device); @@ -284,13 +284,10 @@ ahci_hba_scan(struct ahci_hba *hba) memset(devs, 0, len); pi = mmio_read32(&abar->pi); - while (pi != 0) { - if ((pi & 1) != 0) { + for (int i = 0; i < sizeof(pi) * 8; ++i) { + if (ISSET(pi, BIT(i))) { ahci_init_port(hba, i); } - - ++i; - pi >>= 1; } return 0; -- cgit v1.2.3