2
0
mirror of https://git.missingno.dev/kolibrios-nvme-driver/ synced 2024-12-22 05:48:47 +01:00

fix: running LOADDRV on NVMe driver more than once (#2)

Credits to @Burer for finding this bug, and @Doczom for providing a
solution.
This commit is contained in:
Abdur-Rahman Mansoor 2024-08-09 13:17:39 -04:00
parent 867a675261
commit aa0a75e715

View File

@ -526,6 +526,16 @@ proc detect_nvme
ret ret
.found_dev: .found_dev:
; skip PCIDEV.owner check if the PCI device pointer has already been
; allocated (without this check, more than 1 NVMe device cannot be
; registered)
mov eax, dword [p_nvme_devices]
test eax, eax
jnz @f
cmp dword [esi + PCIDEV.owner], 0
jnz .err
@@:
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): Detected NVMe device...\n", [esi + PCIDEV.bus], [esi + PCIDEV.devfn] PDEBUGF DBG_INFO, "PCI(%u.%u.%u): Detected NVMe device...\n", [esi + PCIDEV.bus], [esi + PCIDEV.devfn]
cmp dword [pcidevs_len], TOTAL_PCIDEVS cmp dword [pcidevs_len], TOTAL_PCIDEVS
jne @f jne @f
@ -538,8 +548,9 @@ proc detect_nvme
jnz @f ; was the pointer already allocated? jnz @f ; was the pointer already allocated?
invoke KernelAlloc, sizeof.pcidev * TOTAL_PCIDEVS invoke KernelAlloc, sizeof.pcidev * TOTAL_PCIDEVS
test eax, eax test eax, eax
jz .err_no_mem jz .err
mov dword [p_nvme_devices], eax mov dword [p_nvme_devices], eax
mov dword [esi + PCIDEV.owner], eax
@@: @@:
mov ecx, dword [pcidevs_len] mov ecx, dword [pcidevs_len]
@ -557,7 +568,7 @@ proc detect_nvme
jmp .next_dev jmp .next_dev
.err_no_mem: .err:
xor eax, eax xor eax, eax
ret ret
@ -1337,7 +1348,7 @@ endp
align 4 align 4
p_nvme_devices dd 0 p_nvme_devices dd 0
pcidevs_len dd 0 pcidevs_len dd 0
my_service db "NVMe",0 ;max 16 chars include zero my_service db "nvme",0 ;max 16 chars include zero
disk_functions: disk_functions:
dd disk_functions.end - disk_functions dd disk_functions.end - disk_functions
dd 0 ; no close function dd 0 ; no close function