From patchwork Fri Feb 2 06:55:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 195645 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp251516dyc; Thu, 1 Feb 2024 22:59:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6rhEc5QkMGLC669q+hu3OQkgWSk62z0mP43Ub8Ccr+TqOWiFvZkRYvItfGNJxiATQ9E/3 X-Received: by 2002:a67:f959:0:b0:46c:f63f:3801 with SMTP id u25-20020a67f959000000b0046cf63f3801mr3493466vsq.9.1706857180168; Thu, 01 Feb 2024 22:59:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706857180; cv=pass; d=google.com; s=arc-20160816; b=JUreMhame398cCggB9sCa2Jeej7L8FEdOgRpnwH/hRUqIvlVe/W5t6DpDvX0QlvlOA PRuvkVNoICpuW4KoQIzodhHfshqUtxrciHNShhL380aeqzzmB5r7XY7CKGFZOg7ADQ9Y Zv74Y0CpJi1t/SuKLapvsgoJ1QLpijorHSB9GuCz7/sOHdP5ON0VirRz6HKhwYQjgog6 tCcrrEa8vCpMDs0MDbbKhcomnuBqKCtij1SOn83IwqCKd+PfaeaSL7eCs2YF+jaSjzLX BtDY9qugaG1izUZMDlpcZ64kN7G9fqaQQwC2FrE2B8Yy4iGdjBVWCbZLq7lSbbaCwww5 8HYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=MM2//6++2K+GxeAWx5v5TL63yBmup9eJfNE/ydbuuRg=; fh=FCGMDNIK9xJk70XvC/wF8PNa4pIcxXZmd/iUslFrp5Q=; b=VEaBhjWF+UKVrRayRTV+IBjhhWtj+ii8PsePUAllL9upczWn0A9IoXGbu8EBMn2yNf 89uGqu2hv/n5Px/gyWUnSOEiUoNC6e5efjykrt4p2sU7VrMGSyzPrHYdcnSQmxZAXhlJ 5yoTsue/CTV45y5I3OU/9QEu7IyyNar0Ze6X3LBEjD1R74/KaniuIeC4JQeXS8LsU4wl UzwO5UPM3j6P4Bntz6HjEZZfEN3IWCcUCphpXC9OZZGInpBeEuCCAa74n6BIrOB/j9HL sZzF+4/VYGee0QAsNTM0aA2CpMFzOsO1TBFDvbjvGiz1gJrkJR6npJcP/IRn2WaOwhoN Ei8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cIadmm3N; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49327-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49327-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUyGuZy1dnfWgRwlKA2FMsUkWo4b7JHWc3WgI82YdoQKyQ1gYWje7eLp8wOsf9t0DzNEW4SDsSZmpYIWtGcHx2JQwa5CQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id cn14-20020ad44a6e000000b00686af113368si1321784qvb.381.2024.02.01.22.59.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 22:59:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49327-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cIadmm3N; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49327-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49327-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DFE111C25391 for ; Fri, 2 Feb 2024 06:59:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CADE13FE5F; Fri, 2 Feb 2024 06:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cIadmm3N" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20FC539AD5; Fri, 2 Feb 2024 06:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706856989; cv=none; b=IRA3erbRAZX2XSvS+ngaKrdPLsFiwKH/ppiPEGzxWcRVe2AYoWd45+KMfxcgRh3hke1Lrez+rgBtvRBUiUQXENnrR8U5Zb6paIyWuUKkZDRirJUvsCsmegp9qirD/nUhKl2yXY6Lg2Qpo1+ZokF3cHrbCyguId6ulFl7Qmm2epI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706856989; c=relaxed/simple; bh=jqH2OL/S99n3SsvoefaaNMtSDFKpEggQ4kdfbyZSD9E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W2iZ9RbardKLoS6/npTHk5lkGoDOEwp7MHTXZQe0qoaVOXrA/wH/8w/nMbTG2tTLYCqY/61bi5zvk1ar/mxxmzaJG5/CF8eOykG5APyipTbN4sicOglmZBcIaV0ciLuRLI7vVIPEIAcbqDqpXS9Oj7dU5136IKo42SMfqPPUjW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cIadmm3N; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EB43C433F1; Fri, 2 Feb 2024 06:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706856988; bh=jqH2OL/S99n3SsvoefaaNMtSDFKpEggQ4kdfbyZSD9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cIadmm3N1wg15B4yH/C2pNXeJG3c/5pfwMefBRntw6Noq+gR75j7qUqafLLaBcqxX JmwfTIPPD5rTkCfngAwWDKaR1htYYgvz7QisqbrSPqY7iiWlosySh+SNbzHY3elMbh iWFlBe0m6E7MbuFtWi0wAsEqUYM0J1du3/RNb7w+gJpqeVR+q4KMX+IvvdowEUTGQL /zOQy8Rr/vM5JRJzYzID8iz7PxAhmcfrw1+frEIVB8tfpILGAbirZmawfONAPIjviP C0xTJ16GId0eFnxVfmyX6CsROsdseS9vOmS0kgz+NB/zSe+fQ5JI+1b5sUDA0vZ4D+ gLE69DNNJr4Dg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 11/22] tty: vt: extract ascii handling to handle_ascii() Date: Fri, 2 Feb 2024 07:55:57 +0100 Message-ID: <20240202065608.14019-12-jirislaby@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202065608.14019-1-jirislaby@kernel.org> References: <20240202065608.14019-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789769474140867346 X-GMAIL-MSGID: 1789769474140867346 To make the do_con_trol() a bit more understandable, extract the ASCII handling (the switch-case) to a separate function. Other nested switch-cases will follow in the next patches. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/vt/vt.c | 58 +++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 451a852ed234..7cda1a958c5e 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -2197,28 +2197,26 @@ enum { ASCII_EXT_CSI = 128 + ASCII_ESCAPE, }; -/* console_lock is held */ -static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c) +/* + * Handle ascii characters in control sequences and change states accordingly. + * E.g. ESC sets the state of vc to ESesc. + * + * Returns: true if @c handled. + */ +static bool handle_ascii(struct tty_struct *tty, struct vc_data *vc, u8 c) { - /* - * Control characters can be used in the _middle_ - * of an escape sequence, aside from ANSI control strings. - */ - if (ansi_control_string(vc->vc_state) && c >= ASCII_IGNORE_FIRST && - c <= ASCII_IGNORE_LAST) - return; switch (c) { case ASCII_NULL: - return; + return true; case ASCII_BELL: if (ansi_control_string(vc->vc_state)) vc->vc_state = ESnormal; else if (vc->vc_bell_duration) kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration); - return; + return true; case ASCII_BACKSPACE: bs(vc); - return; + return true; case ASCII_HTAB: vc->vc_pos -= (vc->state.x << 1); @@ -2230,41 +2228,59 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c) vc->vc_pos += (vc->state.x << 1); notify_write(vc, '\t'); - return; + return true; case ASCII_LINEFEED: case ASCII_VTAB: case ASCII_FORMFEED: lf(vc); if (!is_kbd(vc, lnm)) - return; + return true; fallthrough; case ASCII_CAR_RET: cr(vc); - return; + return true; case ASCII_SHIFTOUT: vc->state.charset = 1; vc->vc_translate = set_translate(vc->state.Gx_charset[1], vc); vc->vc_disp_ctrl = 1; - return; + return true; case ASCII_SHIFTIN: vc->state.charset = 0; vc->vc_translate = set_translate(vc->state.Gx_charset[0], vc); vc->vc_disp_ctrl = 0; - return; + return true; case ASCII_CANCEL: case ASCII_SUBSTITUTE: vc->vc_state = ESnormal; - return; + return true; case ASCII_ESCAPE: vc->vc_state = ESesc; - return; + return true; case ASCII_DEL: del(vc); - return; + return true; case ASCII_EXT_CSI: vc->vc_state = ESsquare; - return; + return true; } + + return false; +} + +/* console_lock is held */ +static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c) +{ + /* + * Control characters can be used in the _middle_ + * of an escape sequence, aside from ANSI control strings. + */ + if (ansi_control_string(vc->vc_state) && c >= ASCII_IGNORE_FIRST && + c <= ASCII_IGNORE_LAST) + return; + + if (handle_ascii(tty, vc, c)) + return; + switch(vc->vc_state) { case ESesc: vc->vc_state = ESnormal;