fix(v4): a controller's drive slots are allocated once, never replaced (#178)

sk_v4_idle allocated a controller's slot array again whenever max_slots + 1
was more than it held -- the old array dropped, neither copied nor freed --
while the identity code holds pointers into it (g_offered, g_spare,
g_pending_real, g_real_drive, g_zuse_dev). Its two slot loops then ran to
max_slots whatever the array held.

sk_v4_slots_get() (kernel/src/v4/sk_v4_slots.c): allocated once, zeroed, at the
size first asked for; never replaced; the slots that may be used are those it
has. sk_v4_idle uses it, and its loops stop at the array's end.

kernel/tests/test_sk_v4_slots.c, kmalloc_aligned faked, seen to fail first
against the allocation as it was (4 failures: replaced when more were asked
for, 17 said usable where 9 existed, a held pointer left behind, an allocation
for 0); now 6 checks, 0 failures. Built for amd64, aarch64, riscv64; latent
today (max_slots does not grow), so the boots show no change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-12 18:05:57 +00:00
parent c778f6e0e7
commit 41f8648dd9
7 changed files with 103 additions and 12 deletions
@@ -0,0 +1,17 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* sk_v4_slots.h -- an xHCI controller's drive slots, for sk_v4_identity.c (#178): the array the
* attached drives live in, which the identity code holds pointers into (the offered stick, the
* spare, the real Zuse's, Zuse's own device). */
#ifndef STARKERNEL_V4_SK_V4_SLOTS_H
#define STARKERNEL_V4_SK_V4_SLOTS_H
#include <stddef.h>
#include <stdint.h>
/* The slot array in *slots, `elem` bytes a slot, *count of them: allocated (zeroed) when there is
* none, with `want` slots. Returns how many slots may be used (0: none could be allocated). */
uint32_t sk_v4_slots_get(void **slots, uint32_t *count, uint32_t want, size_t elem);
#endif