Skip to contentSkip to conversation

scsi: ufs: core: Use 'else' in ufshcd_hba_enable()

PATCH In review Keoseong Park 2 participants 3 messages Oct 27, 2022 – Oct 28, 2022 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20221027062013epcms2p7af8fbc60caaba50686233492fb3dfd93@epcms2p7

#1 lore raw

PATCH 1/1 scsi: ufs: core: Use 'else' in ufshcd_hba_enable()

Convert if (!ret) { ... } if (ret) { ... } into
if (!ret) { ... } else { ... }.

---
 drivers/ufs/core/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +1 -1
index 7256e6c43ca6..3b794be53287 100644
@@ -4670,7 +4670,7 @@ int ufshcd_hba_enable(struct ufs_hba *hba)
 			ret = ufshcd_dme_enable(hba);
 			if (!ret)
 				ufshcd_vops_hce_enable_notify(hba, POST_CHANGE);
-			if (ret)
+			else
 				dev_err(hba->dev,
 					"Host controller enable failed with non-hce\n");
 		}
Signature · 1 line
2.17.1
#2 lore raw
Quoted 13 lines · Keoseong Park

Convert if (!ret) { ... } if (ret) { ... } into
if (!ret) { ... } else { ... }.

---
  drivers/ufs/core/ufshcd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +0 -0
index 7256e6c43ca6..3b794be53287 100644

drivers/ufs/core/ufshcd.c int ufshcd_hba_enable(struct ufs_hba *hba) · line 4676

Quoted 8 lines
drivers/ufs/core/ufshcd.c +1 -1
@@ -4670,7 +4670,7 @@ int ufshcd_hba_enable(struct ufs_hba *hba)
  			ret = ufshcd_dme_enable(hba);
  			if (!ret)
  				ufshcd_vops_hce_enable_notify(hba, POST_CHANGE);
-			if (ret)
+			else
  				dev_err(hba->dev,
  					"Host controller enable failed with non-hce\n");
  		}

If ufshcd_hba_enable() is modified it should be converted into the widely used "if error return" style. How about the untested patch below?

drivers/ufs/core/ufshcd.c +9 -7
index 05feec10fad3..89f8b86c3f85 100644
@@ -4668,14 +4668,16 @@ int ufshcd_hba_enable(struct ufs_hba *hba)
 		/* enable UIC related interrupts */
 		ufshcd_enable_intr(hba, UFSHCD_UIC_MASK);
 		ret = ufshcd_dme_reset(hba);
-		if (!ret) {
-			ret = ufshcd_dme_enable(hba);
-			if (!ret)
-				ufshcd_vops_hce_enable_notify(hba, POST_CHANGE);
-			if (ret)
-				dev_err(hba->dev,
-					"Host controller enable failed with non-hce\n");
+		if (ret) {
+			dev_err(hba->dev, "DME_RESET failed\n");
+			return ret;
+		}
+		ret = ufshcd_dme_enable(hba);
+		if (ret) {
+			dev_err(hba->dev, "Enabling DME failed\n");
+			return ret;
 		}
+		ufshcd_vops_hce_enable_notify(hba, POST_CHANGE);
 	} else {
 		ret = ufshcd_hba_execute_hce(hba);
 	}
#3 lore raw

Hi Bart,

Quoted 9 lines · Keoseong Park
Quoted 8 lines

Convert if (!ret) { ... } if (ret) { ... } into
if (!ret) { ... } else { ... }.

---
  drivers/ufs/core/ufshcd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

drivers/ufs/core/ufshcd.c int ufshcd_hba_enable(struct ufs_hba *hba) · line 4676

Quoted 13 lines
drivers/ufs/core/ufshcd.c +1 -1
index 7256e6c43ca6..3b794be53287 100644
@@ -4670,7 +4670,7 @@ int ufshcd_hba_enable(struct ufs_hba *hba)
  			ret = ufshcd_dme_enable(hba);
  			if (!ret)
  				ufshcd_vops_hce_enable_notify(hba, POST_CHANGE);
-			if (ret)
+			else
  				dev_err(hba->dev,
  					"Host controller enable failed with non-hce\n");
  		}

If ufshcd_hba_enable() is modified it should be converted into the widely used "if error return" style. How about the untested patch below?

Thanks for your feedback.
That seems to be better.
I will apply it to the next version.

Best Regards,
Keoseong

Quoted 29 lines
drivers/ufs/core/ufshcd.c +9 -7
index 05feec10fad3..89f8b86c3f85 100644
@@ -4668,14 +4668,16 @@ int ufshcd_hba_enable(struct ufs_hba *hba)
 		/* enable UIC related interrupts */
 		ufshcd_enable_intr(hba, UFSHCD_UIC_MASK);
 		ret = ufshcd_dme_reset(hba);
-		if (!ret) {
-			ret = ufshcd_dme_enable(hba);
-			if (!ret)
-				ufshcd_vops_hce_enable_notify(hba, POST_CHANGE);
-			if (ret)
-				dev_err(hba->dev,
-					"Host controller enable failed with non-hce\n");
+		if (ret) {
+			dev_err(hba->dev, "DME_RESET failed\n");
+			return ret;
+		}
+		ret = ufshcd_dme_enable(hba);
+		if (ret) {
+			dev_err(hba->dev, "Enabling DME failed\n");
+			return ret;
 		}
+		ufshcd_vops_hce_enable_notify(hba, POST_CHANGE);
 	} else {
 		ret = ufshcd_hba_execute_hce(hba);
 	}