From patchwork Tue Oct 8 13:20:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 175495 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp5695270ill; Tue, 8 Oct 2019 06:21:02 -0700 (PDT) X-Received: by 2002:adf:bb0a:: with SMTP id r10mr28074831wrg.13.1570540861970; Tue, 08 Oct 2019 06:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570540861; cv=none; d=google.com; s=arc-20160816; b=FQi+YoFEw9Dmoo+RFhZfUx+VDSxTD4vQHqkldGgexsbhn1RuSa1EEtj/bKr0gxrW3o SUAwgEL8j573D0dvXFycaA9LNZKxdnHQeU3iCUjjDmC8N1pdXcU/Uq2oA8PDHKPpXyTn u2NoA4T+opavClhyrdfgHcNM24yL+d8WmluZ0LmkFZ0VFSaczYfT+Jcpcs8Q8BgQ18io IYM76DUAZRG8nnFGBMgYvn7LyFcwKxETni3XU4AsgAJSXSQQl7Ad+/N2jx1xqA8OxHp5 tpDcVFcjj6Luwg7si18KkGFbVPhRuvqsNl36KxARoSlI+sPoNljfSehTueA3tcuhxqiT gvmA== 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=aow4Ms/uS5HYvl47E6APw8x/hPXJ5HEyt9xExUwySdY=; b=wTvUzpx7v7M5nw1TFDLYOpaPmM00XGI+PWD0i0aSF+FkgQFEVHJbJdtrCZ0zzZHrlC CHW7ZnPYVWpG4vz2EQgCmDV/UGU2M7Sat8NUgNFqZnQULvZXNhJECUuU8L+pTAxo8ov3 70tEpD72WW3kFssOlHH3c3pb9xRWfpaHLM1KIZiTLDqaqZVzIK+U5kqKsnE3zoutpu4h ZlznZaml4SS/j1n5JJ91RLZ0J3y7wBV/M1ULh2sR8JlBhn7W60QXewZ9D+oI7jTFkwfP zSboovVsZ9iQ5D1aMAJpMhkq9OSLeLLDpsW4xGHnzxsOtIKmNwuohmkVo4mU50i+inRp D2/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wwNfzBdw; 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 r10sor12111022wrx.23.2019.10.08.06.21.01 for (Google Transport Security); Tue, 08 Oct 2019 06:21:01 -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=wwNfzBdw; 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=aow4Ms/uS5HYvl47E6APw8x/hPXJ5HEyt9xExUwySdY=; b=wwNfzBdwi+tFi4BAUOyHRxO6sorSM8lVJ0f9OAf/MSR66X2lKs83f5eUB33YApalVX DfbAID5zJHC+4shWyp8zC0I5X7YkdXjVNfcPkPirASMdmdzhHb88bim0n/2batTqVJRv kYf6f/zuRO1fawEMpXrpt5Vcy9AJeeCIMNkIN6DefjZgQuTONg9Ksi85K/qNK8d1fjOd 5Odbk25PcC6sEH/YXIndJQ3+1wr1dhQJ1tlKpH6m9Nz4M6cfo9oAL//ZU0WNas+QuqxW hxPYxi4BPjP2kqJTiBFgC1KlH/wbh1kGeQ+d+qSLmHkzQLK69ZjQzM/6pWFChJh9YXzs a/gQ== 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=aow4Ms/uS5HYvl47E6APw8x/hPXJ5HEyt9xExUwySdY=; b=BcTwLuH0PDYi27JIK1z8v2q0nBlYhuTzLpx7n0TKjf5F1UcUNKmjG5q6UOq1IMSaaD HQPbpr1685VlqtLqwAuwcEE6b7CHw94BhhEPmZ6MBJsFoHt1GvCpxOgyh/kLeSG5J4ao IBdgv9nITDHg+lopFJVcc5AX5oaJfHFPWLw+PGvjEpD5V+JaXtkjO/YJeE0M3uZFniDq hqpx8mlvony8AZTKEt3N6iI0ur1cbbu0jawBHhFHJwU1OfDLPdnw539JC6QrEOsOca/e CLutSi4dd02rzssI1tyq5Udn+m379khHHQ9lUqMEvFyrt3Gsu5ibz2aT954/BOkpIPdf LFJg== X-Gm-Message-State: APjAAAWQHmWBS87yHFA7uwdB/hFvN4xoOvYg4IPtRIo0doYftYJap1Ox 28Ojw0lFs0yyOHDew1oAU1l/5MSO24FyOkLs X-Google-Smtp-Source: APXvYqyS4GHDWXh8kUnxEPgegNjfoS/nOujwEIaubur1wcA3ko8QUV+4bqOePx6mf8a6cIqbdxBmVQ== X-Received: by 2002:a5d:4c45:: with SMTP id n5mr28870355wrt.100.1570540861496; Tue, 08 Oct 2019 06:21:01 -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 t8sm18237214wrx.76.2019.10.08.06.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 06:21:00 -0700 (PDT) From: Daniel Thompson To: Jason Wessel , Douglas Anderson Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v2 2/5] kdb: Simplify code to fetch characters from console Date: Tue, 8 Oct 2019 14:20:40 +0100 Message-Id: <20191008132043.7966-3-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191008132043.7966-1-daniel.thompson@linaro.org> References: <20191008132043.7966-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 --- kernel/debug/kdb/kdb_io.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) -- 2.21.0 Reviewed-by: Douglas Anderson diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 68e2c29f14f5..78cb6e339408 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -122,25 +122,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'; @@ -148,28 +141,25 @@ 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_read_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;