Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4750105ybp; Mon, 14 Oct 2019 09:26:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzw4jk/jOs0TVSK5ZMWu7iE7IEaNkFmGhAqrwXaqc++JWTWpknuEDLjEem1blSmX3WRoSNW X-Received: by 2002:a50:fc82:: with SMTP id f2mr28894117edq.262.1571070371829; Mon, 14 Oct 2019 09:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571070371; cv=none; d=google.com; s=arc-20160816; b=tS9kX/P7WhE36dbFExjxBwViqx90YjlQRGfUyhlZU6Fe4pNrkf1tbxTgplU+0+ffVX WjDibnhZ9j0STOLHnFLbbOIkZXH9DWtuZ8RKQqJOTWGGDr3OgbQCGKbUIYYxqlz/f4iU 9pL5PJTzOyze9rCHLxo75IUrNO62Rb+ZZyYUPUhIG+WiUQxoYj2GXZuXzPiEuz6QeY5Z lqadod/UPuPitjas7p6xSC3iPA5ywElahD/bgt7v0O22v6qwJQ5LU9EoS06DNj8IsKoY XLaj6nIjyMQA/2gu3UKQ4r+FFKmUqvuNnqC5p/xGWTNN/kTtxSjxQIuzwbX05MgkhJBJ 9vAA== 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=NXVuAHcqUdvW3hoXUr87/ZG8r6N5TpAF9zjL4wdSLjs=; b=X+Xg02su2Gaf4G2APlGnQ7Z36Xs6t9GQJbu3S/ghp1RATXjI0w3E7YjK1KS/rqCuHI CWdq4WTXHX/HRpnVGx6+XfSJS+xFmO+hKPL78TAGXBw0ZXsmVqjdNfuPYBh+Cb5NX/E4 FzTu1sAWeQGOOePxnnTPHNpZA431t7w9B6wu9Xq3uyFtVHlAmNP6NE3DNEmvBxXco3n+ ZBcwWu++1xZS66pbt4z9yIvhnBzfS9oFrvwkkARrehu4dHrZKUkWvvFv9lZ1AebJHtGB nGhWhhM0vtBOgF4UBj6VvJ5PdhfeQdONC8utshbdFTkfBCYgE0OAf3dR+FZ+uq8TFsNJ 1ZHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z0fLFZdi; 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 90si14549490edj.72.2019.10.14.09.25.48; Mon, 14 Oct 2019 09:26:11 -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=z0fLFZdi; 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 S2387796AbfJNPqk (ORCPT + 99 others); Mon, 14 Oct 2019 11:46:40 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:39318 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729997AbfJNPqh (ORCPT ); Mon, 14 Oct 2019 11:46:37 -0400 Received: by mail-wr1-f68.google.com with SMTP id r3so20322770wrj.6 for ; Mon, 14 Oct 2019 08:46:36 -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=NXVuAHcqUdvW3hoXUr87/ZG8r6N5TpAF9zjL4wdSLjs=; b=z0fLFZdiPdt8jFM79h6y29ec5MdAp59EkR64ijJkc1qehMaqn2x6FJkeo/NnmuHEHk j0o5v8iPg0+KK7JLooF72uFuacfEAcb5FywnYGz7gOgd/bdQjzM6xIdbn517084et/Xp Bq9Xot8YchrJLHTDzrMGZvXI0Q7d5flJhYIIQifqmAN2SKlNNbYDtyYTLoM83wZjUy9M HMEivEnl+VO0Sw0i7PmvinffXtQ6t0u+p+lPg5N9W6YSlxKWX/msc+74g9VSRDOp6Jra Ei0/RMsmyksc/XTq8VdmV1LYgxKtE8T6SUbWEuQ1FrPqweF1N6srFJdGMEz+FfxIRraP 31PA== 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=NXVuAHcqUdvW3hoXUr87/ZG8r6N5TpAF9zjL4wdSLjs=; b=aqK2RBMrVFZw7hMkn2QdTGrf/849sbeogpTjkiKd8mlhoFCWOSJZDEkdMDyxR4fGEO PmrAaJ2TTXAhKmpCozfrl+AwRnzu725TNPaqN1ew3FQhGsKD4r0d8DwpgkS6M5bW83Tf W6dqqEEDx3nCGN85wOTZLeamBFibuOUH8RVV4G35o2pbiqN9q5dOzkba3uEwcpPBDeck 6pcJrEwmbMrSwZiM7pc7qLmyZ5otUuQGuaROVqGrtacbvIvjmr6z65GWhl1F1W7QsLxm 2D6Ci2b+tKCEfhddMTG7qjQFjrpsfPyYrBGcCS+b7B5cTXIsEtUltCokzVGrxatwxu6u 2UdA== X-Gm-Message-State: APjAAAXg0xKbV1uLfPQV5fSyo3MCzHw48vbXwcCeRi0XxQ85DlsvKL6N VOT3P0KmgE40YkW98BhM0gAiBg== X-Received: by 2002:adf:fa12:: with SMTP id m18mr26744805wrr.248.1571067995742; Mon, 14 Oct 2019 08:46:35 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 08:46:34 -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 4/5] kdb: Improve handling of characters from different input sources Date: Mon, 14 Oct 2019 16:46:25 +0100 Message-Id: <20191014154626.351-5-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 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 --- kernel/debug/kdb/kdb_io.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 39476616295e..f9839566c7d6 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -125,10 +125,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) { @@ -148,27 +148,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