Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1536488yba; Thu, 4 Apr 2019 12:47:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqybrXktd/W3jB1yUuRz6iJHeibH/DvZZ1In+G0SJC5PYJnHNH8PxbK0WL/oSa6fBRdTaDG8 X-Received: by 2002:a63:6842:: with SMTP id d63mr7484117pgc.49.1554407276024; Thu, 04 Apr 2019 12:47:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554407276; cv=none; d=google.com; s=arc-20160816; b=hEmAiYIP4roKwvxtd83WAdhjzt0swA/iQ71YkPqMOqC3q/hOrosIAxGD0RS4ryac1G OZw7J62dpOYgB4qZluEhE29A4EM7ZSbMaxMGmH7YJILrF15zgCdxwhm7UbgD6taan2SO FU5HnNYgbDmox3nZx6UbYSmHWDkhtr2z2OtxgLEN3T1oCnEfYMDDvaw2bzIvv4tM6JtK hk8JMw0ZM7hv8APTBnEnYaGlkrZTWtFrFeAC6B7JiI7XyOFwvcdKhG8niVlmsgurlbQC 6Q1oxOowa0YLd0fmm+wsyVQ76BPMqVgRUHD4+e9q0C5XZj6gwEmeGqC1sfpP/HOZT5rD U9Jg== 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=9WqxniVDABz/b0GhzlvQtonIOetHKNsnB5PBHBwGIpQ=; b=nIhjhuO6QxVdMuKDFmykVZj3pE0fBePdh180YbGCxEvR/TWusvssc5doXx22r4S6Jb wgNGdHHPuoACrgq0kEQuAgSPe93K1nzOkSJljFlstLhrhnMUT8TD34X2g2vRr2NyQ4xO Ez7BiBsB/JXZuslK0r8L4FNZwoXAz0CUG4UA25lldcxqXBn4V5EEsc1Hx/oRhSa8OND4 ROa/JgP11fzJuQq7Rps4l+JM2XYxvG+4IWcU66fycGh/fcJeHIFWCQIalpSDHoxwsCNH p1C2iIFzSrhXyRwjGxIoIFpiIeZlZHTTtOggeTs8papOj81g67PJorvKfszkVRw8RYxQ k+bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=teP7Gokw; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j64si568247pge.398.2019.04.04.12.47.40; Thu, 04 Apr 2019 12:47:56 -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=@gmail.com header.s=20161025 header.b=teP7Gokw; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730426AbfDDTqy (ORCPT + 99 others); Thu, 4 Apr 2019 15:46:54 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45879 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729793AbfDDTqx (ORCPT ); Thu, 4 Apr 2019 15:46:53 -0400 Received: by mail-wr1-f66.google.com with SMTP id s15so5224342wra.12 for ; Thu, 04 Apr 2019 12:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9WqxniVDABz/b0GhzlvQtonIOetHKNsnB5PBHBwGIpQ=; b=teP7GokwhgBE+bxCO4L/NY0PZUjNI+Zr1EIFKESnVw27voBHV7/XUBz0eWXm0Tlqlu YRrQQAtGVuOpLEUkYzD1Zt2lH7cN+NhzX2bWJ6iOnrRRaiupLI3zfb6lO+elGFHkmNYz YgML/d0MxuZD6mEnBtuzgfOvRLbOW7avbOM7NQnxuZB1x8OfG9zE1y5ksYRMDztKvNrn t+J6f+gPFCR5fGTMSMHCmuueWC7t6PzsEvA3Jc8PcqSuUfeLng5Ch37233aqLOElOXrq oTPpzzVDpgmQJIrywKERPKwToEoWSz/pVK7yQ9we/N9Y4xX1khEPDfgDUQ3+5HnZE6fv vfig== 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=9WqxniVDABz/b0GhzlvQtonIOetHKNsnB5PBHBwGIpQ=; b=WkBERyR2XlItG+KOwJ5Q3c1SIip4Un232eyevFaZe6xJ5ewJVtMOWuuzr40tT/F1/x ouWfHyiREVVa8NwKSprs0Z7bGINIOgc1cv+ExbGarLmFhOLpXqsPEcjRY6A/4iVLwavV IQOvMh1Ej8ObpgFLpTEOGazBPKHLnxZKKv7ZcurUn2PVwQELz4vwgCSrCAGDNKgE3avR im4uNP3nCKT7Lpj6X5Ro+S1/63MfBp4NKoKvhtPjBBxSLH0DhCdFxDc/lU3uG7UbWQfc 38K+6tv8/JpPEYmch2Ur9jNA+ViePto2U3cxM+Qbwntr8bS816ykmuWwk7zG++iwbnjc 35vQ== X-Gm-Message-State: APjAAAVZ8rUQP7ccst/pfflxFdQ+biH4KKx/gwGWm90GaYBWD5KcGG6v bfZG1+ywG3ZY4KQJyDoZ+7A= X-Received: by 2002:adf:f48f:: with SMTP id l15mr5542962wro.248.1554407211015; Thu, 04 Apr 2019 12:46:51 -0700 (PDT) Received: from localhost.localdomain ([185.219.177.201]) by smtp.gmail.com with ESMTPSA id f11sm23047400wrm.30.2019.04.04.12.46.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Apr 2019 12:46:50 -0700 (PDT) From: Okash Khawaja To: Greg Kroah-Hartman , Samuel Thibault , Gregory Nowak , linux-kernel@vger.kernel.org Cc: Jiri Slaby , Ben Hutchings , William Hubbs , Chris Brannon , Kirk Reiser , John Covici , Peter Hurley , devel@driverdev.osuosl.org, speakup@linux-speakup.org, Okash Khawaja Subject: [PATCH 1/2] vt: selection: allow functions to be called from inside kernel Date: Thu, 4 Apr 2019 20:45:29 +0100 Message-Id: <20190404194530.1170-2-okash.khawaja@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404194530.1170-1-okash.khawaja@gmail.com> References: <20190404194530.1170-1-okash.khawaja@gmail.com> 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 This patch breaks set_selection() into two functions so that when called from kernel, copy_from_user() can be avoided. It also exports set_selection() and paste_selection(). These changes are used the following patch where speakup's selection functionality calls into the above functions, thereby doing away with parallel implementation. Signed-off-by: Okash Khawaja Reviewed-by: Samuel Thibault Tested-by: Gregory Nowak --- drivers/tty/vt/selection.c | 37 ++++++++++++++++++++++++------------- include/linux/selection.h | 3 +-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c index 07496c711d7d..a43f9cd9bdd6 100644 --- a/drivers/tty/vt/selection.c +++ b/drivers/tty/vt/selection.c @@ -80,6 +80,7 @@ void clear_selection(void) sel_start = -1; } } +EXPORT_SYMBOL_GPL(clear_selection); /* * User settable table: what characters are to be considered alphabetic? @@ -164,34 +165,42 @@ static int store_utf8(u32 c, char *p) * a lot under the lock but its hardly a performance path */ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *tty) +{ + struct tiocl_selection v; + + if (copy_from_user(&v, sel, sizeof(*sel))) + return -EFAULT; + + return do_set_selection(&v, tty); +} + +int do_set_selection(struct tiocl_selection *v, struct tty_struct *tty) { struct vc_data *vc = vc_cons[fg_console].d; int new_sel_start, new_sel_end, spc; - struct tiocl_selection v; char *bp, *obp; int i, ps, pe, multiplier; u32 c; int mode; poke_blanked_console(); - if (copy_from_user(&v, sel, sizeof(*sel))) - return -EFAULT; - v.xs = min_t(u16, v.xs - 1, vc->vc_cols - 1); - v.ys = min_t(u16, v.ys - 1, vc->vc_rows - 1); - v.xe = min_t(u16, v.xe - 1, vc->vc_cols - 1); - v.ye = min_t(u16, v.ye - 1, vc->vc_rows - 1); - ps = v.ys * vc->vc_size_row + (v.xs << 1); - pe = v.ye * vc->vc_size_row + (v.xe << 1); + v->xs = min_t(u16, v->xs - 1, vc->vc_cols - 1); + v->ys = min_t(u16, v->ys - 1, vc->vc_rows - 1); + v->xe = min_t(u16, v->xe - 1, vc->vc_cols - 1); + v->ye = min_t(u16, v->ye - 1, vc->vc_rows - 1); + ps = v->ys * vc->vc_size_row + (v->xs << 1); + pe = v->ye * vc->vc_size_row + (v->xe << 1); - if (v.sel_mode == TIOCL_SELCLEAR) { + if (v->sel_mode == TIOCL_SELCLEAR) { /* useful for screendump without selection highlights */ clear_selection(); return 0; } - if (mouse_reporting() && (v.sel_mode & TIOCL_SELMOUSEREPORT)) { - mouse_report(tty, v.sel_mode & TIOCL_SELBUTTONMASK, v.xs, v.ys); + if (mouse_reporting() && (v->sel_mode & TIOCL_SELMOUSEREPORT)) { + mouse_report(tty, v->sel_mode & TIOCL_SELBUTTONMASK, v->xs, + v->ys); return 0; } @@ -208,7 +217,7 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t else use_unicode = 0; - switch (v.sel_mode) + switch (v->sel_mode) { case TIOCL_SELCHAR: /* character-by-character selection */ new_sel_start = ps; @@ -322,6 +331,7 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t sel_buffer_lth = bp - sel_buffer; return 0; } +EXPORT_SYMBOL_GPL(do_set_selection); /* Insert the contents of the selection buffer into the * queue of the tty associated with the current console. @@ -367,3 +377,4 @@ int paste_selection(struct tty_struct *tty) tty_ldisc_deref(ld); return 0; } +EXPORT_SYMBOL_GPL(paste_selection); diff --git a/include/linux/selection.h b/include/linux/selection.h index a8f5b97b216f..171d77dfc825 100644 --- a/include/linux/selection.h +++ b/include/linux/selection.h @@ -11,13 +11,12 @@ #include #include -struct tty_struct; - extern struct vc_data *sel_cons; struct tty_struct; extern void clear_selection(void); extern int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *tty); +extern int do_set_selection(struct tiocl_selection *v, struct tty_struct *tty); extern int paste_selection(struct tty_struct *tty); extern int sel_loadlut(char __user *p); extern int mouse_reporting(void); -- 2.21.0