Input: mousedev - fix implicit conversion warning

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 the PS2 data is really a stream of bytes, let's switch to using u8 type
for it, which silences this warning.

Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
Nick Desaulniers 2017-06-24 22:50:12 -07:00 committed by Dmitry Torokhov
parent 3dabc19acf
commit dae1a432ab
1 changed files with 34 additions and 28 deletions

View File

@ -15,6 +15,7 @@
#define MOUSEDEV_MINORS 31 #define MOUSEDEV_MINORS 31
#define MOUSEDEV_MIX 63 #define MOUSEDEV_MIX 63
#include <linux/bitops.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/poll.h> #include <linux/poll.h>
@ -103,7 +104,7 @@ struct mousedev_client {
spinlock_t packet_lock; spinlock_t packet_lock;
int pos_x, pos_y; int pos_x, pos_y;
signed char ps2[6]; u8 ps2[6];
unsigned char ready, buffer, bufsiz; unsigned char ready, buffer, bufsiz;
unsigned char imexseq, impsseq; unsigned char imexseq, impsseq;
enum mousedev_emul mode; enum mousedev_emul mode;
@ -291,11 +292,10 @@ static void mousedev_notify_readers(struct mousedev *mousedev,
} }
client->pos_x += packet->dx; client->pos_x += packet->dx;
client->pos_x = client->pos_x < 0 ? client->pos_x = clamp_val(client->pos_x, 0, xres);
0 : (client->pos_x >= xres ? xres : client->pos_x);
client->pos_y += packet->dy; client->pos_y += packet->dy;
client->pos_y = client->pos_y < 0 ? client->pos_y = clamp_val(client->pos_y, 0, yres);
0 : (client->pos_y >= yres ? yres : client->pos_y);
p->dx += packet->dx; p->dx += packet->dx;
p->dy += packet->dy; p->dy += packet->dy;
@ -571,44 +571,50 @@ static int mousedev_open(struct inode *inode, struct file *file)
return error; return error;
} }
static inline int mousedev_limit_delta(int delta, int limit) static void mousedev_packet(struct mousedev_client *client, u8 *ps2_data)
{
return delta > limit ? limit : (delta < -limit ? -limit : delta);
}
static void mousedev_packet(struct mousedev_client *client,
signed char *ps2_data)
{ {
struct mousedev_motion *p = &client->packets[client->tail]; struct mousedev_motion *p = &client->packets[client->tail];
s8 dx, dy, dz;
ps2_data[0] = 0x08 | dx = clamp_val(p->dx, -127, 127);
((p->dx < 0) << 4) | ((p->dy < 0) << 5) | (p->buttons & 0x07); p->dx -= dx;
ps2_data[1] = mousedev_limit_delta(p->dx, 127);
ps2_data[2] = mousedev_limit_delta(p->dy, 127); dy = clamp_val(p->dy, -127, 127);
p->dx -= ps2_data[1]; p->dy -= dy;
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) { switch (client->mode) {
case MOUSEDEV_EMUL_EXPS: case MOUSEDEV_EMUL_EXPS:
ps2_data[3] = mousedev_limit_delta(p->dz, 7); dz = clamp_val(p->dz, -7, 7);
p->dz -= ps2_data[3]; p->dz -= dz;
ps2_data[3] = (ps2_data[3] & 0x0f) | ((p->buttons & 0x18) << 1);
ps2_data[3] = (dz & 0x0f) | ((p->buttons & 0x18) << 1);
client->bufsiz = 4; client->bufsiz = 4;
break; break;
case MOUSEDEV_EMUL_IMPS: case MOUSEDEV_EMUL_IMPS:
ps2_data[0] |= dz = clamp_val(p->dz, -127, 127);
((p->buttons & 0x10) >> 3) | ((p->buttons & 0x08) >> 1); p->dz -= dz;
ps2_data[3] = mousedev_limit_delta(p->dz, 127);
p->dz -= ps2_data[3]; ps2_data[0] |= ((p->buttons & 0x10) >> 3) |
((p->buttons & 0x08) >> 1);
ps2_data[3] = dz;
client->bufsiz = 4; client->bufsiz = 4;
break; break;
case MOUSEDEV_EMUL_PS2: case MOUSEDEV_EMUL_PS2:
default: default:
ps2_data[0] |=
((p->buttons & 0x10) >> 3) | ((p->buttons & 0x08) >> 1);
p->dz = 0; p->dz = 0;
ps2_data[0] |= ((p->buttons & 0x10) >> 3) |
((p->buttons & 0x08) >> 1);
client->bufsiz = 3; client->bufsiz = 3;
break; 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_client *client = file->private_data;
struct mousedev *mousedev = client->mousedev; struct mousedev *mousedev = client->mousedev;
signed char data[sizeof(client->ps2)]; u8 data[sizeof(client->ps2)];
int retval = 0; int retval = 0;
if (!client->ready && !client->buffer && mousedev->exist && if (!client->ready && !client->buffer && mousedev->exist &&