From patchwork Fri Aug 31 20:51:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 145701 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1217094ljw; Fri, 31 Aug 2018 13:52:33 -0700 (PDT) X-Received: by 2002:a1c:7915:: with SMTP id l21-v6mr6145342wme.136.1535748753811; Fri, 31 Aug 2018 13:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535748753; cv=none; d=google.com; s=arc-20160816; b=C1E06Jw/znH1lsrP5uVwuf/qTd2WYKZZJaYZFLARgBXJTsUJVXzvyEjcZUv7CElA89 FfevtcXsohDorEoaS56qItT7vvevwVEVedsuLtEPTEeXehdbKPLowi5rrlVpv/QRNXyS Sw1UhytTh5gPXaJ+eFXmiv++e5ldczM2Zfr8ZTvP+HQ5ab1Zq+4bf/QjQ3KR1J7faT5+ 7V+7/w79IyxNAOSyJeeKbEOCPNYUMVekJ8sxqekUNkF+VyGRONJc2Zb6i+QtymwftQpF wqd8zv0IHUF6RSHqa1HTflFneQXY3hy7e/85r2a83nB4jzg87dsiQqDCAQNIB2TiQcAP lH0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=DyGBnWZx2nlxc4vEWno/PWe6PjvhGEty03ow5mFqowE=; b=GHt1WBv2BSnrsq/O4Cgm2tiatxyO2JW1S6Ca6RP/GGWF0tX+/CuFt7CMalqZYfdgjR kLMPJb2tCWLtrxqCYRdcX+GyNywQrUyEX7x07h53QnI3rkezcHFplxJ2Gbu6mYBJV46w PjPhL50566JSN6mFW9hL8mDL/TxwGQCCq1bVNn0kwLUlYatvcCFcFS1Mw456V7ntwoOn k0K9CiJPZT7LQ7/qq5uc7f7+3Y0u1eXgy5wL/GrnLIp/2M9XUonFFy3MkHg67l96MxXv Z8wREsfHh+HAcxPppsILxnr2IalBTqVCADKr++TJgTUEYkrR4ig4lekUt1mNbcfJ+5HI Kq5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fk12/YCz"; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id m9-v6sor7828119wrw.24.2018.08.31.13.52.33 for (Google Transport Security); Fri, 31 Aug 2018 13:52:33 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fk12/YCz"; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.41 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; bh=DyGBnWZx2nlxc4vEWno/PWe6PjvhGEty03ow5mFqowE=; b=Fk12/YCzY6LvgACPt4jmmXv/w8T70WtF0fKOhYx4a4zaj4ka1srfoi26Cft7l0bSzT Xal7Wf0FngnMl/RFYksLmZRiu0O8e+YbmQBqCpZYC0uRTmIUoUqxvZPaD8Dwn/sufBOE zqr/kb9dw28sm3Nx5X3fh4Fqrc8iAelb8nflM= 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; bh=DyGBnWZx2nlxc4vEWno/PWe6PjvhGEty03ow5mFqowE=; b=j0wx1+ukBpSuJefwJefx0sMQoJKDmIfjH7MIx+tNv+EVYthMyE/SqFGHzQSGLYmMZl eJCIyWL2KZoCeUuMfO280zbzB8BUeYv6bhi4FGIUXY8iUc1LTOX0Wja9lmx5lCLPErCB xErHDmMqCxjBu11q8JiUdohZWUwQ5x4Gmh7NhufiZTDA3ko4B/CgFyVoN8uy1r99ntbW oQZ6BXN2n73S2srnr+TFGOsovIBeepLSBitH49a/2Si4QfFtRfJkpcENK+tTRLL2sKG2 R2o3VeKPT2IywZahvxU/l/Mte0uEK1aIVbs7m/yPVPHOIE86RPSBlHmpZOWNCI60cAOG ydZA== X-Gm-Message-State: APzg51CVFupOJpkbC9Zp9P3GM2v/e9hq68+G7hTzjHzVd3gPv0aFJ6ZY 5WBB77wvKmHwY7TZvsaMUDWNaqyhg5q9pQ== X-Google-Smtp-Source: ANB0VdaBOSnURcAyKixLkescAzgurtV4ZnSwKo2YfbMWneHfqCu3JC+KzERkjn6KVJkoJIv9G+nVNw== X-Received: by 2002:a5d:4a87:: with SMTP id o7-v6mr11265526wrq.132.1535748753541; Fri, 31 Aug 2018 13:52:33 -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 u4-v6sm7659356wro.47.2018.08.31.13.52.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Aug 2018 13:52:32 -0700 (PDT) From: Daniel Thompson To: Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH 3/5] kdb: Remove special case logic from kdb_read() Date: Fri, 31 Aug 2018 21:51:40 +0100 Message-Id: <20180831205142.23609-4-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180831205142.23609-1-daniel.thompson@linaro.org> References: <20180831205142.23609-1-daniel.thompson@linaro.org> kdb_read() contains special case logic to force it exit after reading a single character. We can remove all the special case logic by directly calling the function to read a single character instead. This also allows us to tidy up the function prototype which, because it now matches getchar(), we can also rename in order to make its role clearer. Signed-off-by: Daniel Thompson --- kernel/debug/kdb/kdb_io.c | 56 ++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 33 deletions(-) -- 2.17.1 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 0ba490728459..f735d859f28b 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -106,7 +106,19 @@ static int kdb_read_handle_escape(char *buf, size_t sz) return -1; } -static int kdb_read_get_key(char *buffer, size_t bufsize) +/* + * kdb_getchar + * + * Read a single character from kdb console (or consoles). + * + * An escape key could be the start of a vt100 control sequence such as \e[D + * (left arrow) or it could be a character in its own right. The standard + * method for detecting the difference is to wait for 2 seconds to see if there + * are any other characters. kdb is complicated by the lack of a timer service + * (interrupts are off), by multiple input sources. Escape sequence processing + * has to be done as states in the polling loop. + */ +static int kdb_getchar(void) { #define ESCAPE_UDELAY 1000 #define ESCAPE_DELAY (2*1000000/ESCAPE_UDELAY) /* 2 seconds worth of udelays */ @@ -124,7 +136,6 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) } key = (*f)(); - if (key == -1) { if (escape_delay) { udelay(ESCAPE_UDELAY); @@ -134,14 +145,6 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) continue; } - if (bufsize <= 2) { - if (key == '\r') - key = '\n'; - *buffer++ = key; - *buffer = '\0'; - return -1; - } - if (escape_delay == 0 && key == '\e') { escape_delay = ESCAPE_DELAY; ped = escape_data; @@ -183,17 +186,7 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) * function. It is not reentrant - it relies on the fact * that while kdb is running on only one "master debug" cpu. * Remarks: - * - * The buffer size must be >= 2. A buffer size of 2 means that the caller only - * wants a single key. - * - * An escape key could be the start of a vt100 control sequence such as \e[D - * (left arrow) or it could be a character in its own right. The standard - * method for detecting the difference is to wait for 2 seconds to see if there - * are any other characters. kdb is complicated by the lack of a timer service - * (interrupts are off), by multiple input sources and by the need to sometimes - * return after just one key. Escape sequence processing has to be done as - * states in the polling loop. + * The buffer size must be >= 2. */ static char *kdb_read(char *buffer, size_t bufsize) @@ -228,9 +221,7 @@ static char *kdb_read(char *buffer, size_t bufsize) *cp = '\0'; kdb_printf("%s", buffer); poll_again: - key = kdb_read_get_key(buffer, bufsize); - if (key == -1) - return buffer; + key = kdb_getchar(); if (key != 9) tab = 0; switch (key) { @@ -738,7 +729,7 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) /* check for having reached the LINES number of printed lines */ if (kdb_nextline >= linecount) { - char buf1[16] = ""; + char ch; /* Watch out for recursion here. Any routine that calls * kdb_printf will come back through here. And kdb_read @@ -773,39 +764,38 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) if (logging) printk("%s", moreprompt); - kdb_read(buf1, 2); /* '2' indicates to return - * immediately after getting one key. */ + ch = kdb_getchar(); kdb_nextline = 1; /* Really set output line 1 */ /* empty and reset the buffer: */ kdb_buffer[0] = '\0'; next_avail = kdb_buffer; size_avail = sizeof(kdb_buffer); - if ((buf1[0] == 'q') || (buf1[0] == 'Q')) { + if ((ch == 'q') || (ch == 'Q')) { /* user hit q or Q */ KDB_FLAG_SET(CMD_INTERRUPT); /* command interrupted */ KDB_STATE_CLEAR(PAGER); /* end of command output; back to normal mode */ kdb_grepping_flag = 0; kdb_printf("\n"); - } else if (buf1[0] == ' ') { + } else if (ch == ' ') { kdb_printf("\r"); suspend_grep = 1; /* for this recursion */ - } else if (buf1[0] == '\n') { + } else if (ch == '\n' || ch == '\r') { kdb_nextline = linecount - 1; kdb_printf("\r"); suspend_grep = 1; /* for this recursion */ - } else if (buf1[0] == '/' && !kdb_grepping_flag) { + } else if (ch == '/' && !kdb_grepping_flag) { kdb_printf("\r"); kdb_getstr(kdb_grep_string, KDB_GREP_STRLEN, kdbgetenv("SEARCHPROMPT") ?: "search> "); *strchrnul(kdb_grep_string, '\n') = '\0'; kdb_grepping_flag += KDB_GREPPING_FLAG_SEARCH; suspend_grep = 1; /* for this recursion */ - } else if (buf1[0] && buf1[0] != '\n') { + } else if (ch && ch != '\n') { /* user hit something other than enter */ suspend_grep = 1; /* for this recursion */ - if (buf1[0] != '/') + if (ch != '/') kdb_printf( "\nOnly 'q', 'Q' or '/' are processed at " "more prompt, input ignored\n");