From patchwork Mon Oct 14 15:46:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 176258 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4682865ill; Mon, 14 Oct 2019 08:46:33 -0700 (PDT) X-Received: by 2002:a1c:1f54:: with SMTP id f81mr16268102wmf.142.1571067993169; Mon, 14 Oct 2019 08:46:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571067993; cv=none; d=google.com; s=arc-20160816; b=rJWTunB1yqffX5ryIm4Qf4kdG7clgLbYVxljonAqWnaqIei6DduculIcykUP5xikY4 y0MQQPKp0wRLCfKTTg57gqADvUhvIukho9EXPKWbZa4kOaQDeJtmtWrmLowsAxRqQdyf d39zIRNcyRUN1qPYi+o962o1TJ34Xl5uml12Pxu2BOy9dySGAlmsBEPjm1cyz/YFfxB5 NCpRev/0GzssY+wFdNXlqWvqC9STNNxsEG6eqSToHvXkK79zHa+udBWkruacd5AM6YvI P/+oiqy/mCYm7Tr6G9aBOc82Iy2DMYFRCFpfSvaDcjC9ilmVJFRgxOqFpNvAH8VHSrc2 XcxQ== 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=7kINXNWWBt4SCXZfRMWNijcHokD4yWzFteamr/of+Do=; b=manB9DmLBcBLfkS1Ffn6Z2+biIwCODlaumaU4ZLuWjHJSOpKNV3IO6vKxUfRAuKTEc 7c4/Ki+DpenBTaIdJIA7HEfZjICkL+AUmzq87NVR5ZVaXns0voGdi1QuHhGqXdNuwMHH mBbNWj3LjeNE2FqLpmhQLb+PmHyaq6V0xsy0hxJzyjV5YcsOmTJ3XjseANYlliHD3mvY Ym0lZVgDIliORLdw1SiaT4iIBNMWlW7pPrIi/M/veedosaEYWLSvKaXEIWqse737wqfP D/0U+MtG+mdZuCymIfR4u0gFMbOhRBzZak4P3lYbF+i1fKojk4xsOcU95lK5LhJ5iTyz wGwg== 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: 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 t1sor12297513wru.46.2019.10.14.08.46.32 for (Google Transport Security); Mon, 14 Oct 2019 08:46:33 -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=wDcXON+1; 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=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=SoFP+ge4/tU6AUSlXqMY8wFYQMIZmxegAhkkQw7k5X2cC/Ko3IxB/gW532cCh8uOe/ CgjfPq6LoWx8iQZ5POMixStvYu+79R3lkfwj64s0fnp8I9tOLnLP4Vd1NBREymncbWvp W1ZaN3p6eNVtPJSJhzk0+JPQ+cx52TgFP8mxyzUHk606Ym81U4cRmjHqfXVPWH5+NWDc eQk9fYig9qNLXhilD21uZoi0OHwN/lGLaIIugJ+6zMDZC2zQmwAG6xj3fWQIGFkqOkZH tIFjPG14QBfQ8YHul/08Z1zVrWmm/gnXqjcZLBhfu9tsRACfoRoRRqai18qPfqSigOfn +zNg== X-Gm-Message-State: APjAAAUcpFsX7gXpcGK6AkIGh30m3wHax2QIgiGKR98jxQ8OPgg0crpm QBcSQp8IfmQUZ8x8RFc+ZDoIp6EO X-Google-Smtp-Source: APXvYqy0ovnoys29DS6SHPRM492SOwp8R433s33wX1W4a85GrfH/w2L+Td6L/d9LtZee3kn3EjlN3w== X-Received: by 2002:a5d:4f8b:: with SMTP id d11mr10159794wru.25.1571067992613; Mon, 14 Oct 2019 08:46:32 -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 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 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(-) -- 2.21.0 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;