[PATCH] scsi: ufs: core: initialize sg_cnt, sg_list

From: Tom Rix
Date: Thu Jan 05 2023 - 16:49:02 EST


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.

Signed-off-by: Tom Rix <trix@xxxxxxxxxx>
---
drivers/ufs/core/ufs_bsg.c | 4 ++--
drivers/ufs/core/ufshcd.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/ufs/core/ufs_bsg.c b/drivers/ufs/core/ufs_bsg.c
index 0044029bcf7b..0d38e7fa34cc 100644
--- a/drivers/ufs/core/ufs_bsg.c
+++ b/drivers/ufs/core/ufs_bsg.c
@@ -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;

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index da81eafc19d5..6ed728885650 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -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));
--
2.27.0