struct nvme_id_ns *id;
        u16 status = 0;
 
-       ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid);
-       if (!ns) {
+       if (le32_to_cpu(req->cmd->identify.nsid) == NVME_NSID_ALL) {
                status = NVME_SC_INVALID_NS | NVME_SC_DNR;
                goto out;
        }
        id = kzalloc(sizeof(*id), GFP_KERNEL);
        if (!id) {
                status = NVME_SC_INTERNAL;
-               goto out_put_ns;
+               goto out;
        }
 
+       /* return an all zeroed buffer if we can't find an active namespace */
+       ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid);
+       if (!ns)
+               goto done;
+
        /*
         * nuse = ncap = nsze isn't always true, but we have no way to find
         * that out from the underlying device.
 
        id->lbaf[0].ds = ns->blksize_shift;
 
+       nvmet_put_namespace(ns);
+done:
        status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id));
-
        kfree(id);
-out_put_ns:
-       nvmet_put_namespace(ns);
 out:
        nvmet_req_complete(req, status);
 }