From patchwork Tue May 30 05:41:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 9753771 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 7B901602B9 for ; Tue, 30 May 2017 05:42:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6454626C9B for ; Tue, 30 May 2017 05:42:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55DC627853; Tue, 30 May 2017 05:42:13 +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 DD3F626C9B for ; Tue, 30 May 2017 05:42:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750796AbdE3FmK (ORCPT ); Tue, 30 May 2017 01:42:10 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36069 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750720AbdE3FmJ (ORCPT ); Tue, 30 May 2017 01:42:09 -0400 Received: by mail-pf0-f194.google.com with SMTP id n23so15459573pfb.3; Mon, 29 May 2017 22:42:09 -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; bh=0cTjYBlsHrUqJ5xA6t0xevjn48gVk3q63A0tXMFO5AU=; b=Ap6Do64Uk00r9cIrLNZbP/HB4S+shQgj+BDxMHkN6+snqyF/Pi+7uB6SnG/Sv9Tfws O7PfwMSRYheDZ6QSeQV/RBAm4OgSIaMQYPFumfQXQrLHoE0FW179/MTxUGiJIacxdUqc Ezd5M7EUS6mrIogBpK/e8IAyQukjQujztWW9JqqZ4IsNnTClw16qlhoYcz24CB0b5D0e VF0eZZp/8JGLOZBVauZtHy605mC/sY4bX80qbRt6Ebv3StqRd2PH8Na/a25nw21TxtIi iJyFikd71Nr2+ro0c5W/UYmfo6WKcElf4tCSkZy/youFuWm4pDw5KhOGD6lP9qvASxFB sP8A== 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=0cTjYBlsHrUqJ5xA6t0xevjn48gVk3q63A0tXMFO5AU=; b=kRn9VmsEVSnxrlWsEe8rXoFgTF0BfS649pe7h801gyKwQpkdm+MEX/RLS/UphaFBNy UfN216Sf3e6rljz3wbTJW9E3L2XTesZf1ILPi/QGh5uXoyU066MshQTLh7bXmnbdI/zk eDkIMfuMHa8MtGonMGWAsl18+nwLHycF3WGb7KUg4PRo1sg6iiv1pUsT2w4MiDzdeEGw gES3GTxMbvnIQl2P65ChJqs76zjSCldYeAPy2uwNKFudyXImcwy0P2jxBsLCHCh41q9I oAac1OjV04H/AA6noxdflJElDgroJ6S/gp23oM9RvGKORYmsbBWhRzXsQF+wIWfytRx+ uOeQ== X-Gm-Message-State: AODbwcCxiNK9if4BccjZU4cnwRxS7dY8DxI2a3UbYzyIS2XeAfwM5tYo K3z2OncLs0EeoibHano= X-Received: by 10.99.127.73 with SMTP id p9mr23494953pgn.169.1496122928787; Mon, 29 May 2017 22:42:08 -0700 (PDT) Received: from localhost.localdomain ([2601:647:4701:31a:320e:d5ff:febd:81c]) by smtp.googlemail.com with ESMTPSA id 3sm17836491pgb.22.2017.05.29.22.42.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 May 2017 22:42:07 -0700 (PDT) From: Nick Desaulniers Cc: Nick Desaulniers , Dmitry Torokhov , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4] Input: mousedev - fix implicit conversion warning Date: Mon, 29 May 2017 22:41:51 -0700 Message-Id: <20170530054151.16639-1-nick.desaulniers@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170526154029.9405-1-nick.desaulniers@gmail.com> References: <20170526154029.9405-1-nick.desaulniers@gmail.com> To: unlisted-recipients:; (no To-header on input) 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 Clang warns: drivers/input/mousedev.c:653:63: error: implicit conversion from 'int' to 'signed char' changes value from 200 to -56 [-Wconstant-conversion] client->ps2[1] = 0x60; client->ps2[2] = 3; client->ps2[3] = 200; ~ ^~~ As far as I can tell, from http://www.computer-engineering.org/ps2mouse/ Under "Command Set" > "0xE9 (Status Request)" the value 200 is a valid sample rate. Using unsigned char [], rather than signed char [], for client->ps2 silences this warning. Also moves some reused logic into a helper function. Signed-off-by: Nick Desaulniers --- What's new in v4: * replace mousedev_limit_delta() with update_clamped() that also updates the ps2_data and delta values. The use of the temporary val should avoid integral conversion and promotion issues. drivers/input/mousedev.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c index 0e0ff84088fd..e645b8c6f2cb 100644 --- a/drivers/input/mousedev.c +++ b/drivers/input/mousedev.c @@ -103,7 +103,7 @@ struct mousedev_client { spinlock_t packet_lock; int pos_x, pos_y; - signed char ps2[6]; + unsigned char ps2[6]; unsigned char ready, buffer, bufsiz; unsigned char imexseq, impsseq; enum mousedev_emul mode; @@ -571,27 +571,27 @@ static int mousedev_open(struct inode *inode, struct file *file) return error; } -static inline int mousedev_limit_delta(int delta, int limit) +static inline void +update_clamped(unsigned char *ps2_data, int *delta, int limit) { - return delta > limit ? limit : (delta < -limit ? -limit : delta); + int val = *delta > limit ? limit : (*delta < -limit ? -limit : *delta); + *ps2_data = (unsigned char) val; + *delta -= val; } static void mousedev_packet(struct mousedev_client *client, - signed char *ps2_data) + unsigned char *ps2_data) { struct mousedev_motion *p = &client->packets[client->tail]; ps2_data[0] = 0x08 | ((p->dx < 0) << 4) | ((p->dy < 0) << 5) | (p->buttons & 0x07); - ps2_data[1] = mousedev_limit_delta(p->dx, 127); - ps2_data[2] = mousedev_limit_delta(p->dy, 127); - p->dx -= ps2_data[1]; - p->dy -= ps2_data[2]; + update_clamped(&ps2_data[1], &p->dx, 127); + update_clamped(&ps2_data[2], &p->dy, 127); switch (client->mode) { case MOUSEDEV_EMUL_EXPS: - ps2_data[3] = mousedev_limit_delta(p->dz, 7); - p->dz -= ps2_data[3]; + update_clamped(&ps2_data[3], &p->dz, 7); ps2_data[3] = (ps2_data[3] & 0x0f) | ((p->buttons & 0x18) << 1); client->bufsiz = 4; break; @@ -599,8 +599,7 @@ static void mousedev_packet(struct mousedev_client *client, case MOUSEDEV_EMUL_IMPS: ps2_data[0] |= ((p->buttons & 0x10) >> 3) | ((p->buttons & 0x08) >> 1); - ps2_data[3] = mousedev_limit_delta(p->dz, 127); - p->dz -= ps2_data[3]; + update_clamped(&ps2_data[3], &p->dz, 127); client->bufsiz = 4; break;