nvme: split out a nvme_identify_ns_nvm helper
[linux-2.6-block.git] / drivers / nvme / host / core.c
index f0686a872d0e309988baa7effa2bc46d8f4a7748..9abcc389f0f3aee522288ec943b80d3ef3bbecc1 100644 (file)
@@ -1831,12 +1831,35 @@ static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b)
                a->csi == b->csi;
 }
 
+static int nvme_identify_ns_nvm(struct nvme_ctrl *ctrl, unsigned int nsid,
+               struct nvme_id_ns_nvm **nvmp)
+{
+       struct nvme_command c = {
+               .identify.opcode        = nvme_admin_identify,
+               .identify.nsid          = cpu_to_le32(nsid),
+               .identify.cns           = NVME_ID_CNS_CS_NS,
+               .identify.csi           = NVME_CSI_NVM,
+       };
+       struct nvme_id_ns_nvm *nvm;
+       int ret;
+
+       nvm = kzalloc(sizeof(*nvm), GFP_KERNEL);
+       if (!nvm)
+               return -ENOMEM;
+
+       ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, nvm, sizeof(*nvm));
+       if (ret)
+               kfree(nvm);
+       else
+               *nvmp = nvm;
+       return ret;
+}
+
 static int nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head,
                struct nvme_id_ns *id)
 {
        bool first = id->dps & NVME_NS_DPS_PI_FIRST;
        unsigned lbaf = nvme_lbaf_index(id->flbas);
-       struct nvme_command c = { };
        struct nvme_id_ns_nvm *nvm;
        int ret = 0;
        u32 elbaf;
@@ -1849,18 +1872,9 @@ static int nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head,
                goto set_pi;
        }
 
-       nvm = kzalloc(sizeof(*nvm), GFP_KERNEL);
-       if (!nvm)
-               return -ENOMEM;
-
-       c.identify.opcode = nvme_admin_identify;
-       c.identify.nsid = cpu_to_le32(head->ns_id);
-       c.identify.cns = NVME_ID_CNS_CS_NS;
-       c.identify.csi = NVME_CSI_NVM;
-
-       ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, nvm, sizeof(*nvm));
+       ret = nvme_identify_ns_nvm(ctrl, head->ns_id, &nvm);
        if (ret)
-               goto free_data;
+               goto set_pi;
 
        elbaf = le32_to_cpu(nvm->elbaf[lbaf]);