* [PATCH] nvme: handle positive error codes in nuse_show()
@ 2026-06-30 10:27 John Garry
2026-07-01 10:45 ` Christoph Hellwig
2026-07-06 18:57 ` Keith Busch
0 siblings, 2 replies; 3+ 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] 3+ 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
2026-07-06 18:57 ` Keith Busch
1 sibling, 0 replies; 3+ 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] 3+ 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
@ 2026-07-06 18:57 ` Keith Busch
1 sibling, 0 replies; 3+ messages in thread
From: Keith Busch @ 2026-07-06 18:57 UTC (permalink / raw)
To: John Garry; +Cc: hch, sagi, axboe, linux-nvme
On Tue, Jun 30, 2026 at 10:27:17AM +0000, John Garry wrote:
> 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.
Thanks, applied to nvme-7.3.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-06 18:57 UTC | newest]
Thread overview: 3+ 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
2026-07-06 18:57 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox