[linux-nvme:nvme-5.19] BUILD SUCCESS WITH WARNING 4db675888cdb7b24812e289d7f90e7928dd400a3

Alan Adamson alan.adamson at oracle.com
Thu Jun 30 09:54:06 PDT 2022



> On Jun 29, 2022, at 11:24 PM, Christoph Hellwig <hch at lst.de> wrote:
> 
> On Thu, Jun 30, 2022 at 01:58:42PM +0800, kernel test robot wrote:
>> tree/branch: git://git.infradead.org/nvme.git nvme-5.19
>> branch HEAD: 4db675888cdb7b24812e289d7f90e7928dd400a3  nvmet: add a clear_ids attribute for passthru targets
>> 
>> Warning: (recently discovered and may have been fixed)
>> 
>> drivers/nvme/target/passthru.c:54:16: warning: variable 'csi_seen' is used uninitialized whenever 'for' loop exits because its condition is false [-Wsometimes-uninitialized]
>> drivers/nvme/target/passthru.c:57:7: warning: variable 'csi_seen' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
> 
> I ended up fixing this with the patch below.  Alan, let me know
> if this works for you:

Looks good.  I tested with my environment.

Reviewed-by: Alan Adamson <alan.adamson at oracle.com>



> 
> diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
> index d71ed297ad16b..6f39a29828b12 100644
> --- a/drivers/nvme/target/passthru.c
> +++ b/drivers/nvme/target/passthru.c
> @@ -33,10 +33,9 @@ void nvmet_passthrough_override_cap(struct nvmet_ctrl *ctrl)
> static u16 nvmet_passthru_override_id_descs(struct nvmet_req *req)
> {
> 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
> -	struct nvme_ns_id_desc *cur;
> 	u16 status = NVME_SC_SUCCESS;
> 	int pos, len;
> -	bool csi_seen;
> +	bool csi_seen = false;
> 	void *data;
> 	u8 csi;
> 
> @@ -52,26 +51,25 @@ static u16 nvmet_passthru_override_id_descs(struct nvmet_req *req)
> 		goto out_free;
> 
> 	for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
> -		cur = data + pos;
> +		struct nvme_ns_id_desc *cur = data + pos;
> 
> 		if (cur->nidl == 0)
> 			break;
> -		len = cur->nidl;
> 		if (cur->nidt == NVME_NIDT_CSI) {
> -			memcpy(&csi, data + pos + sizeof(struct nvme_ns_id_desc),
> -			       NVME_NIDT_CSI_LEN);
> -			csi_seen = 1;
> +			memcpy(&csi, cur + 1, NVME_NIDT_CSI_LEN);
> +			csi_seen = true;
> 			break;
> 		}
> -		len += sizeof(struct nvme_ns_id_desc);
> +		len = sizeof(struct nvme_ns_id_desc) + cur->nidl;
> 	}
> 
> 	memset(data, 0, NVME_IDENTIFY_DATA_SIZE);
> 	if (csi_seen) {
> -		cur = data;
> +		struct nvme_ns_id_desc *cur = data;
> +
> 		cur->nidt = NVME_NIDT_CSI;
> 		cur->nidl = NVME_NIDT_CSI_LEN;
> -		memcpy(data + sizeof(struct nvme_ns_id_desc), &csi,  NVME_NIDT_CSI_LEN);
> +		memcpy(cur + 1, &csi, NVME_NIDT_CSI_LEN);
> 	}
> 	status = nvmet_copy_to_sgl(req, 0, data, NVME_IDENTIFY_DATA_SIZE);
> out_free:




More information about the Linux-nvme mailing list