Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4747960ybp; Mon, 14 Oct 2019 09:24:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCtWGZjsfeVvkB0+Mfx5pLWgncnUeq+uwjzwhJ4H3TsaHNv/5tsidqVdOqClBzc5o23G8s X-Received: by 2002:a17:906:2c5b:: with SMTP id f27mr28780362ejh.239.1571070255888; Mon, 14 Oct 2019 09:24:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571070255; cv=none; d=google.com; s=arc-20160816; b=VVra5EN+VEPDdMT16aDrQs9Ir3Hz7MKTv16d97qNdzzwKjU8rAjlVxTT98cQs6p4ZM B5HE9WChi16gpZRHnu6quAzMxdtcKAZsgbjaFU+LUHTjeJ0VDCoUpEZW6NeFuagzZCBN 9qWXJWIoM9q/tbqPUuwLgkqdikKrT15yPb0E0/j28mqKwkB/uvi9toMLXl2fyMFiQpOc LZU1GG6jO1ybqz06JsMhw8EsQc9EDp0eoMZokhLWnngbPqAILtfZUcP8gCbnLmN9k6EB FZ+//cIsfo0Z3/j8GzE12LQdDdkj07aeauzlIbRx8FVmVGP+P1HAk9z5gBaFJ3v/jFt/ f1Ow== 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=7kINXNWWBt4SCXZfRMWNijcHokD4yWzFteamr/of+Do=; b=tYY9eG9q54GfQyR/UQkEpuwBZLQW/LecHuVUGNZ5VmL4mHR+9iIRC8a4jCrIVg+tR5 Hcfa03e93jyGcU+NF+sziDQ4id3OrLcjNXGyXk8OXWQw7b41eabUuAd5a4aF3Qzcunde RztsXcOhs0Dh7EC2bB+te6BMQ438C4gAf9ZVNRhFYs3wPKbe6W/ZZ6vht8cjTgzWk11c hdMBD5w6+C2W2HqoEwhYlYQcpTpEMxO0x1a6QmUaTc247K8Gq9NBDHT94ksbaMXUupuz lY6/Qtqwv5/9anHg2I8xSu/UzZH36gqrC4QnAxBGqmiv7YlFebuRSRVF2jsqg5l9hUg+ VIRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wDcXON+1; 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 nh5si11337073ejb.154.2019.10.14.09.23.52; Mon, 14 Oct 2019 09:24:15 -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=wDcXON+1; 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 S2387752AbfJNPqh (ORCPT + 99 others); Mon, 14 Oct 2019 11:46:37 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38739 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387729AbfJNPqg (ORCPT ); Mon, 14 Oct 2019 11:46:36 -0400 Received: by mail-wr1-f65.google.com with SMTP id y18so10856906wrn.5 for ; Mon, 14 Oct 2019 08:46:33 -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=7kINXNWWBt4SCXZfRMWNijcHokD4yWzFteamr/of+Do=; b=wDcXON+1m4xAvti7aNKoc4cwF+oGVBwBFrv+CuaZGoSXIxoadjTCogRb+8Gi3on6Ph X63WBulioLHClOM0wy48u5QXBnY3CrsffaJ2GHcPloBlVAj++z0zpW/CDqgyaHy5fWTP Pwpdx1VDGTtMbhaW1dOfkNWCcevpdo4dOOOzoIHkYWHV1zahTUyITHbfcmukOpiGFMlO IFRLoBaAzPD07oiavJbvoyFk5kL4bPekWz+AATsk+e/gpmdjWIk/IV5vEINYtMuCVGhC NnEdyHXGWrKNpAucuRa884MReYJfDNCM0GK1o+cHtotwrwIeG9gwhmmf3adlrbyyvx0n 4Sxw== 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=7kINXNWWBt4SCXZfRMWNijcHokD4yWzFteamr/of+Do=; b=GKViPMBuktqCdiGtx26XrFeOXGTxwpTLcAoCiFy5/EcSS39Qfwcf0JnK7OnSMZGoP9 JTJ/WpzDe148hJYij+6xlvh33VKlGKAffcYFQruvvje6+1Qyml60bjBs6UfYKoZwUdRE ozUqJP1P55D4LMcz2t1YKi6R4pk5vC6kDItO22+2/fi/YmoWZEldcnINuvAzTDG9blga oR7VYRJtReFO3FMV74XvCo7kKnUrkomWLb876YUZfG22jQYjo1rSnAvn8ALMtNaGzMeq aaB6K/QwB7SnCvQbKFd1bTHglacWuhZ4cOL4uWFuBkjypUMIOuKzPtAkqQgmaEH7dMAq q4XA== X-Gm-Message-State: APjAAAWrGt4F7ZLwpo4jcuCpXElXLOmduylgd23/GYIFRxVdRgIEWUi9 wPdOfcjCnVC8vb8tHO1wMpC9kQ== X-Received: by 2002:a5d:4f8b:: with SMTP id d11mr10159794wru.25.1571067992613; Mon, 14 Oct 2019 08:46:32 -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 q22sm16539738wmj.5.2019.10.14.08.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 08:46:31 -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 v3 2/5] kdb: Simplify code to fetch characters from console Date: Mon, 14 Oct 2019 16:46:23 +0100 Message-Id: <20191014154626.351-3-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191014154626.351-1-daniel.thompson@linaro.org> References: <20191014154626.351-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 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