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);