nvme: factor out a nvme_validate_passthru_nsid helper
Add a helper nvme_validate_passthru_nsid() to validate the nsid that removes the nsid validation and error message print code from nvme_user_cmd() and nvme_user_cmd64(). Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
parent
d399742cd0
commit
e7d4b5493a
1 changed files with 16 additions and 10 deletions
|
@ -177,6 +177,20 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
|
||||||
metadata, meta_len, lower_32_bits(io.slba), NULL, 0);
|
metadata, meta_len, lower_32_bits(io.slba), NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool nvme_validate_passthru_nsid(struct nvme_ctrl *ctrl,
|
||||||
|
struct nvme_ns *ns, __u32 nsid)
|
||||||
|
{
|
||||||
|
if (ns && nsid != ns->head->ns_id) {
|
||||||
|
dev_err(ctrl->device,
|
||||||
|
"%s: nsid (%u) in cmd does not match nsid (%u)"
|
||||||
|
"of namespace\n",
|
||||||
|
current->comm, nsid, ns->head->ns_id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
|
static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
|
||||||
struct nvme_passthru_cmd __user *ucmd)
|
struct nvme_passthru_cmd __user *ucmd)
|
||||||
{
|
{
|
||||||
|
@ -192,12 +206,8 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (cmd.flags)
|
if (cmd.flags)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (ns && cmd.nsid != ns->head->ns_id) {
|
if (!nvme_validate_passthru_nsid(ctrl, ns, cmd.nsid))
|
||||||
dev_err(ctrl->device,
|
|
||||||
"%s: nsid (%u) in cmd does not match nsid (%u) of namespace\n",
|
|
||||||
current->comm, cmd.nsid, ns->head->ns_id);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
memset(&c, 0, sizeof(c));
|
memset(&c, 0, sizeof(c));
|
||||||
c.common.opcode = cmd.opcode;
|
c.common.opcode = cmd.opcode;
|
||||||
|
@ -242,12 +252,8 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (cmd.flags)
|
if (cmd.flags)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (ns && cmd.nsid != ns->head->ns_id) {
|
if (!nvme_validate_passthru_nsid(ctrl, ns, cmd.nsid))
|
||||||
dev_err(ctrl->device,
|
|
||||||
"%s: nsid (%u) in cmd does not match nsid (%u) of namespace\n",
|
|
||||||
current->comm, cmd.nsid, ns->head->ns_id);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
memset(&c, 0, sizeof(c));
|
memset(&c, 0, sizeof(c));
|
||||||
c.common.opcode = cmd.opcode;
|
c.common.opcode = cmd.opcode;
|
||||||
|
|
Loading…
Add table
Reference in a new issue