[RFC 2/3] nvme: Move nvme identify CS to separate function
Joel Granados
j.granados at samsung.com
Thu Oct 27 08:57:23 PDT 2022
This is a preparation commit to be able to use the NVME identify command
space controller command from two places without duplication.
Signed-off-by: Joel Granados <j.granados at samsung.com>
---
drivers/nvme/host/core.c | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 7dbf221247f7..d76be125dc49 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3019,9 +3019,27 @@ static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units)
return val;
}
+int nvme_identify_cs_ctrl(struct nvme_ctrl *ctrl, struct nvme_id_ctrl_nvm **id)
+{
+ struct nvme_command c = { };
+ int err;
+
+ c.identify.opcode = nvme_admin_identify;
+ c.identify.cns = NVME_ID_CNS_CS_CTRL;
+ c.identify.csi = NVME_CSI_NVM;
+
+ *id = kzalloc(sizeof(**id), GFP_KERNEL);
+ if (!(*id))
+ return -ENOMEM;
+
+ err = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id));
+ if (err)
+ kfree(*id);
+ return err;
+}
+
static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
{
- struct nvme_command c = { };
struct nvme_id_ctrl_nvm *id;
int ret;
@@ -3048,17 +3066,9 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
if (nvme_ctrl_limited_cns(ctrl))
return 0;
- id = kzalloc(sizeof(*id), GFP_KERNEL);
- if (!id)
- return -ENOMEM;
-
- c.identify.opcode = nvme_admin_identify;
- c.identify.cns = NVME_ID_CNS_CS_CTRL;
- c.identify.csi = NVME_CSI_NVM;
-
- ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id));
+ ret = nvme_identify_cs_ctrl(ctrl, &id);
if (ret)
- goto free_data;
+ return ret;
if (id->dmrl)
ctrl->max_discard_segments = id->dmrl;
@@ -3066,7 +3076,6 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
if (id->wzsl)
ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl);
-free_data:
kfree(id);
return ret;
}
--
2.30.2
More information about the Linux-nvme
mailing list