Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp805129imm; Fri, 31 Aug 2018 13:53:58 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYhgaHLg1pa9TIEx7ISAezc8V7J6i3w6r5wjigV5bOdls9KwlDzzl3ojG2PtONyPkSRR7GQ X-Received: by 2002:a17:902:24e:: with SMTP id 72-v6mr17289233plc.74.1535748838222; Fri, 31 Aug 2018 13:53:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535748838; cv=none; d=google.com; s=arc-20160816; b=NnUFsmDMByj+CxL8UjNzIN1aUeyiXhyV+9oxnMIPMSvLSmorr/ZEeUBtuDL+ObB3nu /nSFaTRjgNwx87BW4TIzjI10IZLOuheENMjcgkVOCuWKE7f4nXoAQa9AQsfnMk0gTw3q TnZDy1ggtaGevMRFdtyhfFCd0GPWp5n3OlDkUkBjuIPdIvSP7ry6DI0lXwnFKTUlWo4e uTfOvoE11HE7GeoZtkFNit14v1xaK92TzAargJ081UtMz+bEnymvuPE3DpsdawJ1mvR+ XBY3JhvlUP4qno8hjkdr6qG240hMnpxexrIuglqGs/d9PPEmDdYOL+upMQpXllpRrZSt 69Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=HK5LT08ykmG5YwLnjISm/Y2crdQ/7wW+cXZ1BfyQFI8=; b=feaxHb63pgQCCQQPa9UYsobjElud4jHAkwW/tkcmpfaT2aSBTFR5UIv9/loEA90uej kfgs6Pw80qQAfpKKKo349yyFbHUZv+MOd0V0qX2+OA/Ju7sCK1ZE7Bw9g4TWxidyDdPY qouA6qT9THt4Ncu3/lfg8TtjkhiIVlqmu2YKOm5VXlYDjIXOtCzOE0JqQtPdkpWCEzJo mXYQ0Mxb6hxJeCstRsUWW/PvW0kurP3Bvclee1t16/TGaDuLWvMWlbt1TF6KGY+eDYSe tlbucB00dec1DFRs+eURwKgollvSBKaCE/2Rj2ui6saDJ9jOK2NbURk+XpRQICzoUjKv mjTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R0hdD9u6; 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 b2-v6si11338028pff.192.2018.08.31.13.53.43; Fri, 31 Aug 2018 13:53:58 -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=R0hdD9u6; 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 S1727743AbeIABBq (ORCPT + 99 others); Fri, 31 Aug 2018 21:01:46 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:52700 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727561AbeIABBq (ORCPT ); Fri, 31 Aug 2018 21:01:46 -0400 Received: by mail-wm0-f66.google.com with SMTP id y139-v6so6299539wmc.2 for ; Fri, 31 Aug 2018 13:52:32 -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; bh=HK5LT08ykmG5YwLnjISm/Y2crdQ/7wW+cXZ1BfyQFI8=; b=R0hdD9u6TBA26WHr0G785Fv+iiZjdlo4tQoCdlURoSmI8I5e5471pL1xQ4uATFT7SJ 5MSUZgnlEmfDD8JaxBe81kzMO6iOYcQ2lxZ9Tw8Zezy02EbG7yEoIzRvNHyfdJwc6sfY 73B8keRHLKkH4BSiCoIyvSyXImGjjjnfMXHnM= 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; bh=HK5LT08ykmG5YwLnjISm/Y2crdQ/7wW+cXZ1BfyQFI8=; b=feRN2wkgrmRSzDw11Zi/VDbpzCiE9v9t0T7HJig9LH/daqf6eo2UsNP+nQEWT2akeU qynClNLC8ahNOuKU4/+s3dBlF4sA98C6ikFkrJLG6uSU9RIyCuSdyYJ7Dm6U5qrFMCDY 49WpjDZR358p+Kzp13ui+CwahBCAdGFa7nafJh7OYXu3Jq2z5d1mXlb+Gj4xDzRPBWVi JDTE/z9hP31w133/CNDxlemXhZCjvnnLxEWNal+MDktg4Yeu6C2Rs79MI5mmP9P0BtxD S6gFETP8hFLCmrLY8gNTFS0rXf9tG7UHpIQAW23H965Wzll35zKE/HdsaXhk1zoND6mP SjjQ== X-Gm-Message-State: APzg51CqcNR/9xtSAuLZ8yCa46WGKGFB2pWkSQ2YyOJ1owXH2x7uO3Z6 4trdozDFzCyCmHSzzs5WAI7Abg== X-Received: by 2002:a1c:f001:: with SMTP id a1-v6mr6040620wmb.160.1535748751991; Fri, 31 Aug 2018 13:52:31 -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 u4-v6sm7659356wro.47.2018.08.31.13.52.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Aug 2018 13:52:31 -0700 (PDT) From: Daniel Thompson To: Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH 2/5] kdb: Simplify code to fetch characters from console Date: Fri, 31 Aug 2018 21:51:39 +0100 Message-Id: <20180831205142.23609-3-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180831205142.23609-1-daniel.thompson@linaro.org> References: <20180831205142.23609-1-daniel.thompson@linaro.org> 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 e54e1e185c47..0ba490728459 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.17.1