Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp898443imm; Wed, 22 Aug 2018 14:45:40 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzpr4L4YXBT4/lhEDPI+2Xlj8VFNYOtRQ0uW08Tu6bxC63tlWMkWWdI8eluK4Up1ovhoAQN X-Received: by 2002:a17:902:7845:: with SMTP id e5-v6mr54939235pln.197.1534974340827; Wed, 22 Aug 2018 14:45:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534974340; cv=none; d=google.com; s=arc-20160816; b=lTndThru5zXMQ/FDFg+zgm7GY36qNmhGFUq/U68KP4zAov4nPb06tK0gCW9rn7YRUT G1RwABCGqFxjcXUxqyVQkFMrb34PuAEomoPinHR4OS2h7adE3VVezJ2I0eEPzi7u0nRg utTh1vye7CWpL2y/zp8anIEMYA72wZrWNmpi2p8lrp4EhRJK+eyeX7/WVV3Lpz13vCbI TGL7xbHwTKbgaDk53iaeno2Mdv+ZtpjXTjPoFm5XPFfLkQ3CUX8yhupHz2NOHAzTRR+L LyCUaLNEebAmbhKXTy7C3xFJxqy2WHPL7MniAz5GTdUKQH0nCamM59gz8jZllqEUFFYE BwKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=zjLKvfcW+HWu9QXWzdhOMc6w1isQUiWqZfugYRvoU0c=; b=NW/zv8789UQcLSwNu0+I4Fkw3qpEGNWd489su5gFOkn/YOW1cVX+8XMPlb6Fqf01uR c/9L65J/siwMPd6CseUUY3o5bjs4EyThDNkDD9EZ4v2elk6x1BSCnN04ZwronhLTM8Y1 C/Xx7PSpLG6xgOTUADaTUF8WviS1gR7usf9/qgyifc727X8TAFjJEJJdiZ1LWBKWlsR1 nGHTltq1C/djlIG0rfvZDNpg5AhF1gM9Xo8rdEQuyI4+keEZs4JAGfXKN+XqGplCLfdp u9pnwRX27gtt7kD2vAOokOSkxGOQNbM/coPjbomHQmwggMCHr/MCUHMbx1gmZFEKTLJS JI4A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h65-v6si3046573pfb.70.2018.08.22.14.45.25; Wed, 22 Aug 2018 14:45:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728144AbeHWBKK (ORCPT + 99 others); Wed, 22 Aug 2018 21:10:10 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:35553 "EHLO relay5-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727007AbeHWBKK (ORCPT ); Wed, 22 Aug 2018 21:10:10 -0400 X-Originating-IP: 88.190.179.123 Received: from localhost (unknown [88.190.179.123]) (Authenticated sender: repk@triplefau.lt) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 2899C1C0002; Wed, 22 Aug 2018 21:43:30 +0000 (UTC) From: Remi Pommarel To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Alexander Viro , Kees Cook , Elie Roudninski , Remi Pommarel Subject: [RFC PATCH 3/4] drivers/tty/vt/keyboard.c: Make key_down[] bitmap input dependent Date: Wed, 22 Aug 2018 23:50:34 +0200 Message-Id: <0024029b8cbfd6e9672e3e620cfc9e4f6b836e03.1534972814.git.repk@triplefau.lt> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A kbd_handle input can have a specific keyboard config that makes keycode to keysym mapping array different from another one. Because key_down[] bitmap stores currently pressed key as keycode, it should be associated with an input keymap in order to retrieve the associated keysym. Allocating this array in each input allows to retrieve its associated keymap. Signed-off-by: Remi Pommarel Tested-by: Elie Roudninski --- drivers/tty/vt/keyboard.c | 46 +++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c index 4f09331ad5c3..7272e1828838 100644 --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -122,6 +122,7 @@ struct kbd_handle { struct kref ref; struct kbd_conf *conf; struct input_handle handle; + unsigned long key_down[BITS_TO_LONGS(KEY_CNT)];/* keyboard key bitmap */ }; #define hdl_to_kbd_handle(h) (container_of(h, struct kbd_handle, handle)) @@ -140,7 +141,6 @@ static const int NR_TYPES = ARRAY_SIZE(max_vals); static struct input_handler kbd_handler; static DEFINE_SPINLOCK(kbd_event_lock); static DEFINE_SPINLOCK(led_lock); -static unsigned long key_down[BITS_TO_LONGS(KEY_CNT)]; /* keyboard key bitmap */ static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ static bool dead_key_next; static int npadch = -1; /* -1 or number assembled on pad */ @@ -378,20 +378,18 @@ static void to_utf8(struct vc_data *vc, uint c) /* * Called after returning from RAW mode or when changing consoles - recompute - * shift_down[] and shift_state from key_down[] maybe called when keymap is - * undefined, so that shiftkey release is seen. The caller must hold the - * kbd_event_lock. + * shift_down[] and shift_state from each input's key_down[] maybe called when + * keymap is undefined, so that shiftkey release is seen. The caller must hold + * the kbd_event_lock. */ -static void do_compute_shiftstate(void) +static int do_compute_input_shiftstate(struct input_handle *handle, void *data) { + struct kbd_handle *kh = hdl_to_kbd_handle(handle); unsigned int k, sym, val; - shift_state = 0; - memset(shift_down, 0, sizeof(shift_down)); - - for_each_set_bit(k, key_down, min(NR_KEYS, KEY_CNT)) { - sym = U(key_maps[0][k]); + for_each_set_bit(k, kh->key_down, min(NR_KEYS, KEY_CNT)) { + sym = U(kh->conf->maps[0][k]); if (KTYP(sym) != KT_SHIFT && KTYP(sym) != KT_SLOCK) continue; @@ -402,6 +400,15 @@ static void do_compute_shiftstate(void) shift_down[val]++; shift_state |= BIT(val); } + return 0; +} + +static void do_compute_shiftstate(void) +{ + shift_state = 0; + memset(shift_down, 0, sizeof(shift_down)); + input_handler_for_each_handle(&kbd_handler, NULL, + do_compute_input_shiftstate); } /* We still have to export this method to vt.c */ @@ -1278,6 +1285,17 @@ static int sparc_l1_a_state; extern void sun_do_break(void); #endif +static int is_alt_down(struct input_handle *handle, void *data) +{ + struct kbd_handle *kh = hdl_to_kbd_handle(handle); + + if (test_bit(KEY_LEFTALT, kh->key_down) || + test_bit(KEY_RIGHTALT, kh->key_down)) + return 1; + + return 0; +} + static int emulate_raw(struct vc_data *vc, unsigned int keycode, unsigned char up_flag) { @@ -1308,8 +1326,8 @@ static int emulate_raw(struct vc_data *vc, unsigned int keycode, * pressing PrtSc/SysRq alone, but simply 0x54 * when pressing Alt+PrtSc/SysRq. */ - if (test_bit(KEY_LEFTALT, key_down) || - test_bit(KEY_RIGHTALT, key_down)) { + if (input_handler_for_each_handle(&kbd_handler, NULL, + is_alt_down)) { put_queue(vc, 0x54 | up_flag); } else { put_queue(vc, 0xe0); @@ -1424,9 +1442,9 @@ static void kbd_keycode(struct kbd_handle *kh, unsigned int keycode, int down, } if (down) - set_bit(keycode, key_down); + set_bit(keycode, kh->key_down); else - clear_bit(keycode, key_down); + clear_bit(keycode, kh->key_down); if (rep && (!vc_kbd_mode(kbd, VC_REPEAT) || -- 2.18.0