[PATCH] Input: ep93xx_keypad - Add check for clk_enable() and clk_prepare_enable

Jiasheng Jiang posted 1 patch 1 week, 4 days ago
drivers/input/keyboard/ep93xx_keypad.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
[PATCH] Input: ep93xx_keypad - Add check for clk_enable() and clk_prepare_enable
Posted by Jiasheng Jiang 1 week, 4 days ago
Add check for the return value of clk_enable() and clk_prepare_enable()
in order to catch the potential exception.

Fixes: e06003af56c3 ("Input: add matrix keypad driver for Cirrus EP93xx")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
 drivers/input/keyboard/ep93xx_keypad.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/input/keyboard/ep93xx_keypad.c b/drivers/input/keyboard/ep93xx_keypad.c
index dcbc50304a5a..06252694f2da 100644
--- a/drivers/input/keyboard/ep93xx_keypad.c
+++ b/drivers/input/keyboard/ep93xx_keypad.c
@@ -141,10 +141,14 @@ static void ep93xx_keypad_config(struct ep93xx_keypad *keypad)
 static int ep93xx_keypad_open(struct input_dev *pdev)
 {
 	struct ep93xx_keypad *keypad = input_get_drvdata(pdev);
+	int ret;
 
 	if (!keypad->enabled) {
 		ep93xx_keypad_config(keypad);
-		clk_prepare_enable(keypad->clk);
+		ret = clk_prepare_enable(keypad->clk);
+		if (ret)
+			return ret;
+
 		keypad->enabled = true;
 	}
 
@@ -185,13 +189,19 @@ static int ep93xx_keypad_resume(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct ep93xx_keypad *keypad = platform_get_drvdata(pdev);
 	struct input_dev *input_dev = keypad->input_dev;
+	int ret;
 
 	mutex_lock(&input_dev->mutex);
 
 	if (input_device_enabled(input_dev)) {
 		if (!keypad->enabled) {
 			ep93xx_keypad_config(keypad);
-			clk_enable(keypad->clk);
+			ret = clk_enable(keypad->clk);
+			if (ret) {
+				mutex_unlock(&input_dev->mutex);
+				return ret;
+			}
+
 			keypad->enabled = true;
 		}
 	}
-- 
2.25.1
[PATCH] Input: samsung-keypad - Add check for clk_enable()
Posted by Jiasheng Jiang 1 week, 4 days ago
Add check for the return value of clk_enable() in order to catch the
potential exception.

Moreover, recursively convert the return type of samsung_keypad_start()
and samsung_keypad_toggle_wakeup() into int and check their return values.

Fixes: 48c98b1bb85a ("Input: samsung-keypad - implement runtime power management support")
Fixes: 0fffed27f92d ("Input: samsung-keypad - Add samsung keypad driver")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
 drivers/input/keyboard/samsung-keypad.c | 43 +++++++++++++++++--------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c
index e212eff7687c..f9bbd4e9d031 100644
--- a/drivers/input/keyboard/samsung-keypad.c
+++ b/drivers/input/keyboard/samsung-keypad.c
@@ -169,16 +169,19 @@ static irqreturn_t samsung_keypad_irq(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-static void samsung_keypad_start(struct samsung_keypad *keypad)
+static int samsung_keypad_start(struct samsung_keypad *keypad)
 {
 	unsigned int val;
+	int ret;
 
 	pm_runtime_get_sync(&keypad->pdev->dev);
 
 	/* Tell IRQ thread that it may poll the device. */
 	keypad->stopped = false;
 
-	clk_enable(keypad->clk);
+	ret = clk_enable(keypad->clk);
+	if (ret)
+		return ret;
 
 	/* Enable interrupt bits. */
 	val = readl(keypad->base + SAMSUNG_KEYIFCON);
@@ -189,6 +192,8 @@ static void samsung_keypad_start(struct samsung_keypad *keypad)
 	writel(0, keypad->base + SAMSUNG_KEYIFCOL);
 
 	pm_runtime_put(&keypad->pdev->dev);
+
+	return 0;
 }
 
 static void samsung_keypad_stop(struct samsung_keypad *keypad)
@@ -225,9 +230,7 @@ static int samsung_keypad_open(struct input_dev *input_dev)
 {
 	struct samsung_keypad *keypad = input_get_drvdata(input_dev);
 
-	samsung_keypad_start(keypad);
-
-	return 0;
+	return samsung_keypad_start(keypad);
 }
 
 static void samsung_keypad_close(struct input_dev *input_dev)
@@ -484,11 +487,14 @@ static int samsung_keypad_runtime_resume(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct samsung_keypad *keypad = platform_get_drvdata(pdev);
 	unsigned int val;
+	int ret;
 
 	if (keypad->stopped)
 		return 0;
 
-	clk_enable(keypad->clk);
+	ret = clk_enable(keypad->clk);
+	if (ret)
+		return ret;
 
 	val = readl(keypad->base + SAMSUNG_KEYIFCON);
 	val &= ~SAMSUNG_KEYIFCON_WAKEUPEN;
@@ -500,12 +506,15 @@ static int samsung_keypad_runtime_resume(struct device *dev)
 	return 0;
 }
 
-static void samsung_keypad_toggle_wakeup(struct samsung_keypad *keypad,
+static int samsung_keypad_toggle_wakeup(struct samsung_keypad *keypad,
 					 bool enable)
 {
 	unsigned int val;
+	int ret;
 
-	clk_enable(keypad->clk);
+	ret = clk_enable(keypad->clk);
+	if (ret)
+		return ret;
 
 	val = readl(keypad->base + SAMSUNG_KEYIFCON);
 	if (enable) {
@@ -520,6 +529,8 @@ static void samsung_keypad_toggle_wakeup(struct samsung_keypad *keypad,
 	writel(val, keypad->base + SAMSUNG_KEYIFCON);
 
 	clk_disable(keypad->clk);
+
+	return 0;
 }
 
 static int samsung_keypad_suspend(struct device *dev)
@@ -527,17 +538,18 @@ static int samsung_keypad_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct samsung_keypad *keypad = platform_get_drvdata(pdev);
 	struct input_dev *input_dev = keypad->input_dev;
+	int ret;
 
 	mutex_lock(&input_dev->mutex);
 
 	if (input_device_enabled(input_dev))
 		samsung_keypad_stop(keypad);
 
-	samsung_keypad_toggle_wakeup(keypad, true);
+	ret = samsung_keypad_toggle_wakeup(keypad, true);
 
 	mutex_unlock(&input_dev->mutex);
 
-	return 0;
+	return ret;
 }
 
 static int samsung_keypad_resume(struct device *dev)
@@ -545,17 +557,22 @@ static int samsung_keypad_resume(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct samsung_keypad *keypad = platform_get_drvdata(pdev);
 	struct input_dev *input_dev = keypad->input_dev;
+	int ret;
 
 	mutex_lock(&input_dev->mutex);
 
-	samsung_keypad_toggle_wakeup(keypad, false);
+	ret = samsung_keypad_toggle_wakeup(keypad, false);
+	if (ret) {
+		mutex_unlock(&input_dev->mutex);
+		return ret;
+	}
 
 	if (input_device_enabled(input_dev))
-		samsung_keypad_start(keypad);
+		ret = samsung_keypad_start(keypad);
 
 	mutex_unlock(&input_dev->mutex);
 
-	return 0;
+	return ret;
 }
 
 static const struct dev_pm_ops samsung_keypad_pm_ops = {
-- 
2.25.1
[PATCH] Input: spear-keyboard - Add check for clk_enable()
Posted by Jiasheng Jiang 1 week, 4 days ago
Add check for the return value of clk_enable() in order to catch the
potential exception.

Fixes: 8314f532ebd5 ("Input: spear_keyboard - reconfigure operating frequency on suspend")
Fixes: bc95df78c456 ("Input: add support for keyboards on ST SPEAr platform")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
 drivers/input/keyboard/spear-keyboard.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c
index 1df4feb8ba01..fe0a33862e60 100644
--- a/drivers/input/keyboard/spear-keyboard.c
+++ b/drivers/input/keyboard/spear-keyboard.c
@@ -273,11 +273,16 @@ static int spear_kbd_suspend(struct device *dev)
 	struct spear_kbd *kbd = platform_get_drvdata(pdev);
 	struct input_dev *input_dev = kbd->input;
 	unsigned int rate = 0, mode_ctl_reg, val;
+	int ret;
 
 	mutex_lock(&input_dev->mutex);
 
 	/* explicitly enable clock as we may program device */
-	clk_enable(kbd->clk);
+	ret = clk_enable(kbd->clk);
+	if (ret) {
+		mutex_unlock(&input_dev->mutex);
+		return ret;
+	}
 
 	mode_ctl_reg = readl_relaxed(kbd->io_base + MODE_CTL_REG);
 
@@ -325,6 +330,7 @@ static int spear_kbd_resume(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct spear_kbd *kbd = platform_get_drvdata(pdev);
 	struct input_dev *input_dev = kbd->input;
+	int ret;
 
 	mutex_lock(&input_dev->mutex);
 
@@ -334,8 +340,13 @@ static int spear_kbd_resume(struct device *dev)
 			disable_irq_wake(kbd->irq);
 		}
 	} else {
-		if (input_device_enabled(input_dev))
-			clk_enable(kbd->clk);
+		if (input_device_enabled(input_dev)) {
+			ret = clk_enable(kbd->clk);
+			if (ret) {
+				mutex_unlock(&input_dev->mutex);
+				return ret;
+			}
+		}
 	}
 
 	/* restore current configuration */
-- 
2.25.1