Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5652433ybp; Tue, 8 Oct 2019 06:23:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzt3jH9FmZNvcAskZH5VsM/4/WgDRAlFhx6y43ei1h6AtrfF3kB090NHfU3YsJUOjT9OFn0 X-Received: by 2002:a05:6402:1549:: with SMTP id p9mr34258311edx.221.1570541014131; Tue, 08 Oct 2019 06:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570541014; cv=none; d=google.com; s=arc-20160816; b=EoFxfI0RIgTW7ouKH8SRiy/5CGQWAopjLGhbtHnqWISgcG0wf8ODGIKF1b7iGXZbaN vps22IpZ5D4Y89VziLdJI0sV0IJrrNzwcbEwR00RYgPAPqsrI+vXUYWquQDpKQ+vTLWr gRb+ZUeRVcBp+eK9YnDT3XQtO2Lk8gMixVTfg1vcg6uRUlRnrTe0e8Rs/YPMuEynsobO 19AMAaKB7nFj2EZUwKUvlC/3K03SNu/G04hBuKp8JOjRCK0A824J9x/vz2BV7Dxl5e2f t6jnsDwy5xM4OLo/dtcUtDWnGoYmMIa+I6ZfUHMNLehmwI7wjX7dfWcCi9x6BV7uOqN1 XDtw== 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=aow4Ms/uS5HYvl47E6APw8x/hPXJ5HEyt9xExUwySdY=; b=Jgi7+IbOY36KNzEwAQmkJiDR0wtpzmB4S7rFdAs2J0yowfYAu/cFIPlM/tyJ4JnTjt me1TaMtjsv7d0mSnWFNq+dPg2f/YAdG9VfekSSxjB7Qti6WTL+vme25/iiIvzpxqk7Su bXiLdHq3oLfHQUhCmoHq3a1iaYnwmAO37nGH05wzKV5bmJ0TTQTUZLdGAeKXMZN7sqTA qdLSzDgsiRg7OqPVnXCkUxrp15FLBJU5uxMtNPJBKt//jzlJfmusGe2u+izi3NNnlJwR Qj4EKfba7d6/XCovzyEzmTTZ7OzJf1ps1WlKkbMcd2eMIWP8DbZ4k3DhCWMA53lLbl0i Hqng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wwNfzBdw; 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 m10si9661480eds.428.2019.10.08.06.23.10; Tue, 08 Oct 2019 06:23:34 -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=wwNfzBdw; 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 S1730797AbfJHNVD (ORCPT + 99 others); Tue, 8 Oct 2019 09:21:03 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41324 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730332AbfJHNVD (ORCPT ); Tue, 8 Oct 2019 09:21:03 -0400 Received: by mail-wr1-f67.google.com with SMTP id q9so19398063wrm.8 for ; Tue, 08 Oct 2019 06:21:02 -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=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=hg+AK+73VPeF8mwaSs5nXCdDaMZoYbNIpWeJJiJFcGnyN73ds+NmwG1kCfx4imMdUC BUJQzZtuui0k7F9yH2Wa2ikUiOpRLtlBa7F7L8Tr3EiCok27hXO9dbLI6FvE3JQkCvK8 Fm6t+b2LctiC7xvL/BT02Xwf+P2xqaBw5ciHFqbtUzhYEBS8O0vvKm7FdrKMngy0l5ya u0u4bRcwZcUGulkUJbKowe1QiBJ5OzCZh7y7wRBbPvhnvvD6UKMAhWCAi4joVq3757Vn pxY7+KVuM/mXPudpil+epBS5gq3RObIH4CaqG6qfcEgejRFO8WVBKeOeSP6rMaGOZ+N8 HSJw== X-Gm-Message-State: APjAAAX1ywjokVqu0usiuJ6ng01ZCEE8lHL58LnLrkYS5xMamXmLcU/W 0fraTOXiBv9pWob974uk9FT3Nw== X-Received: by 2002:a5d:4c45:: with SMTP id n5mr28870355wrt.100.1570540861496; Tue, 08 Oct 2019 06:21:01 -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 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 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 --- 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 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; -- 2.21.0