aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/nvme/target/admin-cmd.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index f7ba006d6a65..2d7a98ab53fb 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -168,11 +168,21 @@ out:
168 nvmet_req_complete(req, status); 168 nvmet_req_complete(req, status);
169} 169}
170 170
171static void copy_and_pad(char *dst, int dst_len, const char *src, int src_len)
172{
173 int len = min(src_len, dst_len);
174
175 memcpy(dst, src, len);
176 if (dst_len > len)
177 memset(dst + len, ' ', dst_len - len);
178}
179
171static void nvmet_execute_identify_ctrl(struct nvmet_req *req) 180static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
172{ 181{
173 struct nvmet_ctrl *ctrl = req->sq->ctrl; 182 struct nvmet_ctrl *ctrl = req->sq->ctrl;
174 struct nvme_id_ctrl *id; 183 struct nvme_id_ctrl *id;
175 u16 status = 0; 184 u16 status = 0;
185 const char model[] = "Linux";
176 186
177 id = kzalloc(sizeof(*id), GFP_KERNEL); 187 id = kzalloc(sizeof(*id), GFP_KERNEL);
178 if (!id) { 188 if (!id) {
@@ -184,8 +194,10 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
184 id->vid = 0; 194 id->vid = 0;
185 id->ssvid = 0; 195 id->ssvid = 0;
186 196
187 memset(id->sn, ' ', sizeof(id->sn)); 197 bin2hex(id->sn, &ctrl->subsys->serial,
188 snprintf(id->sn, sizeof(id->sn), "%llx", ctrl->subsys->serial); 198 min(sizeof(ctrl->subsys->serial), sizeof(id->sn) / 2));
199 copy_and_pad(id->mn, sizeof(id->mn), model, sizeof(model) - 1);
200 copy_and_pad(id->fr, sizeof(id->fr), UTS_RELEASE, strlen(UTS_RELEASE));
189 201
190 memset(id->mn, ' ', sizeof(id->mn)); 202 memset(id->mn, ' ', sizeof(id->mn));
191 strncpy((char *)id->mn, "Linux", sizeof(id->mn)); 203 strncpy((char *)id->mn, "Linux", sizeof(id->mn));