diff mbox

[v3] Input: mousedev - fix implicit conversion warning

Message ID 20170526154029.9405-1-nick.desaulniers@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Nick Desaulniers May 26, 2017, 3:40 p.m. UTC
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.

Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
---
* Additionally change function signature for the lone function dealing
  with ps2 data.

 drivers/input/mousedev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Dmitry Torokhov May 26, 2017, 5:07 p.m. UTC | #1
On Fri, May 26, 2017 at 08:40:28AM -0700, Nick Desaulniers wrote:
> 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.
> 
> Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
> ---
> * Additionally change function signature for the lone function dealing
>   with ps2 data.
> 
>  drivers/input/mousedev.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
> index 0e0ff84088fd..0e31a109b1b4 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;
> @@ -577,7 +577,7 @@ static inline int mousedev_limit_delta(int delta, int limit)
>  }
>  
>  static void mousedev_packet(struct mousedev_client *client,
> -			    signed char *ps2_data)
> +	unsigned char *ps2_data)
>  {
>  	struct mousedev_motion *p = &client->packets[client->tail];

If you look at the code of this fucntion we really use ps2_data as
signed in calculations, and this change would break that. While making
ps2_data u8 might be beneficial we'd need to rework mousedev_packet() to
use signed temporaries for dx, dy and dz before stufifng them into
ps2_data.

Thanks.
Nick Desaulniers May 29, 2017, 7:22 p.m. UTC | #2
On Fri, May 26, 2017 at 10:07:46AM -0700, Dmitry Torokhov wrote:
> If you look at the code of this fucntion we really use ps2_data as
> signed in calculations, and this change would break that. While making
> ps2_data u8 might be beneficial we'd need to rework mousedev_packet() to
> use signed temporaries for dx, dy and dz before stufifng them into
> ps2_data.

Is your recommendation then to stick with the simple cast as in V1 of
this patch, or stick with u8 and rework mousedev_packet()?
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov May 30, 2017, 2:44 a.m. UTC | #3
On Mon, May 29, 2017 at 12:22:52PM -0700, Nick Desaulniers wrote:
> On Fri, May 26, 2017 at 10:07:46AM -0700, Dmitry Torokhov wrote:
> > If you look at the code of this fucntion we really use ps2_data as
> > signed in calculations, and this change would break that. While making
> > ps2_data u8 might be beneficial we'd need to rework mousedev_packet() to
> > use signed temporaries for dx, dy and dz before stufifng them into
> > ps2_data.
> 
> Is your recommendation then to stick with the simple cast as in V1 of
> this patch, or stick with u8 and rework mousedev_packet()?

I think casts are often mysterious, so, unless we'll end up with worse
object code, I'd switch to u8 and temps.
diff mbox

Patch

diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 0e0ff84088fd..0e31a109b1b4 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;
@@ -577,7 +577,7 @@  static inline int mousedev_limit_delta(int delta, int limit)
 }
 
 static void mousedev_packet(struct mousedev_client *client,
-			    signed char *ps2_data)
+	unsigned char *ps2_data)
 {
 	struct mousedev_motion *p = &client->packets[client->tail];