From 4382dc00e4a61f0526836d0aa05299b1994d2083 Mon Sep 17 00:00:00 2001 From: Hao Jiang Date: Mon, 5 Dec 2022 16:48:35 -0800 Subject: [PATCH] mi: fix the return error code. When returning a system error code (i.e. rc < 0), the function should return -1 and set errno instead of returning the errno directly. It is very helpful for the client to handle the rc in an unified way. Signed-off-by: Hao Jiang Signed-off-by: Jinliang Wang --- src/nvme/mi.c | 57 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/src/nvme/mi.c b/src/nvme/mi.c index 84d51b0c..5c83e463 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -1003,8 +1003,10 @@ int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, struct nvme_mi_req req; int rc; - if (args->args_size < sizeof(*args)) - return -EINVAL; + if (args->args_size < sizeof(*args)) { + errno = EINVAL; + return -1; + } nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, nvme_admin_get_features); @@ -1042,8 +1044,10 @@ int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, struct nvme_mi_req req; int rc; - if (args->args_size < sizeof(*args)) - return -EINVAL; + if (args->args_size < sizeof(*args)) { + errno = EINVAL; + return -1; + } nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, nvme_admin_set_features); @@ -1140,8 +1144,10 @@ int nvme_mi_admin_ns_attach(nvme_mi_ctrl_t ctrl, struct nvme_mi_req req; int rc; - if (args->args_size < sizeof(*args)) - return -EINVAL; + if (args->args_size < sizeof(*args)) { + errno = EINVAL; + return -1; + } nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, nvme_admin_ns_attach); @@ -1173,17 +1179,20 @@ int nvme_mi_admin_fw_download(nvme_mi_ctrl_t ctrl, struct nvme_mi_req req; int rc; - if (args->args_size < sizeof(*args)) - return -EINVAL; - - if (args->data_len & 0x3) - return -EINVAL; + if (args->args_size < sizeof(*args)) { + errno = EINVAL; + return -1; + } - if (args->offset & 0x3) - return -EINVAL; + if ((args->data_len & 0x3) || (!args->data_len)) { + errno = EINVAL; + return -1; + } - if (!args->data_len) - return -EINVAL; + if (args->offset & 0x3) { + errno = EINVAL; + return -1; + } nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, nvme_admin_fw_download); @@ -1215,8 +1224,10 @@ int nvme_mi_admin_fw_commit(nvme_mi_ctrl_t ctrl, struct nvme_mi_req req; int rc; - if (args->args_size < sizeof(*args)) - return -EINVAL; + if (args->args_size < sizeof(*args)) { + errno = EINVAL; + return -1; + } nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, nvme_admin_fw_commit); @@ -1245,8 +1256,10 @@ int nvme_mi_admin_format_nvm(nvme_mi_ctrl_t ctrl, struct nvme_mi_req req; int rc; - if (args->args_size < sizeof(*args)) - return -EINVAL; + if (args->args_size < sizeof(*args)) { + errno = EINVAL; + return -1; + } nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, nvme_admin_format_nvm); @@ -1279,8 +1292,10 @@ int nvme_mi_admin_sanitize_nvm(nvme_mi_ctrl_t ctrl, struct nvme_mi_req req; int rc; - if (args->args_size < sizeof(*args)) - return -EINVAL; + if (args->args_size < sizeof(*args)) { + errno = EINVAL; + return -1; + } nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, nvme_admin_sanitize_nvm);