Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2937410pxa; Tue, 18 Aug 2020 01:59:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZHunIBivCf5qTfjSRxkKMDoJbaiAS4qC/PspyV3bB71Iz+HVgu0//agXPrltO6bxMV6js X-Received: by 2002:a50:9fe6:: with SMTP id c93mr18109183edf.286.1597741155078; Tue, 18 Aug 2020 01:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597741155; cv=none; d=google.com; s=arc-20160816; b=T7sQqv6bDQHpFUSsToSrcPR7Kze9GHC/X4UUa6XCLAhHEA3DiWk4GT4N1iNSgauK/a vA9R9XrqaJ+gvTYRb6mSgxTUH0C0AvWv2azs/A0LcF0HbuYx/VC+His8cSzw0eSBx1xu 6brY7epK5vSuFluzLCA4vx58ocjSdQttl8GL8pPBbSiNQRJarrltlMazcIORmIbRE8Wx AW8RgLDL8X4dWvlyDoNFWAyCsLRa5fI95LrzbRCdKmcdDZmB484TM8Qia92MUjjOzra3 diK42x988mH/s//I4gtVB8TkQdTjpGETZATl6Bjyxz7w0oQc9TpI5BzvDtWf4g82wcb2 HeYg== 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; bh=KU4H1TeM9Blzl9FyuVV2nASyW83PA101SvUs2HyH5ck=; b=CnGqtusI2UTj+UrxyZ/M/cW4VwgIgof78WCqOconMtN8EBwLJkFpHFKKOsELZxoI+O b/ZNF+rce1If8JdOsXrquBpHWmj5zNivqiBmF9euaun/z/yvJVNxvq6XSNZ/Nc/7CDEz kguZn8RQB1L2oJqiLdaj9fKGs6hPlMtOQ9pSbUb9vluro//pu35wCuvmfHEdXJvCpjoa l+9AUoIUx7BiFu2KM2k2u9Wh32z2yy+9g+Y2ZJhhxYo6lvj4JjhZe7ArljCMebXry2u6 8XZLltmeg21jpus/M/U6MOncyLtwWWygPF+WzodHydL+95ZSBnbPYtnGs5MnhuzJr1Uw 73lQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t12si12545336ejj.713.2020.08.18.01.58.51; Tue, 18 Aug 2020 01:59:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726852AbgHRI5t (ORCPT + 99 others); Tue, 18 Aug 2020 04:57:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:37998 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726736AbgHRI5M (ORCPT ); Tue, 18 Aug 2020 04:57:12 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9C8FDB048; Tue, 18 Aug 2020 08:57:34 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 15/16] vc_screen: extract vcs_read_buf_header Date: Tue, 18 Aug 2020 10:57:05 +0200 Message-Id: <20200818085706.12163-15-jslaby@suse.cz> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200818085706.12163-1-jslaby@suse.cz> References: <20200818085706.12163-1-jslaby@suse.cz> 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 The attribute header handling is terrible in vcs_read_buf. Separate it to a new function and simply do memmove (of up to 4 bytes) to the start of the con_buf -- if user seeked. Signed-off-by: Jiri Slaby --- drivers/tty/vt/vc_screen.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c index c178a1611223..9d68c6b36ddf 100644 --- a/drivers/tty/vt/vc_screen.c +++ b/drivers/tty/vt/vc_screen.c @@ -297,6 +297,22 @@ static void vcs_read_buf_noattr(const struct vc_data *vc, char *con_buf, } } +static unsigned int vcs_read_buf_header(const struct vc_data *vc, char *con_buf, + unsigned int pos, unsigned int count) +{ + count = min(HEADER_SIZE - pos, count); + + /* clamp header values if they don't fit */ + con_buf[0] = min(vc->vc_rows, 0xFFu); + con_buf[1] = min(vc->vc_cols, 0xFFu); + getconsxy(vc, con_buf + 2); + + if (pos) + memmove(con_buf, con_buf + pos, count); + + return count; +} + static unsigned int vcs_read_buf(const struct vc_data *vc, char *con_buf, unsigned int pos, unsigned int count, bool viewed, unsigned int *skip) @@ -306,22 +322,11 @@ static unsigned int vcs_read_buf(const struct vc_data *vc, char *con_buf, unsigned int filled = count; if (pos < HEADER_SIZE) { - /* clamp header values if they don't fit */ - con_buf[0] = min(vc->vc_rows, 0xFFu); - con_buf[1] = min(vc->vc_cols, 0xFFu); - getconsxy(vc, con_buf + 2); - - *skip += pos; - count += pos; - if (count > CON_BUF_SIZE) { - count = CON_BUF_SIZE; - filled = count - pos; - } + count -= vcs_read_buf_header(vc, con_buf, pos, count); - /* Advance state pointers and move on. */ - count -= min(HEADER_SIZE, count); pos = HEADER_SIZE; con_buf += HEADER_SIZE; + /* If count >= 0, then pos is even... */ } else if (pos & 1) { /* -- 2.28.0