Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1651084 > unrolled thread

[PATCH] Input: mousedev - fix implicit conversion warning

Started byNick Desaulniers <nick.desaulniers@gmail.com>
First post2017-05-26 07:30 +0200
Last post2017-06-06 18:20 +0200
Articles 8 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] Input: mousedev - fix implicit conversion warning Nick Desaulniers <nick.desaulniers@gmail.com> - 2017-05-26 07:30 +0200
    [PATCH v2] Input: mousedev - fix implicit conversion warning Nick Desaulniers <nick.desaulniers@gmail.com> - 2017-05-26 17:40 +0200
      [PATCH v3] Input: mousedev - fix implicit conversion warning Nick Desaulniers <nick.desaulniers@gmail.com> - 2017-05-26 17:50 +0200
        Re: [PATCH v3] Input: mousedev - fix implicit conversion warning Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-05-26 19:10 +0200
          Re: [PATCH v3] Input: mousedev - fix implicit conversion warning Nick Desaulniers <nick.desaulniers@gmail.com> - 2017-05-29 21:30 +0200
            Re: [PATCH v3] Input: mousedev - fix implicit conversion warning Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-05-30 04:50 +0200
        [PATCH v4] Input: mousedev - fix implicit conversion warning Nick Desaulniers <nick.desaulniers@gmail.com> - 2017-05-30 07:50 +0200
          Re: [PATCH v4] Input: mousedev - fix implicit conversion warning Nick Desaulniers <nick.desaulniers@gmail.com> - 2017-06-06 18:20 +0200

#1651084 — [PATCH] Input: mousedev - fix implicit conversion warning

FromNick Desaulniers <nick.desaulniers@gmail.com>
Date2017-05-26 07:30 +0200
Subject[PATCH] Input: mousedev - fix implicit conversion warning
Message-ID<tLfYZ-1JS-1@gated-at.bofh.it>
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. An explicit cast silences this
warning.

Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
---
 drivers/input/mousedev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 0e0ff84088fd..816e2431bba8 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -650,7 +650,9 @@ static void mousedev_generate_response(struct mousedev_client *client,
 		break;
 
 	case 0xe9: /* Get info */
-		client->ps2[1] = 0x60; client->ps2[2] = 3; client->ps2[3] = 200;
+		client->ps2[1] = 0x60;
+		client->ps2[2] = 3;
+		client->ps2[3] = (char) 200;
 		client->bufsiz = 4;
 		break;
 
-- 
2.11.0

[toc] | [next] | [standalone]


#1651432 — [PATCH v2] Input: mousedev - fix implicit conversion warning

FromNick Desaulniers <nick.desaulniers@gmail.com>
Date2017-05-26 17:40 +0200
Subject[PATCH v2] Input: mousedev - fix implicit conversion warning
Message-ID<tLpvj-7E0-3@gated-at.bofh.it>
In reply to#1651084
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>
---
* Changed from using an explicit cast to changing the signedness
  of the declaration.

 drivers/input/mousedev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 0e0ff84088fd..c83688eb2ef4 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;
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1651439 — [PATCH v3] Input: mousedev - fix implicit conversion warning

FromNick Desaulniers <nick.desaulniers@gmail.com>
Date2017-05-26 17:50 +0200
Subject[PATCH v3] Input: mousedev - fix implicit conversion warning
Message-ID<tLpEZ-7Hk-11@gated-at.bofh.it>
In reply to#1651432
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];
 
-- 
2.11.0

[toc] | [prev] | [next] | [standalone]


#1651528 — Re: [PATCH v3] Input: mousedev - fix implicit conversion warning

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2017-05-26 19:10 +0200
SubjectRe: [PATCH v3] Input: mousedev - fix implicit conversion warning
Message-ID<tLqUp-ef-11@gated-at.bofh.it>
In reply to#1651439
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.

-- 
Dmitry

[toc] | [prev] | [next] | [standalone]


#1652691 — Re: [PATCH v3] Input: mousedev - fix implicit conversion warning

FromNick Desaulniers <nick.desaulniers@gmail.com>
Date2017-05-29 21:30 +0200
SubjectRe: [PATCH v3] Input: mousedev - fix implicit conversion warning
Message-ID<tMywx-4rU-1@gated-at.bofh.it>
In reply to#1651528
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()?

[toc] | [prev] | [next] | [standalone]


#1652782 — Re: [PATCH v3] Input: mousedev - fix implicit conversion warning

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2017-05-30 04:50 +0200
SubjectRe: [PATCH v3] Input: mousedev - fix implicit conversion warning
Message-ID<tMFom-XX-7@gated-at.bofh.it>
In reply to#1652691
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.

-- 
Dmitry

[toc] | [prev] | [next] | [standalone]


#1652819 — [PATCH v4] Input: mousedev - fix implicit conversion warning

FromNick Desaulniers <nick.desaulniers@gmail.com>
Date2017-05-30 07:50 +0200
Subject[PATCH v4] Input: mousedev - fix implicit conversion warning
Message-ID<tMIcx-30N-5@gated-at.bofh.it>
In reply to#1651439
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

[toc] | [prev] | [next] | [standalone]


#1658910 — Re: [PATCH v4] Input: mousedev - fix implicit conversion warning

FromNick Desaulniers <nick.desaulniers@gmail.com>
Date2017-06-06 18:20 +0200
SubjectRe: [PATCH v4] Input: mousedev - fix implicit conversion warning
Message-ID<tPpn4-2GL-17@gated-at.bofh.it>
In reply to#1652819
ping for re-review

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web