linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Desaulniers <nick.desaulniers@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Nick Desaulniers <nick.desaulniers@gmail.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	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	[thread overview]
Message-ID: <20170530054151.16639-1-nick.desaulniers@gmail.com> (raw)
In-Reply-To: <20170526154029.9405-1-nick.desaulniers@gmail.com>

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 <nick.desaulniers@gmail.com>
---
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;
 
-- 
2.11.0

  parent reply	other threads:[~2017-05-30  5:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26  5:22 [PATCH] Input: mousedev - fix implicit conversion warning Nick Desaulniers
2017-05-26 15:34 ` [PATCH v2] " Nick Desaulniers
2017-05-26 15:40   ` [PATCH v3] " Nick Desaulniers
2017-05-26 17:07     ` Dmitry Torokhov
2017-05-29 19:22       ` Nick Desaulniers
2017-05-30  2:44         ` Dmitry Torokhov
2017-05-30  5:41     ` Nick Desaulniers [this message]
2017-06-06 16:18       ` [PATCH v4] " Nick Desaulniers
2017-06-23  4:16       ` Nick Desaulniers
2017-06-25 18:06       ` Dmitry Torokhov
2017-06-27  1:39         ` Nick Desaulniers
2017-07-12  6:57         ` Nick Desaulniers
2017-07-12 18:19           ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170530054151.16639-1-nick.desaulniers@gmail.com \
    --to=nick.desaulniers@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).