linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: You-Sheng Yang <vicamo@gmail.com>
To: vicamo@gmail.com
Cc: acelan.kao@canonical.com, allison@lohutok.net,
	dmitry.torokhov@gmail.com, info@metux.net,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	rafael.j.wysocki@intel.com, swboyd@chromium.org,
	tglx@linutronix.de, You-Sheng Yang <vicamo.yang@canonical.com>
Subject: [PATCH v2] Input: i8042 - fix the selftest retry logic
Date: Tue, 10 Mar 2020 11:36:40 +0800	[thread overview]
Message-ID: <20200310033640.14440-1-vicamo@gmail.com> (raw)
In-Reply-To: <501e8224-e334-0aa8-41c0-8f67552e7069@gmail.com>

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


  reply	other threads:[~2020-03-10  3:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-05  6:44 [PATCH] Input: i8042 - Fix " AceLan Kao
2020-03-06  4:16 ` Dmitry Torokhov
2020-03-06  6:40   ` AceLan Kao
2020-03-10  3:35 ` You-Sheng Yang
2020-03-10  3:36   ` You-Sheng Yang [this message]
2020-03-17  4:22     ` [PATCH v2] Input: i8042 - fix " AceLan Kao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200310033640.14440-1-vicamo@gmail.com \
    --to=vicamo@gmail.com \
    --cc=acelan.kao@canonical.com \
    --cc=allison@lohutok.net \
    --cc=dmitry.torokhov@gmail.com \
    --cc=info@metux.net \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=swboyd@chromium.org \
    --cc=tglx@linutronix.de \
    --cc=vicamo.yang@canonical.com \
    --subject='Re: [PATCH v2] Input: i8042 - fix the selftest retry logic' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).