Skip to contentSkip to conversation

nvmem: imx-ocotp: Improve logic to save many code lines

PATCH In review Anson Huang 2 participants 2 messages Mar 19, 2020 – Apr 17, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: imx-ocotp: Improve logic to save many code lines

Several logic improvements to save many code lines:

- no need to use goto;
- no need to assign return value;
- combine different conditions of return value into one line.

---
 drivers/nvmem/imx-ocotp.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/nvmem/imx-ocotp.c +2 -7
index 50bea2a..7a1ebd6 100644
@@ -196,7 +196,6 @@ static int imx_ocotp_read(void *context, unsigned int offset,
 		if (*(buf - 1) == IMX_OCOTP_READ_LOCKED_VAL)
 			imx_ocotp_clr_err_if_set(priv);
 	}
-	ret = 0;
 
 read_end:
 	clk_disable_unprepare(priv->clk);
@@ -435,17 +434,13 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val,
 	       priv->base + IMX_OCOTP_ADDR_CTRL_SET);
 	ret = imx_ocotp_wait_for_busy(priv,
 				      priv->params->ctrl.bm_rel_shadows);
-	if (ret < 0) {
+	if (ret < 0)
 		dev_err(priv->dev, "timeout during shadow register reload\n");
-		goto write_end;
-	}
 
 write_end:
 	clk_disable_unprepare(priv->clk);
 	mutex_unlock(&ocotp_mutex);
-	if (ret < 0)
-		return ret;
-	return bytes;
+	return ret < 0 ? ret : bytes;
 }
 
 static struct nvmem_config imx_ocotp_nvmem_config = {
Signature · 1 line
2.7.4
#1 lore raw
Quoted 7 lines · Anson Huang

Several logic improvements to save many code lines:

- no need to use goto;
- no need to assign return value;
- combine different conditions of return value into one line.

Applied thanks,
--srini

Quoted 37 lines
---
  drivers/nvmem/imx-ocotp.c | 9 ++-------
  1 file changed, 2 insertions(+), 7 deletions(-)
drivers/nvmem/imx-ocotp.c +2 -7
index 50bea2a..7a1ebd6 100644
@@ -196,7 +196,6 @@ static int imx_ocotp_read(void *context, unsigned int offset,
  		if (*(buf - 1) == IMX_OCOTP_READ_LOCKED_VAL)
  			imx_ocotp_clr_err_if_set(priv);
  	}
-	ret = 0;
 
  read_end:
  	clk_disable_unprepare(priv->clk);
@@ -435,17 +434,13 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val,
  	       priv->base + IMX_OCOTP_ADDR_CTRL_SET);
  	ret = imx_ocotp_wait_for_busy(priv,
  				      priv->params->ctrl.bm_rel_shadows);
-	if (ret < 0) {
+	if (ret < 0)
  		dev_err(priv->dev, "timeout during shadow register reload\n");
-		goto write_end;
-	}
 
  write_end:
  	clk_disable_unprepare(priv->clk);
  	mutex_unlock(&ocotp_mutex);
-	if (ret < 0)
-		return ret;
-	return bytes;
+	return ret < 0 ? ret : bytes;
  }
 
  static struct nvmem_config imx_ocotp_nvmem_config = {