diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-18 19:25:04 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-18 19:49:46 -0400 |
commit | ea986eaff90c2d5b1b243b28c8891db2dd5039de (patch) | |
tree | c2e8b051e5e4ee7834546a53de15278bdb5ec610 /src/sys | |
parent | 341c360a90a6698a11ffada0feb1527eb1b46a53 (diff) |
kern: ahci: Use the stack for ports before copy
When attempting to initialize ports, have the caller use a stack
variable for the port descriptor to not stress the heap. If the port is
valid, ahci_init_port() will make a heap copy.
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/io/ic/ahci.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/sys/io/ic/ahci.c b/src/sys/io/ic/ahci.c index 383e531..f4b38d2 100644 --- a/src/sys/io/ic/ahci.c +++ b/src/sys/io/ic/ahci.c @@ -665,6 +665,7 @@ ahci_init_port(struct ahci_hba *hba, struct ahci_port *port) const uint16_t BSIZE = 512; volatile struct hba_port *regs; struct ahci_cmd_hdr *cmdlist; + struct ahci_port *port_cpy; uint32_t cmd, lo, hi; size_t clen; paddr_t pa; @@ -718,8 +719,14 @@ ahci_init_port(struct ahci_hba *hba, struct ahci_port *port) return error; } - TAILQ_INSERT_TAIL(&portlist, port, link); - ahci_identify(hba, port); + port_cpy = kalloc(sizeof(*port_cpy)); + if (port_cpy == NULL) { + return -ENOMEM; + } + + memcpy(port_cpy, port, sizeof(*port_cpy)); + TAILQ_INSERT_TAIL(&portlist, port_cpy, link); + ahci_identify(hba, port_cpy); return 0; } @@ -730,7 +737,7 @@ static int ahci_init_ports(struct ahci_hba *hba) { volatile struct hba_memspace *io = hba->io; - struct ahci_port *port; + struct ahci_port port; uint32_t pi, nbits; int error; @@ -743,20 +750,13 @@ ahci_init_ports(struct ahci_hba *hba) /* Allocate a new port descriptor */ dtrace("port %d implemented\n", i); - port = kalloc(sizeof(*port)); - if (port == NULL) { - dtrace("failed to allocate port\n"); - continue; - } - - port->io = &io->ports[i]; - port->portno = i; - port->parent = hba; + port.io = &io->ports[i]; + port.portno = i; + port.parent = hba; /* Initialize the port */ - error = ahci_init_port(hba, port); + error = ahci_init_port(hba, &port); if (error < 0) { - ahci_port_detach(port); dtrace("port init failed (error=%d)\n", error); continue; } |