diff mbox series

[v2] Input: i8042 - fix the selftest retry logic

Message ID 20200310033640.14440-1-vicamo@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2] Input: i8042 - fix the selftest retry logic | expand

Commit Message

You-Sheng Yang March 10, 2020, 3:36 a.m. UTC
From: You-Sheng Yang <vicamo.yang@canonical.com>

It returns -NODEV at the first selftest timeout, so the retry logic
doesn't work. Move the return outside of the while loop to make it real
retry 5 times before returns -ENODEV.

BTW, the origin loop will retry 6 times, also fix this.

Signed-off-by: You-Sheng Yang <vicamo.yang@canonical.com>
---
 drivers/input/serio/i8042.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

Comments

Chia-Lin Kao (AceLan) March 17, 2020, 4:22 a.m. UTC | #1
This v2 fix my issue, too.
Please consider to merge this patch.
Thanks.

You-Sheng Yang <vicamo@gmail.com> 於 2020年3月10日 週二 上午11:37寫道:
>
> From: You-Sheng Yang <vicamo.yang@canonical.com>
>
> It returns -NODEV at the first selftest timeout, so the retry logic
> doesn't work. Move the return outside of the while loop to make it real
> retry 5 times before returns -ENODEV.
>
> BTW, the origin loop will retry 6 times, also fix this.
>
> Signed-off-by: You-Sheng Yang <vicamo.yang@canonical.com>
> ---
>  drivers/input/serio/i8042.c | 23 +++++++++++++----------
>  1 file changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
> index 20ff2bed3917..e8f2004071d4 100644
> --- a/drivers/input/serio/i8042.c
> +++ b/drivers/input/serio/i8042.c
> @@ -937,25 +937,28 @@ static int i8042_controller_selftest(void)
>  {
>         unsigned char param;
>         int i = 0;
> +       int ret;
>
>         /*
>          * We try this 5 times; on some really fragile systems this does not
>          * take the first time...
>          */
> -       do {
> -
> -               if (i8042_command(&param, I8042_CMD_CTL_TEST)) {
> -                       pr_err("i8042 controller selftest timeout\n");
> -                       return -ENODEV;
> -               }
> +       while (i++ < 5) {
>
> -               if (param == I8042_RET_CTL_TEST)
> +               ret = i8042_command(&param, I8042_CMD_CTL_TEST);
> +               if (ret)
> +                       pr_err("i8042 controller selftest timeout (%d/5)\n", i);
> +               else if (param == I8042_RET_CTL_TEST)
>                         return 0;
> +               else
> +                       dbg("i8042 controller selftest: %#x != %#x\n",
> +                           param, I8042_RET_CTL_TEST);
>
> -               dbg("i8042 controller selftest: %#x != %#x\n",
> -                   param, I8042_RET_CTL_TEST);
>                 msleep(50);
> -       } while (i++ < 5);
> +       }
> +
> +       if (ret)
> +               return -ENODEV;
>
>  #ifdef CONFIG_X86
>         /*
> --
> 2.25.0
>
diff mbox series

Patch

diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 20ff2bed3917..e8f2004071d4 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -937,25 +937,28 @@  static int i8042_controller_selftest(void)
 {
 	unsigned char param;
 	int i = 0;
+	int ret;
 
 	/*
 	 * We try this 5 times; on some really fragile systems this does not
 	 * take the first time...
 	 */
-	do {
-
-		if (i8042_command(&param, I8042_CMD_CTL_TEST)) {
-			pr_err("i8042 controller selftest timeout\n");
-			return -ENODEV;
-		}
+	while (i++ < 5) {
 
-		if (param == I8042_RET_CTL_TEST)
+		ret = i8042_command(&param, I8042_CMD_CTL_TEST);
+		if (ret)
+			pr_err("i8042 controller selftest timeout (%d/5)\n", i);
+		else if (param == I8042_RET_CTL_TEST)
 			return 0;
+		else
+			dbg("i8042 controller selftest: %#x != %#x\n",
+			    param, I8042_RET_CTL_TEST);
 
-		dbg("i8042 controller selftest: %#x != %#x\n",
-		    param, I8042_RET_CTL_TEST);
 		msleep(50);
-	} while (i++ < 5);
+	}
+
+	if (ret)
+		return -ENODEV;
 
 #ifdef CONFIG_X86
 	/*