qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

linux-user: Fix error handling in flatload.c target_pread()

The flatload.c target_pread() function is supposed to return
0 on success or negative host errnos; however it wasn't
checking lock_user() for failure or returning the errno from
the pread() call. Fix these problems (the first of which is
noted by Coverity).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>

authored by

Peter Maydell and committed by
Riku Voipio
e5a869ed f9757b1d

+6
+6
linux-user/flatload.c
··· 95 95 int ret; 96 96 97 97 buf = lock_user(VERIFY_WRITE, ptr, len, 0); 98 + if (!buf) { 99 + return -EFAULT; 100 + } 98 101 ret = pread(fd, buf, len, offset); 102 + if (ret < 0) { 103 + ret = -errno; 104 + } 99 105 unlock_user(buf, ptr, len); 100 106 return ret; 101 107 }