From 5f05daba4633d014c3d8dcebe2b48fd2c775c21c Mon Sep 17 00:00:00 2001 From: Alexander Gall Date: Mon, 4 May 2020 16:56:10 +0200 Subject: [PATCH] lib.hardware.pci.map_pci_memory: only wait if first call failed --- src/lib/hardware/pci.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/lib/hardware/pci.lua b/src/lib/hardware/pci.lua index a666a53959..4d73501912 100644 --- a/src/lib/hardware/pci.lua +++ b/src/lib/hardware/pci.lua @@ -176,17 +176,20 @@ function map_pci_memory (device, n, lock) assert(f:flock("ex, nb"), "failed to lock " .. filepath) end local st = assert(f:stat()) - local mem + local mem, err + mem, err = f:mmap(nil, st.size, "read, write", "shared", 0) -- mmap() returns EINVAL on Linux >= 4.5 if the device is still -- claimed by the kernel driver. We assume that -- unbind_device_from_linux() has already been called but it may take -- some time for the driver to release the device. - lib.waitfor2("mmap of "..filepath, - function () - mem, err = f:mmap(nil, st.size, "read, write", "shared", 0) - assert(not err or err.INVAL) - return mem - end, 5, 1000000) + if not mem then + lib.waitfor2("mmap of "..filepath, + function () + mem, err = f:mmap(nil, st.size, "read, write", "shared", 0) + assert(not err or err.INVAL) + return mem + end, 5, 1000000) + end return ffi.cast("uint32_t *", mem), f end