From patchwork Fri Oct 25 07:33:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 177676 Delivered-To: patches@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3285972ill; Fri, 25 Oct 2019 00:33:45 -0700 (PDT) X-Received: by 2002:a05:6000:142:: with SMTP id r2mr1501426wrx.30.1571988824991; Fri, 25 Oct 2019 00:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571988824; cv=none; d=google.com; s=arc-20160816; b=zhT4ClQ3YZSU7p8p7ziSlW3KrT825MyDj71KUaxCym1iTfCwWCRmjJQloWHsoQWqrp z4spnfm3auaqMy6emb5DmjEB3j6Okvbs3gkCg4m1yzeDf9j8tYhiM4BlQtoCout6kAxd PourRO0P9L2jAe4dA9mWsuXQLw3w8NFwGkg/viqKiAqbL0wchxiRyvaSFx8ac9Ekg6Oy fy+SqRJgY/9PzMNsGHVeELz/Jx6v0MwIgRF7lYRyTt76goc9Ho5kRL4zFAUs0FlfOHRR bajGcdMapxdRP3gV5kwLFrFKwGKB3g6IZOOGPDFk8MKWNSqwKjG0n313nM1GmaE6vu8r Qqmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=N2ThTAgeoHW31mlsGh12ha2Pd6KE6BHGLEXeQ2AbFfI=; b=keu7ys+CmEmf5T5C0MkJoM+X1P8cNv/a3JDBU1sMkMFZcsjVlFPpCIrJ9G3LANCavF pCREWzSW5gsZpv5Ffs8xtgZwKIHkL00aDNNcU2aWHpCX6IfHliiTV/ZyDQT/0aL/rAlr +7pWK+ah81HjsiH2RY9njIUf4TtLFZNpz7nxDzoHbRPv0GhHtRsC2wFqu2ifXEAhQ6ij FRDcTPwI+v3cyYDLsfjytY98JOqQm5Pxyz8mv4ve+2+zq230k1MIer2Xutney+FRbHM+ l5Crc96YpNSvhfaoKWx1kDMrWkV/HQ+r/Q7CDJM+0SQo+sz9rxjx4M6TGOMrGkb9o/SP FFOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Cvs9FoyY; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id s13sor857221wmj.23.2019.10.25.00.33.44 for (Google Transport Security); Fri, 25 Oct 2019 00:33:44 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Cvs9FoyY; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N2ThTAgeoHW31mlsGh12ha2Pd6KE6BHGLEXeQ2AbFfI=; b=Cvs9FoyYv3MIFrp8WsjkZyLWI7/e8F24s3eJ99R0F1t4im2+jVXGtFQuSpT7wg3scc wsdBc7PXrlNxj22obCjBZy14slZaCxrfheFn1+wmC8Xy1rZaOWc1eQ60VjEYGPp6b/xo iIkWjEJYecuOfoEUGTAsoCrjvgxigmHbtwl2qh4UB2czJI2aNxSxmZ+EedpO2rYEueBe mZWcnRQGeptOqWd2+S6GA59sILp53CTh9fm3jOrMTtjcObFTulfmEGsOM9IQDxcAoRzl j7AIrrWMZL7YrxHf+6bFe9NhFOXQ1RWVWS58lPGPx5ABi9/7dLBYS8ib4dqZ2AQvMOmR d80g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N2ThTAgeoHW31mlsGh12ha2Pd6KE6BHGLEXeQ2AbFfI=; b=nbLpkIsUMHaATSrpXGTVj6SwiustwJepaA3rRUC34ojugrYPFgeITbT2RIKghJptV3 WtCcHl6P+Z+apen7FAYcl58ZYUzX1cD7dJl73pMeQCVcAmZtx+EcreTuxkRMgi4BmepI S5hjScOs0MSZB4fV22U5hoKd0aoR7z5c0ZXjJ0pTzmY53a5cb6LGoKkH0g9UXP9FEnT8 3zDAonDxIeLkn0cUB6acMFCfscerEB5DSxItsEh6EmhMe77b33piUfY0rcrzTdEJdUB1 +4Za8Sut7D1KyTpQigCPn5TTyEijC5ACqnclSSPVeyMH5GdiOjfa23o3p95vw4tXDrvV Y02w== X-Gm-Message-State: APjAAAVZ9OjYoBjV8rtikk6EfVtR8M6qT9cA+rEUwMPJ+6yvJhfVyyVn WGgvHxS0LSnoS1lFtlKLy4IEgtAa X-Google-Smtp-Source: APXvYqwyGKGRjS9F8gjBeH9bcpVse8C1AwyaGfdsUQNKHh5P4Ahfrc9NpXUS5b2AvwtLf8hZ5yKnQw== X-Received: by 2002:a7b:cd89:: with SMTP id y9mr2191028wmj.51.1571988824531; Fri, 25 Oct 2019 00:33:44 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id a11sm1586602wmh.40.2019.10.25.00.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 00:33:43 -0700 (PDT) From: Daniel Thompson To: Douglas Anderson , Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v4 2/5] kdb: Simplify code to fetch characters from console Date: Fri, 25 Oct 2019 08:33:25 +0100 Message-Id: <20191025073328.643-3-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191025073328.643-1-daniel.thompson@linaro.org> References: <20191025073328.643-1-daniel.thompson@linaro.org> MIME-Version: 1.0 Currently kdb_read_get_key() contains complex control flow that, on close inspection, turns out to be unnecessary. In particular: 1. It is impossible to enter the branch conditioned on (escape_delay == 1) except when the loop enters with (escape_delay == 2) allowing us to combine the branches. 2. Most of the code conditioned on (escape_delay == 2) simply modifies local data and then breaks out of the loop causing the function to return escape_data[0]. 3. Based on #2 there is not actually any need to ever explicitly set escape_delay to 2 because we it is much simpler to directly return escape_data[0] instead. 4. escape_data[0] is, for all but one exit path, known to be '\e'. Simplify the code based on these observations. There is a subtle (and harmless) change of behaviour resulting from this simplification: instead of letting the escape timeout after ~1998 milliseconds we now timeout after ~2000 milliseconds Signed-off-by: Daniel Thompson Reviewed-by: Douglas Anderson --- kernel/debug/kdb/kdb_io.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) -- 2.21.0 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index cfc054fd8097..a92ceca29637 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -124,25 +124,18 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) touch_nmi_watchdog(); f = &kdb_poll_funcs[0]; } - if (escape_delay == 2) { - *ped = '\0'; - ped = escape_data; - --escape_delay; - } - if (escape_delay == 1) { - key = *ped++; - if (!*ped) - --escape_delay; - break; - } + key = (*f)(); + if (key == -1) { if (escape_delay) { udelay(ESCAPE_UDELAY); - --escape_delay; + if (--escape_delay == 0) + return '\e'; } continue; } + if (bufsize <= 2) { if (key == '\r') key = '\n'; @@ -150,27 +143,24 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) *buffer = '\0'; return -1; } + if (escape_delay == 0 && key == '\e') { escape_delay = ESCAPE_DELAY; ped = escape_data; f_escape = f; } if (escape_delay) { - *ped++ = key; - if (f_escape != f) { - escape_delay = 2; - continue; - } + if (f_escape != f) + return '\e'; + *ped++ = key; key = kdb_handle_escape(escape_data, ped - escape_data); - if (key > 0) { - escape_data[0] = key; - escape_data[1] = '\0'; - } - if (key) - escape_delay = 2; - continue; + if (key < 0) + return '\e'; + if (key == 0) + continue; } + break; /* A key to process */ } return key;