Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5650469ybp; Tue, 8 Oct 2019 06:21:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5mIB8i7QROlwoO1IXUxVU2FhzR6lg0/vouaJxeWTCogqkVwFzvcswndDba1Z3OFxP2Xw0 X-Received: by 2002:a17:906:b316:: with SMTP id n22mr28542992ejz.54.1570540915799; Tue, 08 Oct 2019 06:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570540915; cv=none; d=google.com; s=arc-20160816; b=C2Ipqjxyf8LmulCPYV0Gg4/A5TWZ+/J1GYLMpOxRfEEKq1kuEXAl3nREl4QUL8BH+Y Md9iYbw+HFrknttKxW2+jPLuUJ5HU2Y8icBSo7qq9zQFTKkgAHHwcW92tZP824u0kueD EmD1dJl0JKHWQrKXvumL2swC1F0G+SvS9PrkvTQB4oLlK6wYl+330LfEjoYRI99sfQc8 oplvfN49Sa9/MutkHYXIxi1GBZRLeOmKyLXdu/Oa7Ps4bj1p0Cgn0Gz6sVnwo99iKFsB BNUXEfRgWfKQpm1yH+UqtryfBcNRauc159CnIloLofu1Z124tZ2cY0XxNEIGf4BfXeWe 7Fsg== 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=zRFXe3/XZQCUi1W0+GR//OOmf/+747T61SkEsMl88/k=; b=Kc+RdjRqZniLZQFReiv+kd1iF5H5a0sJ3+GYi00+YMlLaw0ez+c6ngk+g7qDja9Zur BdiCCVOZ/xweaUSYMUz9lrfCJymztsFQMeq0MgIvP8PSg7XqFbpJ1VI5s9rOEIpYG3MM BD/Brtjn0aqwwx40Aup0/QtMaT9qyUgGt9zgytbU9xcmHOKNu+J9PIdHx3VdYj9f5hLx OrkLFgKgssLZi6UwV/Fd8hGh8/ERXCtPNY2tivosYdNK0at2qMH8phQNib+HeyGO4FvV /KJCpXs5EtTjY7CcNLv4+PMME2AfLU7z9UIg37WWL3WYkwHnCEcPq3JLggczavRv7IvK cDDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tZfC1OM8; 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 h17si8754721ejt.173.2019.10.08.06.21.32; Tue, 08 Oct 2019 06:21:55 -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=tZfC1OM8; 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 S1731104AbfJHNVK (ORCPT + 99 others); Tue, 8 Oct 2019 09:21:10 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39844 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730332AbfJHNVG (ORCPT ); Tue, 8 Oct 2019 09:21:06 -0400 Received: by mail-wr1-f66.google.com with SMTP id r3so19417063wrj.6 for ; Tue, 08 Oct 2019 06:21:04 -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=zRFXe3/XZQCUi1W0+GR//OOmf/+747T61SkEsMl88/k=; b=tZfC1OM8yntNwmeY8DAkjskgZ4slX04meu2wTKakCs13kvAbXSBqEwTrQ9aC2yuPML OHcDHrf/kxg7FZQc/bw5zY+4gw2NEUUh+Kan7Efd79O7lwR4tYdG5Ez1HZlIt6tnd5g6 RQnyvNGFQZCIWBeImePzvn0xNbkGynWCXxsrKdMTufPSnkx0Nw6NgQD/t19klEMPlGia +hbI4WRCv7GGXO50twrjV6esz8V7EnR3akgbWjXhCwYSEvIvCzJ1AxoPB2Mg/6V1KdUE 19it6wJ7xMQ7755HDqWvENvwa/+R+1Kxtl2IQxVfBH7Tp1Eb6cujDx22F/QNnXvrxBnd zaSg== 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=zRFXe3/XZQCUi1W0+GR//OOmf/+747T61SkEsMl88/k=; b=iQ5RPcojrZZuoBYuxqZUCSSya3YRisBa/lJVY3bD8F957bc8rZKqKMGf+cEhqtAvGH iwiODhgTeM4qPAkbv2UPok4WJwXZvnsTz+gqJDYiP/xJs98LzR2nJxlQGxuxstu4rWdS uzlvN3Pcv01UAnC6+pw6x1ZEs3/zqczGkR3/3AQWfUSIjqsnLw32p+LHDpCDJqf9j2s6 3kApJJEMZd0NJqtxrRmyKzRviTmq3O0kHM9xIkO/8ooCn8x3mV6epAdJ8XuJwqiqeKkR N82/eB8vTmOIe1JQidT9IyNhsjgggs6bZj+NwiwsBSO5j1Vyr8jA5kGrxRv9bipbY5jQ Uk+Q== X-Gm-Message-State: APjAAAW6nEutZxX/zkb7vlT8T3vxtmNLJIHclyNmReVgFtGfSdK4qlAO 2q/AUt6nSUmkq7r/R8YrqX8Hfw== X-Received: by 2002:adf:9d87:: with SMTP id p7mr25812577wre.245.1570540863921; Tue, 08 Oct 2019 06:21:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 06:21:03 -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 4/5] kdb: Improve handling of characters from different input sources Date: Tue, 8 Oct 2019 14:20:42 +0100 Message-Id: <20191008132043.7966-5-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 if an escape timer is interrupted by a character from a different input source then the new character is discarded and the function returns '\e' (which will be discarded by the level above). It is hard to see why this would ever be the desired behaviour. Fix this to return the new character rather then the '\e'. This is a bigger refactor that might be expected because the new character needs to go through escape sequence detection. Signed-off-by: Daniel Thompson --- kernel/debug/kdb/kdb_io.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index a9e73bc9d1c3..288dd1babf90 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -122,8 +122,8 @@ static int kdb_getchar(void) { #define ESCAPE_UDELAY 1000 #define ESCAPE_DELAY (2*1000000/ESCAPE_UDELAY) /* 2 seconds worth of udelays */ - char escape_data[5]; /* longest vt100 escape sequence is 4 bytes */ - char *ped = escape_data; + char buf[4]; /* longest vt100 escape sequence is 4 bytes */ + char *pbuf = buf; int escape_delay = 0; get_char_func *f, *f_escape = NULL; int key; @@ -145,27 +145,26 @@ static int kdb_getchar(void) continue; } - if (escape_delay == 0 && key == '\e') { - escape_delay = ESCAPE_DELAY; - ped = escape_data; + /* + * When the first character is received (or we get a change + * input source) we set ourselves up to handle an escape + * sequences (just in case). + */ + if (f_escape != f) { f_escape = f; - } - if (escape_delay) { - if (f_escape != f) - return '\e'; - - *ped++ = key; - key = kdb_read_handle_escape(escape_data, - ped - escape_data); - if (key < 0) - return '\e'; - if (key == 0) - continue; + pbuf = buf; + escape_delay = ESCAPE_DELAY; } - break; /* A key to process */ + *pbuf++ = key; + key = kdb_read_handle_escape(buf, pbuf - buf); + if (key < 0) /* no escape sequence; return first character */ + return buf[0]; + if (key > 0) + return key; } - return key; + + unreachable(); } /* -- 2.21.0