nvme: handle positive error codes in nuse_show()
PATCH 1/1 nvme: handle positive error codes in nuse_show()
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.
---
We could also print the string from nvme_get_error_status_str(), but I don't think that's a good idea.
drivers/nvme/host/sysfs.c +3 -1
@@ -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); }
Signature · 1 line
2.43.7
Looks good:
Quoted 4 lines · 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.
Quoted 8 lines
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.