Skip to content

Commit

Permalink
mi: fix the return error code.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jinliang Wang <[email protected]>
  • Loading branch information
drakedog2008 authored and igaw committed May 6, 2024
1 parent 41a448d commit 4382dc0
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions src/nvme/mi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4382dc0

Please sign in to comment.