mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] nvmet-file: fix nvmet_file_flush() always returning an error
@ 2019-07-15 22:17 Logan Gunthorpe
  2019-07-16  1:13 ` Sagi Grimberg
  2019-07-17 18:35 ` Chaitanya Kulkarni
  0 siblings, 2 replies; 3+ messages in thread
From: Logan Gunthorpe @ 2019-07-15 22:17 UTC (permalink / raw)
  To: linux-nvme, linux-kernel
  Cc: Christoph Hellwig, Sagi Grimberg, Logan Gunthorpe, Chaitanya Kulkarni

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.

Fixes: c6aa3542e010 ("nvmet: add error log support for file backend")
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Cc: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 7734a6acff85..e1f03cfc6675 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -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;
-- 
2.20.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] nvmet-file: fix nvmet_file_flush() always returning an error
  2019-07-15 22:17 [PATCH v2] nvmet-file: fix nvmet_file_flush() always returning an error Logan Gunthorpe
@ 2019-07-16  1:13 ` Sagi Grimberg
  2019-07-17 18:35 ` Chaitanya Kulkarni
  1 sibling, 0 replies; 3+ messages in thread
From: Sagi Grimberg @ 2019-07-16  1:13 UTC (permalink / raw)
  To: Logan Gunthorpe, linux-nvme, linux-kernel
  Cc: Christoph Hellwig, Chaitanya Kulkarni

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] nvmet-file: fix nvmet_file_flush() always returning an error
  2019-07-15 22:17 [PATCH v2] nvmet-file: fix nvmet_file_flush() always returning an error Logan Gunthorpe
  2019-07-16  1:13 ` Sagi Grimberg
@ 2019-07-17 18:35 ` Chaitanya Kulkarni
  1 sibling, 0 replies; 3+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-17 18:35 UTC (permalink / raw)
  To: Logan Gunthorpe, linux-nvme, linux-kernel
  Cc: Christoph Hellwig, Sagi Grimberg

On 07/15/2019 03:17 PM, Logan Gunthorpe wrote:
> 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.
>
> Fixes: c6aa3542e010 ("nvmet: add error log support for file backend")
> Signed-off-by: Logan Gunthorpe<logang@deltatee.com>
> Cc: Chaitanya Kulkarni<chaitanya.kulkarni@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.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-17 18:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-15 22:17 [PATCH v2] nvmet-file: fix nvmet_file_flush() always returning an error Logan Gunthorpe
2019-07-16  1:13 ` Sagi Grimberg
2019-07-17 18:35 ` Chaitanya Kulkarni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®