Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4042365ybg; Fri, 25 Oct 2019 12:29:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqw3LO7OeGWwyguwQm11sZR2WuoHTAQwc4icQQroP45N3jamOQ3FC8C2LXQCFqiXtNhbSNDe X-Received: by 2002:aa7:cf83:: with SMTP id z3mr5926551edx.198.1572031763865; Fri, 25 Oct 2019 12:29:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572031763; cv=none; d=google.com; s=arc-20160816; b=OkfpQA7S+qSN4VZv2J3yLlUNzcVNu65PjFW9Kb/hs4CBznD8AgcPoUKYx/AkT7htQQ NS4IK4CdWvODY/z5U4JMiKP+8Ap32bzMd0LoNTHKXXZlsKhiV07zma9TCZL2u9MK0ekQ 0+EpKcYAgmTQKSOXmL3S0AuGEI9nEbKPqTtGAk+aRI3/P2arJ/S4Ug0/qANXeAzr1KSz ZXGFMv0dMfaNov20xQj/gSy/77yTDfpNJwNeMJb0JU003w5Oo4sbrrHYLtPl9yoxYYnH Ds9aWpxy/Z1HLQIHVASe6TMyWe6fxTgd03JGFJmasZuSIfDS5KC4ZIYiWJzZ16eaHKOU 6DLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=N2ThTAgeoHW31mlsGh12ha2Pd6KE6BHGLEXeQ2AbFfI=; b=j2JcIk7/A+QKETW9o8CJE5e3+y7+hwDsYdIOO1fz0D5hIDVzM33tZkwjqggvZuZJQl 5hAyRtHkqEYrgfLwW5HRxEof2jirNwxzF0iQ9y4DhksXl6kF50Hz7cJx4ElAY5KJUWZ6 lm8TkGVuKDGZlT4B8/6Wc6pCLa1NhwTxdTE5kUTDeMCnf2d1St3tN297CnTO7qOqZH35 OHYG60WAnZ/xGZXg3ODwZoLkCtsfjkzQJ0BCpv+WkIA+hLrvxtUkxwNrPKAgc7PByEws JujrDft1dIAquiAV8jshG3x8v4N23MUVQPM4CT0mTSNcIfsIywdj9nPTNVrk56Kmft75 BEgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Cvs9FoyY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u17si2172224edb.365.2019.10.25.12.29.00; Fri, 25 Oct 2019 12:29:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Cvs9FoyY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394310AbfJYHdq (ORCPT + 99 others); Fri, 25 Oct 2019 03:33:46 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:56095 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726479AbfJYHdq (ORCPT ); Fri, 25 Oct 2019 03:33:46 -0400 Received: by mail-wm1-f65.google.com with SMTP id g24so910960wmh.5 for ; Fri, 25 Oct 2019 00:33:45 -0700 (PDT) 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=Fo7Nlbsf/phcBxHMoq1V1zHZDVBFK0aVdRMvm6BKMmtw9tEHwRnvRj1iILlONKqLRr AVe1iq7u3Gxz4dx1y1xmYGlb15Kxq1CAjU0Ip7HCcs3324pCsLc3LxdTNYyjMPQxWXBe G88LdBs1gLjr/kYXF69hhpSel7XR6OAYFh1JSNn2FN61IP1WP7OtNZCb3ZvrmTryBduh Q1kXqTEH4dJ9uxyR1gy2VdyKdk0wZ1XbbfpjgvE6+zNGdKUfXv0Cn5mEjjW+KaAES5Hs KhXh+cV9UD3+qzL7vZG2BnUIreIf+sKgFTkm4P6seNc/g0dUO5mZOprWl02PJA7xcN4v 8goA== X-Gm-Message-State: APjAAAWGUqjAh05Ge/qoXp2PEWhd8crCHGPy9ErIIY3tuIChQQUJOpmP V1H6zagqhBX7xzJ5h5lxlyiOo0x6+KHPFQ== X-Received: by 2002:a7b:cd89:: with SMTP id y9mr2191028wmj.51.1571988824531; Fri, 25 Oct 2019 00:33:44 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) 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; -- 2.21.0