Skip to contentSkip to conversation

Input: tegra-kbc: Handle return value of clk_prepare_enable.

PATCH Applied Arvind Yadav 2 participants 4 messages Aug 1, 2017 – Aug 31, 2017

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

PATCH 1/2 Input: tegra-kbc: Handle return value of clk_prepare_enable.

clk_prepare_enable() can fail here and we must check its return value.

---
 drivers/input/keyboard/tegra-kbc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/input/keyboard/tegra-kbc.c +4 -1
index 0c07e10..edc1385 100644
@@ -370,8 +370,11 @@ static int tegra_kbc_start(struct tegra_kbc *kbc)
 {
 	unsigned int debounce_cnt;
 	u32 val = 0;
+	int ret;
 
-	clk_prepare_enable(kbc->clk);
+	ret = clk_prepare_enable(kbc->clk);
+	if (ret)
+		return ret;
 
 	/* Reset the KBC controller to clear all previous status.*/
 	reset_control_assert(kbc->rst);
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/2 Input: pxa27x_keypad: Handle return value of clk_prepare_enable.

clk_prepare_enable() can fail here and we must check its return value.

---
 drivers/input/keyboard/pxa27x_keypad.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/input/keyboard/pxa27x_keypad.c +11 -3
index 3841fa3..a3396a7 100644
@@ -644,9 +644,12 @@ static void pxa27x_keypad_config(struct pxa27x_keypad *keypad)
 static int pxa27x_keypad_open(struct input_dev *dev)
 {
 	struct pxa27x_keypad *keypad = input_get_drvdata(dev);
-
+	int ret;
 	/* Enable unit clock */
-	clk_prepare_enable(keypad->clk);
+	ret = clk_prepare_enable(keypad->clk);
+	if (ret)
+		return ret;
+
 	pxa27x_keypad_config(keypad);
 
 	return 0;
@@ -683,6 +686,7 @@ static int pxa27x_keypad_resume(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct pxa27x_keypad *keypad = platform_get_drvdata(pdev);
 	struct input_dev *input_dev = keypad->input_dev;
+	int ret;
 
 	/*
 	 * If the keypad is used as wake up source, the clock is not turned
@@ -695,7 +699,11 @@ static int pxa27x_keypad_resume(struct device *dev)
 
 		if (input_dev->users) {
 			/* Enable unit clock */
-			clk_prepare_enable(keypad->clk);
+			ret = clk_prepare_enable(keypad->clk);
+			if (ret) {
+				mutex_unlock(&input_dev->mutex);
+				return ret;
+			}
 			pxa27x_keypad_config(keypad);
 		}
 
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH 2/2] Input: pxa27x_keypad: Handle return value of clk_prepare_enable.

Quoted 36 lines · Arvind Yadav

clk_prepare_enable() can fail here and we must check its return value.

---
 drivers/input/keyboard/pxa27x_keypad.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/input/keyboard/pxa27x_keypad.c +6 -2
index 3841fa3..a3396a7 100644
@@ -644,9 +644,12 @@ static void pxa27x_keypad_config(struct pxa27x_keypad *keypad)
 static int pxa27x_keypad_open(struct input_dev *dev)
 {
 	struct pxa27x_keypad *keypad = input_get_drvdata(dev);
-
+	int ret;
 	/* Enable unit clock */
-	clk_prepare_enable(keypad->clk);
+	ret = clk_prepare_enable(keypad->clk);
+	if (ret)
+		return ret;
+
 	pxa27x_keypad_config(keypad);
 
 	return 0;
@@ -683,6 +686,7 @@ static int pxa27x_keypad_resume(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct pxa27x_keypad *keypad = platform_get_drvdata(pdev);
 	struct input_dev *input_dev = keypad->input_dev;
+	int ret;
 
 	/*
 	 * If the keypad is used as wake up source, the clock is not turned
@@ -695,7 +699,11 @@ static int pxa27x_keypad_resume(struct device *dev)
 

drivers/input/keyboard/pxa27x_keypad.c static int pxa27x_keypad_resume(struct device *dev) · line 708

Quoted 10 lines
drivers/input/keyboard/pxa27x_keypad.c +5 -1
 		if (input_dev->users) {
 			/* Enable unit clock */
-			clk_prepare_enable(keypad->clk);
+			ret = clk_prepare_enable(keypad->clk);
+			if (ret) {
+				mutex_unlock(&input_dev->mutex);
+				return ret;
+			}
 			pxa27x_keypad_config(keypad);
 		}

Rewrote as

	int ret = 0;

	...

		mutex_lock(&input_dev->mutex);

		if (input_dev->users) {
			/* Enable unit clock */
			ret = clk_prepare_enable(keypad->clk);
			if (!ret)
				pxa27x_keypad_config(keypad);
		}

		mutex_unlock(&input_dev->mutex);

	...
	return ret;

to avoid unlocking mutex in 2 places and applied, thanks.

Signature · 1 line
Dmitry
maintainer Applied
#3 lore raw
In reply to Arvind Yadav
Quoted 3 lines · Arvind Yadav

clk_prepare_enable() can fail here and we must check its return value.

Applied, thank you.

Quoted 24 lines
---
 drivers/input/keyboard/tegra-kbc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/input/keyboard/tegra-kbc.c +4 -1
index 0c07e10..edc1385 100644
@@ -370,8 +370,11 @@ static int tegra_kbc_start(struct tegra_kbc *kbc)
 {
 	unsigned int debounce_cnt;
 	u32 val = 0;
+	int ret;
 
-	clk_prepare_enable(kbc->clk);
+	ret = clk_prepare_enable(kbc->clk);
+	if (ret)
+		return ret;
 
 	/* Reset the KBC controller to clear all previous status.*/
 	reset_control_assert(kbc->rst);
Signature · 1 line
1.9.1
Signature · 1 line
Dmitry