nvmet-file: fix nvmet_file_flush() always returning an error
Subsystems (2)
PATCH v2 1/1 nvmet-file: fix nvmet_file_flush() always returning an error
Presently, nvmet_file_flush() always returns a call to errno_to_nvme_status() but that helper doesn't take into account the case when errno=0. So nvmet_file_flush() always returns an error code.
All other callers of errno_to_nvme_status() check for success before calling it.
To fix this, ensure errno_to_nvme_status() returns success if the errno is zero. This should prevent future mistakes like this from happening.
--- drivers/nvme/target/core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/nvme/target/core.c +3 -0
@@ -43,6 +43,9 @@ inline u16 errno_to_nvme_status(struct nvmet_req *req, int errno)u16 status;switch (errno) { +case 0 : + status =NVME_SC_SUCCESS ; +break ;case -ENOSPC : req->error_loc = offsetof(struct nvme_rw_command , length); status =NVME_SC_CAP_EXCEEDED |NVME_SC_DNR ;
Signature · 1 line
2.20.1
Quoted 7 lines · Logan Gunthorpe
Presently,
nvmet_file_flush()always returns a call toerrno_to_nvme_status()but that helper doesn't take into account the case when errno=0. Sonvmet_file_flush()always returns an error code.All other callers of
errno_to_nvme_status()check for success before calling it.
Quoted 7 lines
To fix this, ensure
errno_to_nvme_status()returns success if the errno is zero. This should prevent future mistakes like this from happening.Fixes c6aa3542e010 ("nvmet: add error log support for file backend")Signed-off-by Logan Gunthorpe<logang at deltatee.com>Cc Chaitanya Kulkarni<chaitanya.kulkarni at wdc.com>
Thanks for the fix Logan, errno_to_nvme_status() needs to be only called in the case of error. Clearly bad example of calling function withing function.
Looks good to me.