From patchwork Wed Jul 12 18:19:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9837233 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 3DD92602BD for ; Wed, 12 Jul 2017 18:20:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 333B427FA6 for ; Wed, 12 Jul 2017 18:20:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 240022861E; Wed, 12 Jul 2017 18:20:04 +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 4240627FA6 for ; Wed, 12 Jul 2017 18:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752042AbdGLSUC (ORCPT ); Wed, 12 Jul 2017 14:20:02 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:34707 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751075AbdGLSUB (ORCPT ); Wed, 12 Jul 2017 14:20:01 -0400 Received: by mail-pg0-f66.google.com with SMTP id j186so3905209pge.1; Wed, 12 Jul 2017 11:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=GmaQsuB51r95jQa0Q+dGKVwn2wxI3ytii2n35ajGMIo=; b=ieM4NOc8Am5O0hKx8rsNvywcMV1eG3PClY7UyCpLNenOkbk4ZCCiPEmtB4YITGMLKV qNmLLExwlYFKepDxxuPyOCiN77oxh0+Gf1xiT8IOq4gzz5yrSeJL0vuN6XnFpistLsHi wwJsP3HJmfhP7dD1454RWcwUCQ/69vuMlDcohBZTr9luqBnvhTOCu+s74P/3C6xSF4pK DNmDPhNNcb1PSX8ZOYHxfPK0HX1WsfdeKF2dfGstmIfQnT98rvB1zMsd6ztydwrVnmJQ 2z7/PJ4m/Qns3AxDhbGj18bwjCVmxD2BjZMjGji6zySOj4vkTGgbnkUBrWch7CjceycF 5OZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=GmaQsuB51r95jQa0Q+dGKVwn2wxI3ytii2n35ajGMIo=; b=ddfEY/To/CLuTObxDR1sfVW1VBNc4ApKAxmhtc4h74uNtJq1ZxzFwSxdxMg2qeJ+7b 8Ervj+9z2Y/zsBbscg7w5/mt5gxRs4NnyzKyuE0aOPR0qijutcAwh+UChNVS1Jts7Yqd B7lsq2lW9V3D3VXtsu5HJLDSfzmfOxKusw316GhUpaOTpo1E4FErwfY94m0xDKFTFl42 h9k+m2UER/oGEz7+g6gc4DyjKC32QQGSzHLR+Rq0CXSo3jaal4oak5sT4+Z+hnO2KKyd sSlJOpimeWyqZmlP8Y8TQzdlqEzDKmezu7Dxr8KMaqM4aD047d70+mW7fFi4HrDhB8DU E7zw== X-Gm-Message-State: AIVw112R1N9D/SMcyyGQG22Zu4CjfYiXNT1iVdpAiu5rHKyRJWi8ErJT AL6YeAaVL0f/WQ== X-Received: by 10.84.215.150 with SMTP id l22mr5637084pli.29.1499883600205; Wed, 12 Jul 2017 11:20:00 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1311:f8a8:14b7:d244:fba6]) by smtp.gmail.com with ESMTPSA id s123sm5830692pgs.2.2017.07.12.11.19.59 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 12 Jul 2017 11:19:59 -0700 (PDT) Date: Wed, 12 Jul 2017 11:19:57 -0700 From: Dmitry Torokhov To: Nick Desaulniers Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4] Input: mousedev - fix implicit conversion warning Message-ID: <20170712181957.GA16112@dtor-ws> References: <20170526154029.9405-1-nick.desaulniers@gmail.com> <20170530054151.16639-1-nick.desaulniers@gmail.com> <20170625180609.GA8697@dtor-ws> <20170712065710.7rn43l6uujsbboju@lostoracle.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170712065710.7rn43l6uujsbboju@lostoracle.net> User-Agent: Mutt/1.5.21 (2010-09-15) 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 On Tue, Jul 11, 2017 at 11:57:10PM -0700, Nick Desaulniers wrote: > Hi Dmitry, did you get a chance to merge the sugguested revision, yet? Sorry, no, as it was broken (we lost the assignment to the bytes 2 and 3 of the PS/2 data stream). Here is the version that seems to work, but at this time I guess I'll push it out to 4.14. diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c index 0e0ff84088fd..114730a0c3fa 100644 --- a/drivers/input/mousedev.c +++ b/drivers/input/mousedev.c @@ -15,6 +15,7 @@ #define MOUSEDEV_MINORS 31 #define MOUSEDEV_MIX 63 +#include #include #include #include @@ -103,7 +104,7 @@ struct mousedev_client { spinlock_t packet_lock; int pos_x, pos_y; - signed char ps2[6]; + u8 ps2[6]; unsigned char ready, buffer, bufsiz; unsigned char imexseq, impsseq; enum mousedev_emul mode; @@ -291,11 +292,10 @@ static void mousedev_notify_readers(struct mousedev *mousedev, } client->pos_x += packet->dx; - client->pos_x = client->pos_x < 0 ? - 0 : (client->pos_x >= xres ? xres : client->pos_x); + client->pos_x = clamp_val(client->pos_x, 0, xres); + client->pos_y += packet->dy; - client->pos_y = client->pos_y < 0 ? - 0 : (client->pos_y >= yres ? yres : client->pos_y); + client->pos_y = clamp_val(client->pos_y, 0, yres); p->dx += packet->dx; p->dy += packet->dy; @@ -571,44 +571,50 @@ static int mousedev_open(struct inode *inode, struct file *file) return error; } -static inline int mousedev_limit_delta(int delta, int limit) -{ - return delta > limit ? limit : (delta < -limit ? -limit : delta); -} - -static void mousedev_packet(struct mousedev_client *client, - signed char *ps2_data) +static void mousedev_packet(struct mousedev_client *client, u8 *ps2_data) { struct mousedev_motion *p = &client->packets[client->tail]; + s8 dx, dy, dz; + + dx = clamp_val(p->dx, -127, 127); + p->dx -= dx; + + dy = clamp_val(p->dy, -127, 127); + p->dy -= dy; - 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]; + ps2_data[0] = BIT(3); + ps2_data[0] |= ((dx & BIT(7)) >> 3) | ((dy & BIT(7)) >> 2); + ps2_data[0] |= p->buttons & 0x07; + ps2_data[1] = dx; + ps2_data[2] = dy; switch (client->mode) { case MOUSEDEV_EMUL_EXPS: - ps2_data[3] = mousedev_limit_delta(p->dz, 7); - p->dz -= ps2_data[3]; - ps2_data[3] = (ps2_data[3] & 0x0f) | ((p->buttons & 0x18) << 1); + dz = clamp_val(p->dz, -7, 7); + p->dz -= dz; + + ps2_data[3] = (dz & 0x0f) | ((p->buttons & 0x18) << 1); client->bufsiz = 4; break; 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]; + dz = clamp_val(p->dz, -127, 127); + p->dz -= dz; + + ps2_data[0] |= ((p->buttons & 0x10) >> 3) | + ((p->buttons & 0x08) >> 1); + ps2_data[3] = dz; + client->bufsiz = 4; break; case MOUSEDEV_EMUL_PS2: default: - ps2_data[0] |= - ((p->buttons & 0x10) >> 3) | ((p->buttons & 0x08) >> 1); p->dz = 0; + + ps2_data[0] |= ((p->buttons & 0x10) >> 3) | + ((p->buttons & 0x08) >> 1); + client->bufsiz = 3; break; } @@ -714,7 +720,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer, { struct mousedev_client *client = file->private_data; struct mousedev *mousedev = client->mousedev; - signed char data[sizeof(client->ps2)]; + u8 data[sizeof(client->ps2)]; int retval = 0; if (!client->ready && !client->buffer && mousedev->exist &&