Skip to contentSkip to conversation

ASoC: codecs: da*: Remove redundant null check before clk_prepare_enable/clk_disable_unprepare

PATCH In review Xu Wang 2 participants 2 messages Jan 8, 2021

Subsystems (3)
lore
Share & tools
lore

Xu Wang

author
#0 lore raw

PATCH 1/1 ASoC: codecs: da*: Remove redundant null check before clk_prepare_enable/clk_disable_unprepare

Because clk_prepare_enable() and clk_disable_unprepare() already checked NULL clock parameter, so the additional checks are unnecessary, just remove them.

---
 sound/soc/codecs/da7218.c     | 13 +++++--------
 sound/soc/codecs/da7219-aad.c | 19 ++++++++-----------
 sound/soc/codecs/da7219.c     |  3 +--
 3 files changed, 14 insertions(+), 21 deletions(-)
sound/soc/codecs/da7218.c +5 -8
index 2bfafbe9e3dc..324d95e3b48a 100644
@@ -2582,12 +2582,10 @@ static int da7218_set_bias_level(struct snd_soc_component *component,
 	case SND_SOC_BIAS_PREPARE:
 		/* Enable MCLK for transition to ON state */
 		if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY) {
-			if (da7218->mclk) {
-				ret = clk_prepare_enable(da7218->mclk);
-				if (ret) {
-					dev_err(component->dev, "Failed to enable mclk\n");
-					return ret;
-				}
+			ret = clk_prepare_enable(da7218->mclk);
+			if (ret) {
+				dev_err(component->dev, "Failed to enable mclk\n");
+				return ret;
 			}
 		}
 
@@ -2605,8 +2603,7 @@ static int da7218_set_bias_level(struct snd_soc_component *component,
 					    DA7218_LDO_EN_MASK);
 		} else {
 			/* Remove MCLK */
-			if (da7218->mclk)
-				clk_disable_unprepare(da7218->mclk);
+			clk_disable_unprepare(da7218->mclk);
 		}
 		break;
 	case SND_SOC_BIAS_OFF:
sound/soc/codecs/da7219-aad.c +8 -11
index 48081d71c22c..fa61cfc8e50c 100644
@@ -123,15 +123,13 @@ static void da7219_aad_hptest_work(struct work_struct *work)
 	mutex_lock(&da7219->pll_lock);
 
 	/* Ensure MCLK is available for HP test procedure */
-	if (da7219->mclk) {
-		ret = clk_prepare_enable(da7219->mclk);
-		if (ret) {
-			dev_err(component->dev, "Failed to enable mclk - %d\n", ret);
-			mutex_unlock(&da7219->pll_lock);
-			mutex_unlock(&da7219->ctrl_lock);
-			snd_soc_dapm_mutex_unlock(dapm);
-			return;
-		}
+	ret = clk_prepare_enable(da7219->mclk);
+	if (ret) {
+		dev_err(component->dev, "Failed to enable mclk - %d\n", ret);
+		mutex_unlock(&da7219->pll_lock);
+		mutex_unlock(&da7219->ctrl_lock);
+		snd_soc_dapm_mutex_unlock(dapm);
+		return;
 	}
 
 	/*
@@ -318,8 +316,7 @@ static void da7219_aad_hptest_work(struct work_struct *work)
 		da7219_set_pll(component, DA7219_SYSCLK_MCLK, 0);
 
 	/* Remove MCLK, if previously enabled */
-	if (da7219->mclk)
-		clk_disable_unprepare(da7219->mclk);
+	clk_disable_unprepare(da7219->mclk);
 
 	mutex_unlock(&da7219->pll_lock);
 	mutex_unlock(&da7219->ctrl_lock);
sound/soc/codecs/da7219.c +1 -2
index e9b45daec0ca..50307cc9d640 100644
@@ -1826,8 +1826,7 @@ static int da7219_set_bias_level(struct snd_soc_component *component,
 
 		if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_PREPARE) {
 			/* Remove MCLK */
-			if (da7219->mclk)
-				clk_disable_unprepare(da7219->mclk);
+			clk_disable_unprepare(da7219->mclk);
 		}
 		break;
 	case SND_SOC_BIAS_OFF:
Signature · 1 line
2.17.1
#1 lore raw
Quoted 92 lines · Xu Wang

Because clk_prepare_enable() and clk_disable_unprepare() already checked NULL clock parameter, so the additional checks are unnecessary, just remove them.

---
 sound/soc/codecs/da7218.c     | 13 +++++--------
 sound/soc/codecs/da7219-aad.c | 19 ++++++++-----------
 sound/soc/codecs/da7219.c     |  3 +--
 3 files changed, 14 insertions(+), 21 deletions(-)
sound/soc/codecs/da7218.c +3 -6
index 2bfafbe9e3dc..324d95e3b48a 100644
@@ -2582,12 +2582,10 @@ static int da7218_set_bias_level(struct
 snd_soc_component *component,
 	case SND_SOC_BIAS_PREPARE:
 		/* Enable MCLK for transition to ON state */
 		if (snd_soc_component_get_bias_level(component) ==
 SND_SOC_BIAS_STANDBY) {
-			if (da7218->mclk) {
-				ret = clk_prepare_enable(da7218->mclk);
-				if (ret) {
-					dev_err(component->dev, "Failed to
 enable mclk\n");
-					return ret;
-				}
+			ret = clk_prepare_enable(da7218->mclk);
+			if (ret) {
+				dev_err(component->dev, "Failed to enable

mclk\n");

sound/soc/codecs/da7218.c +2 -2
+				return ret;
 			}
 		}
@@ -2605,8 +2603,7 @@ static int da7218_set_bias_level(struct
 snd_soc_component *component,
 					    DA7218_LDO_EN_MASK);
 		} else {
 			/* Remove MCLK */
-			if (da7218->mclk)
-				clk_disable_unprepare(da7218->mclk);
+			clk_disable_unprepare(da7218->mclk);
 		}
 		break;
sound/soc/codecs/da7218.c +0 -0
 	case SND_SOC_BIAS_OFF:
sound/soc/codecs/da7219-aad.c +7 -9
index 48081d71c22c..fa61cfc8e50c 100644
@@ -123,15 +123,13 @@ static void da7219_aad_hptest_work(struct work_struct
 *work)
 	mutex_lock(&da7219->pll_lock);
 
 	/* Ensure MCLK is available for HP test procedure */
-	if (da7219->mclk) {
-		ret = clk_prepare_enable(da7219->mclk);
-		if (ret) {
-			dev_err(component->dev, "Failed to enable mclk -
 %d\n", ret);
-			mutex_unlock(&da7219->pll_lock);
-			mutex_unlock(&da7219->ctrl_lock);
-			snd_soc_dapm_mutex_unlock(dapm);
-			return;
-		}
+	ret = clk_prepare_enable(da7219->mclk);
+	if (ret) {
+		dev_err(component->dev, "Failed to enable mclk - %d\n", ret);
+		mutex_unlock(&da7219->pll_lock);
+		mutex_unlock(&da7219->ctrl_lock);
+		snd_soc_dapm_mutex_unlock(dapm);
+		return;
 	}
sound/soc/codecs/da7219-aad.c +1 -2
 	/*
@@ -318,8 +316,7 @@ static void da7219_aad_hptest_work(struct work_struct
 *work)
 		da7219_set_pll(component, DA7219_SYSCLK_MCLK, 0);
 
 	/* Remove MCLK, if previously enabled */
-	if (da7219->mclk)
-		clk_disable_unprepare(da7219->mclk);
+	clk_disable_unprepare(da7219->mclk);
 
 	mutex_unlock(&da7219->pll_lock);
sound/soc/codecs/da7219-aad.c +0 -0
 	mutex_unlock(&da7219->ctrl_lock);
sound/soc/codecs/da7219.c +0 -0
index e9b45daec0ca..50307cc9d640 100644

sound/soc/codecs/da7219.c static int da7219_set_bias_level(struct · line 1831

Quoted 8 lines
sound/soc/codecs/da7219.c +1 -2
@@ -1826,8 +1826,7 @@ static int da7219_set_bias_level(struct
 snd_soc_component *component,
 
 		if (snd_soc_component_get_bias_level(component) ==
 SND_SOC_BIAS_PREPARE) {
 			/* Remove MCLK */
-			if (da7219->mclk)
-				clk_disable_unprepare(da7219->mclk);
+			clk_disable_unprepare(da7219->mclk);

You seem to have missed the change for clk_prepare_enable() usage in the same function. Also as the above is now a single line if statement, you can remove the brackets.

In addition, the normal approach would be to split the changes into separate patches per driver, just so it's cleaner.

Quoted 5 lines
sound/soc/codecs/da7219.c +0 -0
 		}
sound/soc/codecs/da7219.c +0 -1
 		break;
 	case SND_SOC_BIAS_OFF:
--

2.17.1