Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nvmet: add helpers to set the result field for connect commands

The code to set the result field for the admin and I/O connect commands
is not only verbose and duplicated, but also violates the aliasing
rules as it accesses both the u16 and u32 members in the union.

Add a little helper to sort all that out.

Fixes: db1312dd9548 ("nvmet: implement basic In-Band Authentication")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Hannes Reinecke <hare@suse.de>

+8 -10
+8 -10
drivers/nvme/target/fabrics-cmd.c
··· 198 198 return ret; 199 199 } 200 200 201 + static u32 nvmet_connect_result(struct nvmet_ctrl *ctrl) 202 + { 203 + return (u32)ctrl->cntlid | 204 + (nvmet_has_auth(ctrl) ? NVME_CONNECT_AUTHREQ_ATR : 0); 205 + } 206 + 201 207 static void nvmet_execute_admin_connect(struct nvmet_req *req) 202 208 { 203 209 struct nvmf_connect_command *c = &req->cmd->connect; ··· 275 269 ctrl->cntlid, ctrl->subsys->subsysnqn, ctrl->hostnqn, 276 270 ctrl->pi_support ? " T10-PI is enabled" : "", 277 271 nvmet_has_auth(ctrl) ? " with DH-HMAC-CHAP" : ""); 278 - req->cqe->result.u16 = cpu_to_le16(ctrl->cntlid); 279 - 280 - if (nvmet_has_auth(ctrl)) 281 - req->cqe->result.u32 |= cpu_to_le32(NVME_CONNECT_AUTHREQ_ATR); 272 + req->cqe->result.u32 = cpu_to_le32(nvmet_connect_result(ctrl)); 282 273 out: 283 274 kfree(d); 284 275 complete: ··· 331 328 if (status) 332 329 goto out_ctrl_put; 333 330 334 - /* pass back cntlid for successful completion */ 335 - req->cqe->result.u16 = cpu_to_le16(ctrl->cntlid); 336 - 337 331 pr_debug("adding queue %d to ctrl %d.\n", qid, ctrl->cntlid); 338 - if (nvmet_has_auth(ctrl)) 339 - req->cqe->result.u32 |= cpu_to_le32(NVME_CONNECT_AUTHREQ_ATR); 340 - 332 + req->cqe->result.u32 = cpu_to_le32(nvmet_connect_result(ctrl)); 341 333 out: 342 334 kfree(d); 343 335 complete: