[PATCH 1/2] ufs: core: Initialize a value of an attribute as returned by uic cmd

Wonkon Kim posted 2 patches 3 months, 3 weeks ago
[PATCH 1/2] ufs: core: Initialize a value of an attribute as returned by uic cmd
Posted by Wonkon Kim 3 months, 3 weeks ago
From: wkon-kim <wkon.kim@samsung.com>

If ufshcd_send_cmd() fails, *mib_val may have a garbage value.
It can get an unintended value of an attribute.
ufshcd_dme_get_attr() always initializes *mib_val.

Fixes: 12b4fdb4f6bc ("[SCSI] ufs: add dme configuration primitives")
Signed-off-by: Wonkon Kim <wkon.kim@samsung.com>
---
 drivers/ufs/core/ufshcd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 9a43102b2b21..969f3a23bf92 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -4273,8 +4273,8 @@ int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel,
 			get, UIC_GET_ATTR_ID(attr_sel),
 			UFS_UIC_COMMAND_RETRIES - retries);
 
-	if (mib_val && !ret)
-		*mib_val = uic_cmd.argument3;
+	if (mib_val)
+		*mib_val = ret == 0 ? uic_cmd.argument3 : 0;
 
 	if (peer && (hba->quirks & UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE)
 	    && pwr_mode_change)
-- 
2.34.1