From patchwork Mon Oct 14 15:46:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 176260 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4682905ill; Mon, 14 Oct 2019 08:46:36 -0700 (PDT) X-Received: by 2002:a5d:51d2:: with SMTP id n18mr26224798wrv.225.1571067996169; Mon, 14 Oct 2019 08:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571067996; cv=none; d=google.com; s=arc-20160816; b=vAyXvK5nlALISYuF94QS7BLW5/T3QUfgDMpBkrdkQrtEM3wox1qIaJUX7U3baOygn9 NH4Eej4IjKbno6uXV4sTjOxTHVZgOYdS2d0B6bIkfFA3pOlVDx/RS4r6Vlk0JQEkXbBX vomxqwJf45FAsLPzIDG4a5ToNeBOHWXzdYmJWO0xDC9Nr3EqEoo5TfLXm6VupVN154hP DruH/RUaFVDy2uWG191DvqRtWPmNUrJm9NAc0hmBIY4C7LZ+MO36Co5h2OYtjXwIaku9 VAPECRObkKL6q2dRJN6X1qE3/dSwOpWL9RVfyEyEOsjfbrAhCiGvtS1yRPK+MGEB/lJJ h8LA== 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=NXVuAHcqUdvW3hoXUr87/ZG8r6N5TpAF9zjL4wdSLjs=; b=DLKvtnM8osdQcuG1ATmhAkasl9qjmayLix9ZxrPUdUukK+asMqb3t1SLhitP8r9Xh0 fN6oh9fEglUps8Cr4FTaXaVIckLIbh4D8C6FyR8dZzpy4xShLPKax/eVEsyuQJmYdizf dSLYLn1rt2mmeolAG4xy+t0LeKmhs713NR6A67fg4M9MeV5FjbDnPvq9Ys122W1JZPQD RYCJOP4ONEU6aTCLeoErT1CJVwJxq44nhW8mpe9e+tDOWVm0Nb8cuwZeZX+qagARi5ao vtNjKbDwf9HLEGprSFuG9mqHzGd67XZ/SFYE4hvzYEItFoxCAg3AeBv+IPKcKkRCwSzZ O2Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z0fLFZdi; 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 i11sor12530583wrb.17.2019.10.14.08.46.36 for (Google Transport Security); Mon, 14 Oct 2019 08:46:36 -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=z0fLFZdi; 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=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=FIMR0/PdNyDpxepj6NLGH0z+rLqMtYQzRQ2MBEIDkNDhs83/48lO2wBOV9zs3zDCWZ hhXlWGOWRWTz+WjODOEaVuMeZQjiRAQJI2GmAZldrVwFgiFO3gnCPRgVBJk3P3gCu8je mil37bjpoOrkoi5FFZuFymFCd0h4YSyTvFR3rKvIHqDkLWBM7cDGiIyIGV/EjeuJxdX6 9ypUGE0LBkVnE6nYGjo9Ez5CeH0d9KaDonoJBfJit1I8XNM4liXCtfnyEego7gux6+HY 3rhPRK6PkDakxM+mK4lUfwDDEBpyzdpyEJsQByBxrTpTleRsgexEwNcWmVVAdmu/Gmd+ dbIw== X-Gm-Message-State: APjAAAWi811lfYDzOkrqr/6uXkPSiG2FHPOmw5cuoIjz2mWwyqH9uwfL yz3IREI4vBXBtZyilgdOTCIv+Zku X-Google-Smtp-Source: APXvYqx5FADHfzYt8ud++1U/l8HJVf0n/fufR09PMBReCszMIQDI28Ic5gABp6oUYxd229QF8PVDnQ== X-Received: by 2002:adf:fa12:: with SMTP id m18mr26744805wrr.248.1571067995742; Mon, 14 Oct 2019 08:46:35 -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.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 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(-) -- 2.21.0 Reviewed-by: Douglas Anderson 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(); } /*