Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4042528ybg; Fri, 25 Oct 2019 12:29:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFYwu0MNI3FKU3xjyVrBXbKsxX261tKzMJuJRJMhT3IOe0LLgYf9OJPAoBNaZM09hCo4ZV X-Received: by 2002:a50:b2c4:: with SMTP id p62mr5747242edd.128.1572031772641; Fri, 25 Oct 2019 12:29:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572031772; cv=none; d=google.com; s=arc-20160816; b=KtKexcdcj+tU89Q6JiKi7zfyttS4k4/sU3xa6hm/r1N0eXeSzWUN5z50TdYt+zCMgh b+ll3LXLSr6icH16OUNf7EWIa3MNP0XDVbhcKU1KpBMXUvgV7tVqDRCK7BFkXeQs7Bki mdkT0sFn9C7sggJf+g4wPCfJiCi1QPYzCiUsmvEocBMK22tRlBj4XHNvxSEV+JlBSevT 901Q5sa0l2Z3kURLMMNe/BlQxtL9WfJm4HI/rzKWMjG3Nm2edXqGtgyecjYj4GGDT5ne J6vV0nzz8E9IHCqJjdxb/GAIOv5DqtIP/VqE/KYu1eb7gzKYmNGXKQVFUvDo1/6U8RWy NO3A== 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=VxRxdqK8wDgtRtqhN/4fmGim8qsHy1Sh2vs1pQm0S1s=; b=L16VRg6Ym+GvHKJlyfUNy0qqMezJ1HtNTMiWx4NdZJH2e+q5JO+ew8+mNpPsZa85oc kD2N+d1Uk9V4ituwWM1cUAVsIzAiotYk4lbrccXHvVQ/Pz/V5TIBp2FB3/lINVSrlZQ4 ayhT4SciQ06gJVrHtnjwxpZTa71ErBurIpQT3DifFsWvkerRQC+EbdhaN0/jm8VR5bvI BvJmTb33oPd08RIlsHRc18XuRILLohx5/y92sQRwE7IUMF3rTULURwIV9plHp7Af2g+G TNJkiDG9HkmwjIHgzBYpTZQFy2hMhWChNqB2nxSqc84dJ5RjI6hx2g8I9MDYFh8Cs5hq ysww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F5JEpHMe; 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 x50si1968911eda.155.2019.10.25.12.29.09; Fri, 25 Oct 2019 12:29:32 -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=F5JEpHMe; 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 S2406978AbfJYHdy (ORCPT + 99 others); Fri, 25 Oct 2019 03:33:54 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41078 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406004AbfJYHdu (ORCPT ); Fri, 25 Oct 2019 03:33:50 -0400 Received: by mail-wr1-f66.google.com with SMTP id p4so1069788wrm.8 for ; Fri, 25 Oct 2019 00:33:48 -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=VxRxdqK8wDgtRtqhN/4fmGim8qsHy1Sh2vs1pQm0S1s=; b=F5JEpHMej8YX8/tXiqp25sBGpi1nHuIwrK/ACEWIlTPQozJML/KptQdG5HGN4mB0mN Dmj9dtiWrZYX+yR4JK3i5Lrw7hKeW+ZMJhTepWlCKmhVeVGbDNAPXVaKRs49ut5Lchs0 pGD2ZDoyvmprP9o6AMdzq9FkIlo5jzFVLmfO6O0XiN/zFuzIo43Ms3rH2k8+GWNv37wk Aq9mXXxRAIzdsuXmoGscnLJrlSDOetxBr+G4c3kWFlddhFxWqp7ShmIBashpCE7vlqNI JqRXHfCVpcFEjLwlJbT8XxvWOLUMeeWwrzIKjnAHNEPWE1XG74iy+9G1Ok8qTXMOQYad KaDA== 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=VxRxdqK8wDgtRtqhN/4fmGim8qsHy1Sh2vs1pQm0S1s=; b=nTPou0FZsW6b4fvv3+hy7F+or4kb3r+Hu0kovOFrZjibQARzMN58V+ZKTg+1AIhT4M 97QGK5fI5OPr8CVGueYLByPv2JcIKS80IcozOAWRE7UfQIU/rzsCqrdAqbSqndWpLAkO EBbb2uXTC2xuKp+JGGniZkkiQK65kpsb0KRtzAJ9lvIwCqP8glRQ2b8/RSHdLvUGpnUw enjeVErcrTAP8Abc5bjKZfv7EOW9Ok5Irsg1bIzgWydNTS8izDhb+VZd6ouAYbx/G7SP 19xGVo493Te0VlV5vzQiEGxmDTN6i9XqCayPg/eU5CiDny03ZKqdCltKeBxgfZ4YShL5 CcEA== X-Gm-Message-State: APjAAAXmuV9mz3z27uoYpJ11TCth5GxWv7+Q+ICq1+oh6I2XbL5Qxf5O kL4rZxzmP0yfAqLIh+ofeGeHsg== X-Received: by 2002:a05:6000:118f:: with SMTP id g15mr1440429wrx.242.1571988827402; Fri, 25 Oct 2019 00:33:47 -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 a11sm1586602wmh.40.2019.10.25.00.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 00:33:46 -0700 (PDT) From: Daniel Thompson To: Douglas Anderson , Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v4 4/5] kdb: Improve handling of characters from different input sources Date: Fri, 25 Oct 2019 08:33:27 +0100 Message-Id: <20191025073328.643-5-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191025073328.643-1-daniel.thompson@linaro.org> References: <20191025073328.643-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 than the '\e'. This is a bigger refactor than might be expected because the new character needs to go through escape sequence detection. Signed-off-by: Daniel Thompson Reviewed-by: Douglas Anderson --- kernel/debug/kdb/kdb_io.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 9b6933d585b5..f794c0ca4557 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -127,10 +127,10 @@ char 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; + get_char_func *f, *f_prev = NULL; int key; for (f = &kdb_poll_funcs[0]; ; ++f) { @@ -150,26 +150,26 @@ char kdb_getchar(void) continue; } - if (escape_delay == 0 && key == '\e') { + /* + * 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_prev != f) { + f_prev = f; + pbuf = buf; escape_delay = ESCAPE_DELAY; - ped = escape_data; - f_escape = f; - } - if (escape_delay) { - if (f_escape != f) - return '\e'; - - *ped++ = key; - key = kdb_handle_escape(escape_data, ped - escape_data); - if (key < 0) - return '\e'; - if (key == 0) - continue; } - break; /* A key to process */ + *pbuf++ = key; + key = kdb_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