linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] Input: mma8450 - fix signed 12bits to 32bits conversion
@ 2013-03-27  8:17 seb
  2013-03-28  5:58 ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: seb @ 2013-03-27  8:17 UTC (permalink / raw)
  To: Dmitry Torokhov, Bill Pemberton; +Cc: linux-kernel, seb

Event value is wrong. Should be in range -2048 to 2047, but is in range 0 to 4095.
Use int8_t to int conversion and remove 0xfff mask.

Signed-off-by: seb <sebastien.royen@armadeus.com>
---
 drivers/input/misc/mma8450.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
index 480557f..c3781a1 100644
--- a/drivers/input/misc/mma8450.c
+++ b/drivers/input/misc/mma8450.c
@@ -110,7 +110,7 @@ static void mma8450_poll(struct input_polled_dev *dev)
 	struct mma8450 *m = dev->private;
 	int x, y, z;
 	int ret;
-	u8 buf[6];
+	int8_t buf[6];
 
 	ret = mma8450_read(m, MMA8450_STATUS);
 	if (ret < 0)
@@ -119,13 +119,18 @@ static void mma8450_poll(struct input_polled_dev *dev)
 	if (!(ret & MMA8450_STATUS_ZXYDR))
 		return;
 
-	ret = mma8450_read_block(m, MMA8450_OUT_X_LSB, buf, sizeof(buf));
+	ret = mma8450_read_block(m, MMA8450_OUT_X_LSB, (u8*)buf, sizeof(buf));
 	if (ret < 0)
 		return;
 
-	x = ((buf[1] << 4) & 0xff0) | (buf[0] & 0xf);
-	y = ((buf[3] << 4) & 0xff0) | (buf[2] & 0xf);
-	z = ((buf[5] << 4) & 0xff0) | (buf[4] & 0xf);
+	/* convert 8 MSB from int8_t to int */
+	x = buf[1];
+	y = buf[3];
+	z = buf[5];
+	/* add 4 LSB */
+	x = (x << 4) | (buf[0] & 0xf);
+	y = (y << 4) | (buf[2] & 0xf);
+	z = (z << 4) | (buf[4] & 0xf);
 
 	input_report_abs(dev->input, ABS_X, x);
 	input_report_abs(dev->input, ABS_Y, y);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] Input: mma8450 - fix signed 12bits to 32bits conversion
  2013-03-27  8:17 [PATCH 1/1] Input: mma8450 - fix signed 12bits to 32bits conversion seb
@ 2013-03-28  5:58 ` Dmitry Torokhov
  2013-03-28  7:36   ` Sebastien Royen
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2013-03-28  5:58 UTC (permalink / raw)
  To: seb; +Cc: Bill Pemberton, linux-kernel, seb

Hi Seb,

On Wed, Mar 27, 2013 at 09:17:43AM +0100, seb wrote:
> Event value is wrong. Should be in range -2048 to 2047, but is in range 0 to 4095.
> Use int8_t to int conversion and remove 0xfff mask.
> 
> Signed-off-by: seb <sebastien.royen@armadeus.com>
> ---
>  drivers/input/misc/mma8450.c |   15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
> index 480557f..c3781a1 100644
> --- a/drivers/input/misc/mma8450.c
> +++ b/drivers/input/misc/mma8450.c
> @@ -110,7 +110,7 @@ static void mma8450_poll(struct input_polled_dev *dev)
>  	struct mma8450 *m = dev->private;
>  	int x, y, z;
>  	int ret;
> -	u8 buf[6];
> +	int8_t buf[6];
>  
>  	ret = mma8450_read(m, MMA8450_STATUS);
>  	if (ret < 0)
> @@ -119,13 +119,18 @@ static void mma8450_poll(struct input_polled_dev *dev)
>  	if (!(ret & MMA8450_STATUS_ZXYDR))
>  		return;
>  
> -	ret = mma8450_read_block(m, MMA8450_OUT_X_LSB, buf, sizeof(buf));
> +	ret = mma8450_read_block(m, MMA8450_OUT_X_LSB, (u8*)buf, sizeof(buf));
>  	if (ret < 0)
>  		return;
>  
> -	x = ((buf[1] << 4) & 0xff0) | (buf[0] & 0xf);
> -	y = ((buf[3] << 4) & 0xff0) | (buf[2] & 0xf);
> -	z = ((buf[5] << 4) & 0xff0) | (buf[4] & 0xf);
> +	/* convert 8 MSB from int8_t to int */
> +	x = buf[1];
> +	y = buf[3];
> +	z = buf[5];
> +	/* add 4 LSB */
> +	x = (x << 4) | (buf[0] & 0xf);
> +	y = (y << 4) | (buf[2] & 0xf);
> +	z = (z << 4) | (buf[4] & 0xf);

Should we just say:

	x = ((int)(s8)buf[1] << 4) | (buf[0] & 0xf);
	y = ...
	z = ...

and leave the rest as is?

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] Input: mma8450 - fix signed 12bits to 32bits conversion
  2013-03-28  5:58 ` Dmitry Torokhov
@ 2013-03-28  7:36   ` Sebastien Royen
  2013-03-28  8:14     ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: Sebastien Royen @ 2013-03-28  7:36 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Bill Pemberton, linux-kernel, seb

Hi Dmitry

2013/3/28 Dmitry Torokhov <dmitry.torokhov@gmail.com>
>
> Hi Seb,
>
> On Wed, Mar 27, 2013 at 09:17:43AM +0100, seb wrote:
> > Event value is wrong. Should be in range -2048 to 2047, but is in range 0 to 4095.
> > Use int8_t to int conversion and remove 0xfff mask.
> >
> > Signed-off-by: seb <sebastien.royen@armadeus.com>
> > ---
> >  drivers/input/misc/mma8450.c |   15 ++++++++++-----
> >  1 file changed, 10 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
> > index 480557f..c3781a1 100644
> > --- a/drivers/input/misc/mma8450.c
> > +++ b/drivers/input/misc/mma8450.c
> > @@ -110,7 +110,7 @@ static void mma8450_poll(struct input_polled_dev *dev)
> >       struct mma8450 *m = dev->private;
> >       int x, y, z;
> >       int ret;
> > -     u8 buf[6];
> > +     int8_t buf[6];
> >
> >       ret = mma8450_read(m, MMA8450_STATUS);
> >       if (ret < 0)
> > @@ -119,13 +119,18 @@ static void mma8450_poll(struct input_polled_dev *dev)
> >       if (!(ret & MMA8450_STATUS_ZXYDR))
> >               return;
> >
> > -     ret = mma8450_read_block(m, MMA8450_OUT_X_LSB, buf, sizeof(buf));
> > +     ret = mma8450_read_block(m, MMA8450_OUT_X_LSB, (u8*)buf, sizeof(buf));
> >       if (ret < 0)
> >               return;
> >
> > -     x = ((buf[1] << 4) & 0xff0) | (buf[0] & 0xf);
> > -     y = ((buf[3] << 4) & 0xff0) | (buf[2] & 0xf);
> > -     z = ((buf[5] << 4) & 0xff0) | (buf[4] & 0xf);
> > +     /* convert 8 MSB from int8_t to int */
> > +     x = buf[1];
> > +     y = buf[3];
> > +     z = buf[5];
> > +     /* add 4 LSB */
> > +     x = (x << 4) | (buf[0] & 0xf);
> > +     y = (y << 4) | (buf[2] & 0xf);
> > +     z = (z << 4) | (buf[4] & 0xf);
>
> Should we just say:
>
>         x = ((int)(s8)buf[1] << 4) | (buf[0] & 0xf);
>         y = ...
>         z = ...
>
> and leave the rest as is?
>
> Thanks.
>
> --
> Dmitry

Yes, it works too and is more close to original version.
It's my first contrib so I'm not familiar with process,
do you need another patch with right changes ?

Regards,

Sebastien Royen

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] Input: mma8450 - fix signed 12bits to 32bits conversion
  2013-03-28  7:36   ` Sebastien Royen
@ 2013-03-28  8:14     ` Dmitry Torokhov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2013-03-28  8:14 UTC (permalink / raw)
  To: Sebastien Royen; +Cc: Bill Pemberton, linux-kernel, seb

On Thu, Mar 28, 2013 at 08:36:52AM +0100, Sebastien Royen wrote:
> Hi Dmitry
> 
> 2013/3/28 Dmitry Torokhov <dmitry.torokhov@gmail.com>
> >
> > Hi Seb,
> >
> > On Wed, Mar 27, 2013 at 09:17:43AM +0100, seb wrote:
> > > Event value is wrong. Should be in range -2048 to 2047, but is in range 0 to 4095.
> > > Use int8_t to int conversion and remove 0xfff mask.
> > >
> > > Signed-off-by: seb <sebastien.royen@armadeus.com>
> > > ---
> > >  drivers/input/misc/mma8450.c |   15 ++++++++++-----
> > >  1 file changed, 10 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
> > > index 480557f..c3781a1 100644
> > > --- a/drivers/input/misc/mma8450.c
> > > +++ b/drivers/input/misc/mma8450.c
> > > @@ -110,7 +110,7 @@ static void mma8450_poll(struct input_polled_dev *dev)
> > >       struct mma8450 *m = dev->private;
> > >       int x, y, z;
> > >       int ret;
> > > -     u8 buf[6];
> > > +     int8_t buf[6];
> > >
> > >       ret = mma8450_read(m, MMA8450_STATUS);
> > >       if (ret < 0)
> > > @@ -119,13 +119,18 @@ static void mma8450_poll(struct input_polled_dev *dev)
> > >       if (!(ret & MMA8450_STATUS_ZXYDR))
> > >               return;
> > >
> > > -     ret = mma8450_read_block(m, MMA8450_OUT_X_LSB, buf, sizeof(buf));
> > > +     ret = mma8450_read_block(m, MMA8450_OUT_X_LSB, (u8*)buf, sizeof(buf));
> > >       if (ret < 0)
> > >               return;
> > >
> > > -     x = ((buf[1] << 4) & 0xff0) | (buf[0] & 0xf);
> > > -     y = ((buf[3] << 4) & 0xff0) | (buf[2] & 0xf);
> > > -     z = ((buf[5] << 4) & 0xff0) | (buf[4] & 0xf);
> > > +     /* convert 8 MSB from int8_t to int */
> > > +     x = buf[1];
> > > +     y = buf[3];
> > > +     z = buf[5];
> > > +     /* add 4 LSB */
> > > +     x = (x << 4) | (buf[0] & 0xf);
> > > +     y = (y << 4) | (buf[2] & 0xf);
> > > +     z = (z << 4) | (buf[4] & 0xf);
> >
> > Should we just say:
> >
> >         x = ((int)(s8)buf[1] << 4) | (buf[0] & 0xf);
> >         y = ...
> >         z = ...
> >
> > and leave the rest as is?
> >
> > Thanks.
> >
> > --
> > Dmitry
> 
> Yes, it works too and is more close to original version.
> It's my first contrib so I'm not familiar with process,
> do you need another patch with right changes ?

Yes please as I do not have the hardware to test modified patch.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] Input: mma8450 - fix signed 12bits to 32bits conversion
  2013-03-28 14:16 Sebastien Royen
@ 2013-03-31  7:25 ` Dmitry Torokhov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2013-03-31  7:25 UTC (permalink / raw)
  To: Sebastien Royen; +Cc: Bill Pemberton, linux-kernel, seb

On Thu, Mar 28, 2013 at 03:16:29PM +0100, Sebastien Royen wrote:
> From: seb <sebastien.royen@armadeus.com>
> 
> Event value is wrong. Should be in range -2048 to 2047, but is in range 0 to 4095.
> Use s8 to int conversion and remove 0xfff mask.
> 
> Signed-off-by: Sebastien Royen <sebastien.royen@armadeus.com>

Applied, thank you Sebastien.

> ---
>  drivers/input/misc/mma8450.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
> index 480557f..f330969 100644
> --- a/drivers/input/misc/mma8450.c
> +++ b/drivers/input/misc/mma8450.c
> @@ -123,9 +123,9 @@ static void mma8450_poll(struct input_polled_dev *dev)
>  	if (ret < 0)
>  		return;
>  
> -	x = ((buf[1] << 4) & 0xff0) | (buf[0] & 0xf);
> -	y = ((buf[3] << 4) & 0xff0) | (buf[2] & 0xf);
> -	z = ((buf[5] << 4) & 0xff0) | (buf[4] & 0xf);
> +	x = ((int)(s8)buf[1] << 4) | (buf[0] & 0xf);
> +	y = ((int)(s8)buf[3] << 4) | (buf[2] & 0xf);
> +	z = ((int)(s8)buf[5] << 4) | (buf[4] & 0xf);
>  
>  	input_report_abs(dev->input, ABS_X, x);
>  	input_report_abs(dev->input, ABS_Y, y);
> -- 
> 1.7.9.5
> 

-- 
Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] Input: mma8450 - fix signed 12bits to 32bits conversion
@ 2013-03-28 14:16 Sebastien Royen
  2013-03-31  7:25 ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: Sebastien Royen @ 2013-03-28 14:16 UTC (permalink / raw)
  To: Dmitry Torokhov, Bill Pemberton; +Cc: linux-kernel, seb

From: seb <sebastien.royen@armadeus.com>

Event value is wrong. Should be in range -2048 to 2047, but is in range 0 to 4095.
Use s8 to int conversion and remove 0xfff mask.

Signed-off-by: Sebastien Royen <sebastien.royen@armadeus.com>
---
 drivers/input/misc/mma8450.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
index 480557f..f330969 100644
--- a/drivers/input/misc/mma8450.c
+++ b/drivers/input/misc/mma8450.c
@@ -123,9 +123,9 @@ static void mma8450_poll(struct input_polled_dev *dev)
 	if (ret < 0)
 		return;
 
-	x = ((buf[1] << 4) & 0xff0) | (buf[0] & 0xf);
-	y = ((buf[3] << 4) & 0xff0) | (buf[2] & 0xf);
-	z = ((buf[5] << 4) & 0xff0) | (buf[4] & 0xf);
+	x = ((int)(s8)buf[1] << 4) | (buf[0] & 0xf);
+	y = ((int)(s8)buf[3] << 4) | (buf[2] & 0xf);
+	z = ((int)(s8)buf[5] << 4) | (buf[4] & 0xf);
 
 	input_report_abs(dev->input, ABS_X, x);
 	input_report_abs(dev->input, ABS_Y, y);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-03-31  7:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-27  8:17 [PATCH 1/1] Input: mma8450 - fix signed 12bits to 32bits conversion seb
2013-03-28  5:58 ` Dmitry Torokhov
2013-03-28  7:36   ` Sebastien Royen
2013-03-28  8:14     ` Dmitry Torokhov
2013-03-28 14:16 Sebastien Royen
2013-03-31  7:25 ` Dmitry Torokhov

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).