From patchwork Fri Jan 19 19:41:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10175905 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 34AB06055D for ; Fri, 19 Jan 2018 19:41:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23D15287C8 for ; Fri, 19 Jan 2018 19:41:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20D0E287C5; Fri, 19 Jan 2018 19:41:54 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 AE90A28803 for ; Fri, 19 Jan 2018 19:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756402AbeASTlq (ORCPT ); Fri, 19 Jan 2018 14:41:46 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:34607 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756214AbeASTlR (ORCPT ); Fri, 19 Jan 2018 14:41:17 -0500 Received: by mail-pg0-f67.google.com with SMTP id r19so2184698pgn.1; Fri, 19 Jan 2018 11:41:17 -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:in-reply-to:references; bh=q+8cmHkgbAAmMpMXSdoI5aQvdZsj2CvTx6sJwS3VlaU=; b=NvDXI1tWhXKW3qo08jMEja7L8+wIy+dNWCJpaH5f8DUJ+rjVs9gBySWO1qvuJsXXLD 9sRivkMhOF+tXIGBgxqlTaAu9DlhaNuA2OlwA9ft9VPJScJADH9Ks9wXzjuwK/9BsUwZ bCKQKa/1az871DHnCGqxa5Dw3CDKXdKrlwiOQqOGP5rYpoddS1WJTeowLmcLfi0iMX2v uUBh1/MkXQwq4WHkh04vB7GVlxawW8F5kBICdWB8eVwjlP6OIw0kIAdebE7L4nGRq2wG XYux2c0/vHxc1z2VPk8VxtUNVnJuXFRi/JQnURoVUWdtxmrUlZgLT1uD4IdrIKYN5sIG fphQ== 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; bh=q+8cmHkgbAAmMpMXSdoI5aQvdZsj2CvTx6sJwS3VlaU=; b=QXaty+jeaEme6XuQwLbCMb7fhb515bE6+KwvK1ClRg1Fhpp/3EJt2udLjCtIyPztoO SJDEyf8fLm6pkIgH5u7jCOZMZfui9FnWjuEBFS0+ZGOh78LmmVCthknNBtgxmRK2iCQJ O3AaRCjK+mXu5YpSIdU3YFxaVeAYlTnX5PIxd5nTHsuxsbSOGsc9+cuIjB5KO3eHwNvr XpH7MxcbyFAAcaWarMRKx6WGt29DZZmkRRrs0H6kYlgNHJvJI4bqGDaEXq38RrbK1NPh g3mKiFWaUQhHv/wZ8CE32Caz8hXwNTKuKAqCeeMrK3aL1QF322cC9lHjLQH6O/4c3ZBM JVCQ== X-Gm-Message-State: AKwxytexjmoAp7w4EyLivQVjHWZmsrlGk5/K63V/SRK7bfDAeCL82d5X y8nCtyw2ZbXIhOeSivzzO1E= X-Google-Smtp-Source: ACJfBos/48VDSJLskzuXXRuOoYZ8e5XO3cxqvWyVREaKOyIp9pHNoQlTsF/kITHWb1N3JzUfJsAU5A== X-Received: by 10.99.128.66 with SMTP id j63mr31884145pgd.254.1516390876401; Fri, 19 Jan 2018 11:41:16 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:0:1000:1611:da80:8749:c06f:9515]) by smtp.gmail.com with ESMTPSA id p1sm18947830pgr.44.2018.01.19.11.41.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 11:41:15 -0800 (PST) From: Dmitry Torokhov To: Benjamin Tissoires , Hans de Goede , Lyude Paul Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] Input: libps2 - use u8 for byte data Date: Fri, 19 Jan 2018 11:41:06 -0800 Message-Id: <20180119194111.185590-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog In-Reply-To: <20180119194111.185590-1-dmitry.torokhov@gmail.com> References: <20180119194111.185590-1-dmitry.torokhov@gmail.com> 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 Instead of using unsigned char for the byte data switch to using u8. Also use unsigned int for the command codes and timeouts, and have ps2_handle_ack() and ps2_handle_response() return bool instead of int, as they do not return error codes but rather signal whether a byte was handled or not handled. ps2_is_keyboard_id() now returns bool as well. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/libps2.c | 31 ++++++++++++++++--------------- include/linux/libps2.h | 20 ++++++++++---------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c index 21aea5169a99c..c3712f0a47b50 100644 --- a/drivers/input/serio/libps2.c +++ b/drivers/input/serio/libps2.c @@ -34,7 +34,7 @@ MODULE_LICENSE("GPL"); * ps2_sendbyte() can only be called from a process context. */ -int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout) +int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout) { serio_pause_rx(ps2dev->serio); ps2dev->nak = 1; @@ -75,7 +75,7 @@ EXPORT_SYMBOL(ps2_end_command); * and discards them. */ -void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout) +void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout) { if (maxbytes > sizeof(ps2dev->cmdbuf)) { WARN_ON(1); @@ -102,9 +102,9 @@ EXPORT_SYMBOL(ps2_drain); * known keyboard IDs. */ -int ps2_is_keyboard_id(char id_byte) +bool ps2_is_keyboard_id(u8 id_byte) { - static const char keyboard_ids[] = { + static const u8 keyboard_ids[] = { 0xab, /* Regular keyboards */ 0xac, /* NCD Sun keyboard */ 0x2b, /* Trust keyboard, translated */ @@ -123,7 +123,8 @@ EXPORT_SYMBOL(ps2_is_keyboard_id); * completion. */ -static int ps2_adjust_timeout(struct ps2dev *ps2dev, int command, int timeout) +static int ps2_adjust_timeout(struct ps2dev *ps2dev, + unsigned int command, unsigned int timeout) { switch (command) { case PS2_CMD_RESET_BAT: @@ -178,11 +179,11 @@ static int ps2_adjust_timeout(struct ps2dev *ps2dev, int command, int timeout) * ps2_command() can only be called from a process context */ -int __ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command) +int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) { - int timeout; - int send = (command >> 12) & 0xf; - int receive = (command >> 8) & 0xf; + unsigned int timeout; + unsigned int send = (command >> 12) & 0xf; + unsigned int receive = (command >> 8) & 0xf; int rc = -1; int i; @@ -256,7 +257,7 @@ int __ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command) } EXPORT_SYMBOL(__ps2_command); -int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command) +int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) { int rc; @@ -286,7 +287,7 @@ EXPORT_SYMBOL(ps2_init); * to properly process ACK/NAK of a command from a PS/2 device. */ -int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data) +bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data) { switch (data) { case PS2_RET_ACK: @@ -318,7 +319,7 @@ int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data) } /* Fall through */ default: - return 0; + return false; } if (!ps2dev->nak) { @@ -333,7 +334,7 @@ int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data) if (data != PS2_RET_ACK) ps2_handle_response(ps2dev, data); - return 1; + return true; } EXPORT_SYMBOL(ps2_handle_ack); @@ -343,7 +344,7 @@ EXPORT_SYMBOL(ps2_handle_ack); * waiting for completion of the command. */ -int ps2_handle_response(struct ps2dev *ps2dev, unsigned char data) +bool ps2_handle_response(struct ps2dev *ps2dev, u8 data) { if (ps2dev->cmdcnt) ps2dev->cmdbuf[--ps2dev->cmdcnt] = data; @@ -359,7 +360,7 @@ int ps2_handle_response(struct ps2dev *ps2dev, unsigned char data) wake_up(&ps2dev->wait); } - return 1; + return true; } EXPORT_SYMBOL(ps2_handle_response); diff --git a/include/linux/libps2.h b/include/linux/libps2.h index 4ad06e824f76f..365c50b097ded 100644 --- a/include/linux/libps2.h +++ b/include/linux/libps2.h @@ -36,21 +36,21 @@ struct ps2dev { wait_queue_head_t wait; unsigned long flags; - unsigned char cmdbuf[8]; - unsigned char cmdcnt; - unsigned char nak; + u8 cmdbuf[8]; + u8 cmdcnt; + u8 nak; }; void ps2_init(struct ps2dev *ps2dev, struct serio *serio); -int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout); -void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout); +int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout); +void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout); void ps2_begin_command(struct ps2dev *ps2dev); void ps2_end_command(struct ps2dev *ps2dev); -int __ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command); -int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command); -int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data); -int ps2_handle_response(struct ps2dev *ps2dev, unsigned char data); +int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command); +int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command); +bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data); +bool ps2_handle_response(struct ps2dev *ps2dev, u8 data); void ps2_cmd_aborted(struct ps2dev *ps2dev); -int ps2_is_keyboard_id(char id); +bool ps2_is_keyboard_id(u8 id); #endif /* _LIBPS2_H */