Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme: handle positive error codes in nuse_show()
@ 2026-06-30 10:27 John Garry
  2026-07-01 10:45 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: John Garry @ 2026-06-30 10:27 UTC (permalink / raw)
  To: hch, kbusch, sagi, axboe; +Cc: linux-nvme, John Garry

Function __nvme_submit_sync_cmd() returns a positive error code for NVMe
errors. Otherwise, we get 0 for success or a negative error code for a
kernel error.

In nuse_show() -> ns_{head}_update_nuse() -> nvme_identify_ns() ->
nvme_submit_sync_cmd() -> __nvme_submit_sync_cmd(), we then may get a
positive error code returned.

Function nuse_show() - being a device attr handler - should return the
number of bytes written to the buffer or a negative error code.

Convert any positive NVMe error code to -EIO.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
We could also print the string from nvme_get_error_status_str(), but I
don't think that's a good idea.

diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
index 75b2d69b59578..abf8edaae371b 100644
--- a/drivers/nvme/host/sysfs.c
+++ b/drivers/nvme/host/sysfs.c
@@ -240,8 +240,10 @@ static ssize_t nuse_show(struct device *dev, struct device_attribute *attr,
 		ret = ns_head_update_nuse(head);
 	else
 		ret = ns_update_nuse(disk->private_data);
-	if (ret)
+	if (ret < 0)
 		return ret;
+	else if (ret > 0)
+		return -EIO;
 
 	return sysfs_emit(buf, "%llu\n", head->nuse);
 }
-- 
2.43.7



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

* Re: [PATCH] nvme: handle positive error codes in nuse_show()
  2026-06-30 10:27 [PATCH] nvme: handle positive error codes in nuse_show() John Garry
@ 2026-07-01 10:45 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2026-07-01 10:45 UTC (permalink / raw)
  To: John Garry; +Cc: kbusch, sagi, axboe, linux-nvme

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>



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

end of thread, other threads:[~2026-07-01 10:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30 10:27 [PATCH] nvme: handle positive error codes in nuse_show() John Garry
2026-07-01 10:45 ` Christoph Hellwig

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