Skip to contentSkip to conversation

scsi: ufs: core: initialize sg_cnt, sg_list

PATCH In review Tom Rix 2 participants 2 messages Jan 5, 2023 – Jan 6, 2023

Subsystems (2)
lore
Share & tools
lore

Tom Rix

author
#0 lore raw

PATCH 1/1 scsi: ufs: core: initialize sg_cnt, sg_list

The clang build fails with
drivers/ufs/core/ufs_bsg.c:107:6: error: variable 'sg_cnt' is used
uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]

        if (dir != DMA_NONE) {
            ^~~~~~~~~~~~~~~

Similar for sg_list.

This is not an error because ufshcd_advanced_rpmb_req_handler() does a similar check, but that check can be reduced if sg_list is initialized to NULL. Initialize sg_cnt to silence its error.

---
 drivers/ufs/core/ufs_bsg.c | 4 ++--
 drivers/ufs/core/ufshcd.c  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/ufs/core/ufs_bsg.c +2 -2
index 0044029bcf7b..0d38e7fa34cc 100644
@@ -70,9 +70,9 @@ static int ufs_bsg_exec_advanced_rpmb_req(struct ufs_hba *hba, struct bsg_job *j
 	struct ufs_rpmb_reply *rpmb_reply = job->reply;
 	struct bsg_buffer *payload = NULL;
 	enum dma_data_direction dir;
-	struct scatterlist *sg_list;
+	struct scatterlist *sg_list = NULL;
 	int rpmb_req_type;
-	int sg_cnt;
+	int sg_cnt = 0;
 	int ret;
 	int data_len;
 
drivers/ufs/core/ufshcd.c +1 -1
index da81eafc19d5..6ed728885650 100644
@@ -7051,7 +7051,7 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r
 	/* Copy EHS, starting with byte32, immediately after the CDB package */
 	memcpy(lrbp->ucd_req_ptr + 1, req_ehs, sizeof(*req_ehs));
 
-	if (dir != DMA_NONE && sg_list)
+	if (sg_list)
 		ufshcd_sgl_to_prdt(hba, lrbp, sg_cnt, sg_list);
 
 	memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp));
Signature · 1 line
2.27.0
reviewer
#1 lore raw
Quoted 6 lines

The clang build fails with drivers/ufs/core/ufs_bsg.c:107:6: error: variable 'sg_cnt' is used
uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-
uninitialized]

        if (dir != DMA_NONE) {
            ^~~~~~~~~~~~~~~
Quoted 7 lines

Similar for sg_list.

This is not an error because ufshcd_advanced_rpmb_req_handler() does a similar check, but that check can be reduced if sg_list is initialized to NULL. Initialize sg_cnt to silence its error.

I think that Bean already submitted a fix for that.

Thanks,
Avri