From patchwork Sun Dec 25 10:04:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 9488199 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DBA6260839 for ; Sun, 25 Dec 2016 10:06:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEB2925D97 for ; Sun, 25 Dec 2016 10:06:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D254D26253; Sun, 25 Dec 2016 10:06:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A01E525D97 for ; Sun, 25 Dec 2016 10:06:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753904AbcLYKG0 (ORCPT ); Sun, 25 Dec 2016 05:06:26 -0500 Received: from mail-wj0-f196.google.com ([209.85.210.196]:34746 "EHLO mail-wj0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753135AbcLYKF1 (ORCPT ); Sun, 25 Dec 2016 05:05:27 -0500 Received: by mail-wj0-f196.google.com with SMTP id qs7so7984989wjc.1; Sun, 25 Dec 2016 02:05:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uRa8iXH/SaHCumFXlzTdRVXYdjqml5QAe1H/MsW29o0=; b=I70RfBW9bTXgDk0nPRdEAAf47huHWKNNzliNe5/SDqXLiaQM+9QVTvLLAPCwujR93x elRS7m6rhr6AwQR0SrlnRZGHHCJcRznl20hBXyaIWON8VlPaPd8oaCsVrOOUVjgiAJtL k274xCgbxB1+T6UPbTrY67YMPq49XRaZ+IiOf6bBiAb7FyJvl1l6P1l/szWsGMVc0NIO ZS3iqH1xtataUy+sMg0z3ul3TyZWpBpWIp7y+hptlor0Ir/yiK9UjzMDnIufWjEhBZJl lxvOJzbut2BpGjo1BotA3Nwb7waZJxUJ3BTGCEQvncEiy4dNRKaImcIIR+bNgBowUtJ3 lzsA== 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:mime-version :content-transfer-encoding; bh=uRa8iXH/SaHCumFXlzTdRVXYdjqml5QAe1H/MsW29o0=; b=CO4pwu0emyaoRb85zB6hhQ0oqUgJYqM1x62uLhB3I+y7mxxFGWzjx02C4BfPmhVlCW pNgCUBmm3VlWFNx0zrLE/8BY/CSZMUQWLoygq1dOYte5KcXYnIDTUNDrz26L5yn3YnEa WZd15mXQuMbDTAIAGz7/1asqe+5Pqg5OXVcfIyAHa49Kt46EBBOG5ec9IAvRUo3K+vMA lK1a6af1L/NSGwemu2UtlnoVY90Dh5yT/BOURhdZcWGLyxEc2HyRVrJODwJpfwFHEVCM 5qymYsamVCKeSw9ewf2z6pP+T4sq6li9t/iGXxj+YZRL33xVKfpc4XQ39XO3IfEeDYjJ st8Q== X-Gm-Message-State: AIkVDXIZuzT2GBohT6S4gpTiVbArMVG0rWCsK3UiQYsVT/BLLku9jmaGu16YaICRWTd6Wg== X-Received: by 10.194.177.231 with SMTP id ct7mr20047455wjc.221.1482660325014; Sun, 25 Dec 2016 02:05:25 -0800 (PST) Received: from localhost.localdomain (ip-88-212-34-237.antik.sk. [88.212.34.237]) by smtp.gmail.com with ESMTPSA id i10sm49495393wjd.15.2016.12.25.02.05.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Dec 2016 02:05:24 -0800 (PST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Dmitry Torokhov , Sebastian Reichel , Pavel Machek , Mauro Carvalho Chehab , Chuck Ebbert , Henrik Rydberg , Ivaylo Dimitrov Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [RFC PATCH] input: Add disable sysfs entry for every input device Date: Sun, 25 Dec 2016 11:04:56 +0100 Message-Id: <1482660296-8432-1-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch allows user to disable events from any input device so events would not be delivered to userspace. Currently there is no way to disable particular input device by kernel. User for different reasons would need it for integrated PS/2 keyboard or touchpad in notebook or touchscreen on mobile device to prevent sending events. E.g. mobile phone in pocket or broken integrated PS/2 keyboard. This is just a RFC patch, not tested yet. Original post about motivation about this patch is there: https://lkml.org/lkml/2014/11/29/92 Signed-off-by: Pali Rohár Tested-by: Nikita Yushchenko --- drivers/input/input.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/input.h | 4 ++++ 2 files changed, 39 insertions(+) diff --git a/drivers/input/input.c b/drivers/input/input.c index d95c34e..9f0da7e 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -430,6 +430,9 @@ void input_event(struct input_dev *dev, { unsigned long flags; + if (unlikely(dev->disabled)) + return; + if (is_event_supported(type, dev->evbit, EV_MAX)) { spin_lock_irqsave(&dev->event_lock, flags); @@ -457,6 +460,9 @@ void input_inject_event(struct input_handle *handle, struct input_handle *grab; unsigned long flags; + if (unlikely(dev->disabled)) + return; + if (is_event_supported(type, dev->evbit, EV_MAX)) { spin_lock_irqsave(&dev->event_lock, flags); @@ -1389,12 +1395,41 @@ static ssize_t input_dev_show_properties(struct device *dev, } static DEVICE_ATTR(properties, S_IRUGO, input_dev_show_properties, NULL); +static ssize_t input_dev_show_disable(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct input_dev *input_dev = to_input_dev(dev); + + return snprintf(buf, PAGE_SIZE, "%d\n", input_dev->disabled ? 1 : 0); +} +static ssize_t input_dev_store_disable(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct input_dev *input_dev = to_input_dev(dev); + int disable; + int ret; + + ret = kstrtoint(buf, 0, &disable); + if (ret) + return ret; + + if (disable != 0 && disable != 1) + return -EINVAL; + + input_dev->disabled = disable; + return count; +} +static DEVICE_ATTR(disable, S_IRUGO | S_IWUSR, input_dev_show_disable, input_dev_store_disable); + static struct attribute *input_dev_attrs[] = { &dev_attr_name.attr, &dev_attr_phys.attr, &dev_attr_uniq.attr, &dev_attr_modalias.attr, &dev_attr_properties.attr, + &dev_arrr_disable.attr, NULL }; diff --git a/include/linux/input.h b/include/linux/input.h index a65e3b2..e390b56 100644 --- a/include/linux/input.h +++ b/include/linux/input.h @@ -117,6 +117,8 @@ struct input_value { * @vals: array of values queued in the current frame * @devres_managed: indicates that devices is managed with devres framework * and needs not be explicitly unregistered or freed. + * @disabled: indicates that device is in disabled state and kernel drop + * all events from it */ struct input_dev { const char *name; @@ -187,6 +189,8 @@ struct input_dev { struct input_value *vals; bool devres_managed; + + bool disabled; }; #define to_input_dev(d) container_of(d, struct input_dev, dev)