linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input: alps: fix compatibility with -funsigned-char
@ 2023-03-18 14:42 msizanoen
  2023-03-18 16:25 ` Hans de Goede
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: msizanoen @ 2023-03-18 14:42 UTC (permalink / raw)
  To: Pali Rohár, Dmitry Torokhov, Hans de Goede
  Cc: msizanoen, stable, linux-input, linux-kernel

The AlpsPS/2 code previously relied on the assumption that `char` is a
signed type, which was true on x86 platforms (the only place where this
driver is used) before kernel 6.2. However, on 6.2 and later, this
assumption is broken due to the introduction of -funsigned-char as a new
global compiler flag.

Fix this by explicitly specifying the signedness of `char` when sign
extending the values received from the device.

Fixes: f3f33c677699 ("Input: alps - Rushmore and v7 resolution support")
Cc: stable@vger.kernel.org
Signed-off-by: msizanoen <msizanoen@qtmlabs.xyz>
---
 drivers/input/mouse/alps.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 989228b5a0a4..1c570d373b30 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -2294,20 +2294,20 @@ static int alps_get_v3_v7_resolution(struct psmouse *psmouse, int reg_pitch)
 	if (reg < 0)
 		return reg;
 
-	x_pitch = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
+	x_pitch = (signed char)(reg << 4) >> 4; /* sign extend lower 4 bits */
 	x_pitch = 50 + 2 * x_pitch; /* In 0.1 mm units */
 
-	y_pitch = (char)reg >> 4; /* sign extend upper 4 bits */
+	y_pitch = (signed char)reg >> 4; /* sign extend upper 4 bits */
 	y_pitch = 36 + 2 * y_pitch; /* In 0.1 mm units */
 
 	reg = alps_command_mode_read_reg(psmouse, reg_pitch + 1);
 	if (reg < 0)
 		return reg;
 
-	x_electrode = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
+	x_electrode = (signed char)(reg << 4) >> 4; /* sign extend lower 4 bits */
 	x_electrode = 17 + x_electrode;
 
-	y_electrode = (char)reg >> 4; /* sign extend upper 4 bits */
+	y_electrode = (signed char)reg >> 4; /* sign extend upper 4 bits */
 	y_electrode = 13 + y_electrode;
 
 	x_phys = x_pitch * (x_electrode - 1); /* In 0.1 mm units */
-- 
2.39.2


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

* Re: [PATCH] input: alps: fix compatibility with -funsigned-char
  2023-03-18 14:42 [PATCH] input: alps: fix compatibility with -funsigned-char msizanoen
@ 2023-03-18 16:25 ` Hans de Goede
  2023-03-19  9:56 ` msizanoen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2023-03-18 16:25 UTC (permalink / raw)
  To: msizanoen, Pali Rohár, Dmitry Torokhov
  Cc: stable, linux-input, linux-kernel

Hi,

On 3/18/23 15:42, msizanoen wrote:
> The AlpsPS/2 code previously relied on the assumption that `char` is a
> signed type, which was true on x86 platforms (the only place where this
> driver is used) before kernel 6.2. However, on 6.2 and later, this
> assumption is broken due to the introduction of -funsigned-char as a new
> global compiler flag.
> 
> Fix this by explicitly specifying the signedness of `char` when sign
> extending the values received from the device.
> 
> Fixes: f3f33c677699 ("Input: alps - Rushmore and v7 resolution support")
> Cc: stable@vger.kernel.org
> Signed-off-by: msizanoen <msizanoen@qtmlabs.xyz>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> ---
>  drivers/input/mouse/alps.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
> index 989228b5a0a4..1c570d373b30 100644
> --- a/drivers/input/mouse/alps.c
> +++ b/drivers/input/mouse/alps.c
> @@ -2294,20 +2294,20 @@ static int alps_get_v3_v7_resolution(struct psmouse *psmouse, int reg_pitch)
>  	if (reg < 0)
>  		return reg;
>  
> -	x_pitch = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
> +	x_pitch = (signed char)(reg << 4) >> 4; /* sign extend lower 4 bits */
>  	x_pitch = 50 + 2 * x_pitch; /* In 0.1 mm units */
>  
> -	y_pitch = (char)reg >> 4; /* sign extend upper 4 bits */
> +	y_pitch = (signed char)reg >> 4; /* sign extend upper 4 bits */
>  	y_pitch = 36 + 2 * y_pitch; /* In 0.1 mm units */
>  
>  	reg = alps_command_mode_read_reg(psmouse, reg_pitch + 1);
>  	if (reg < 0)
>  		return reg;
>  
> -	x_electrode = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
> +	x_electrode = (signed char)(reg << 4) >> 4; /* sign extend lower 4 bits */
>  	x_electrode = 17 + x_electrode;
>  
> -	y_electrode = (char)reg >> 4; /* sign extend upper 4 bits */
> +	y_electrode = (signed char)reg >> 4; /* sign extend upper 4 bits */
>  	y_electrode = 13 + y_electrode;
>  
>  	x_phys = x_pitch * (x_electrode - 1); /* In 0.1 mm units */


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

* Re: [PATCH] input: alps: fix compatibility with -funsigned-char
  2023-03-18 14:42 [PATCH] input: alps: fix compatibility with -funsigned-char msizanoen
  2023-03-18 16:25 ` Hans de Goede
@ 2023-03-19  9:56 ` msizanoen
  2023-03-19 16:54   ` Pali Rohár
  2023-03-19 17:45 ` Jason A. Donenfeld
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: msizanoen @ 2023-03-19  9:56 UTC (permalink / raw)
  To: Pali Rohár, Dmitry Torokhov, Hans de Goede
  Cc: stable, linux-input, linux-kernel

Patch confirmed working as expected on real hardware.

Tested-by: msizanoen <msizanoen@qtmlabs.xyz>

On 3/18/23 21:42, msizanoen wrote:
> The AlpsPS/2 code previously relied on the assumption that `char` is a
> signed type, which was true on x86 platforms (the only place where this
> driver is used) before kernel 6.2. However, on 6.2 and later, this
> assumption is broken due to the introduction of -funsigned-char as a new
> global compiler flag.
>
> Fix this by explicitly specifying the signedness of `char` when sign
> extending the values received from the device.
>
> Fixes: f3f33c677699 ("Input: alps - Rushmore and v7 resolution support")
> Cc: stable@vger.kernel.org
> Signed-off-by: msizanoen <msizanoen@qtmlabs.xyz>
> ---
>   drivers/input/mouse/alps.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
> index 989228b5a0a4..1c570d373b30 100644
> --- a/drivers/input/mouse/alps.c
> +++ b/drivers/input/mouse/alps.c
> @@ -2294,20 +2294,20 @@ static int alps_get_v3_v7_resolution(struct psmouse *psmouse, int reg_pitch)
>   	if (reg < 0)
>   		return reg;
>   
> -	x_pitch = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
> +	x_pitch = (signed char)(reg << 4) >> 4; /* sign extend lower 4 bits */
>   	x_pitch = 50 + 2 * x_pitch; /* In 0.1 mm units */
>   
> -	y_pitch = (char)reg >> 4; /* sign extend upper 4 bits */
> +	y_pitch = (signed char)reg >> 4; /* sign extend upper 4 bits */
>   	y_pitch = 36 + 2 * y_pitch; /* In 0.1 mm units */
>   
>   	reg = alps_command_mode_read_reg(psmouse, reg_pitch + 1);
>   	if (reg < 0)
>   		return reg;
>   
> -	x_electrode = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
> +	x_electrode = (signed char)(reg << 4) >> 4; /* sign extend lower 4 bits */
>   	x_electrode = 17 + x_electrode;
>   
> -	y_electrode = (char)reg >> 4; /* sign extend upper 4 bits */
> +	y_electrode = (signed char)reg >> 4; /* sign extend upper 4 bits */
>   	y_electrode = 13 + y_electrode;
>   
>   	x_phys = x_pitch * (x_electrode - 1); /* In 0.1 mm units */

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

* Re: [PATCH] input: alps: fix compatibility with -funsigned-char
  2023-03-19  9:56 ` msizanoen
@ 2023-03-19 16:54   ` Pali Rohár
  0 siblings, 0 replies; 10+ messages in thread
From: Pali Rohár @ 2023-03-19 16:54 UTC (permalink / raw)
  To: msizanoen
  Cc: Dmitry Torokhov, Hans de Goede, stable, linux-input, linux-kernel

On Sunday 19 March 2023 16:56:11 msizanoen wrote:
> Patch confirmed working as expected on real hardware.
> 
> Tested-by: msizanoen <msizanoen@qtmlabs.xyz>

Thank you for testing. Patch looks good, you can add my:

Reviewed-by: Pali Rohár <pali@kernel.org>

Anyway, for future, what do you think about using of s8 and u8 types?
It could prevent this signdness char nightmare.

> On 3/18/23 21:42, msizanoen wrote:
> > The AlpsPS/2 code previously relied on the assumption that `char` is a
> > signed type, which was true on x86 platforms (the only place where this
> > driver is used) before kernel 6.2. However, on 6.2 and later, this
> > assumption is broken due to the introduction of -funsigned-char as a new
> > global compiler flag.
> > 
> > Fix this by explicitly specifying the signedness of `char` when sign
> > extending the values received from the device.
> > 
> > Fixes: f3f33c677699 ("Input: alps - Rushmore and v7 resolution support")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: msizanoen <msizanoen@qtmlabs.xyz>
> > ---
> >   drivers/input/mouse/alps.c | 8 ++++----
> >   1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
> > index 989228b5a0a4..1c570d373b30 100644
> > --- a/drivers/input/mouse/alps.c
> > +++ b/drivers/input/mouse/alps.c
> > @@ -2294,20 +2294,20 @@ static int alps_get_v3_v7_resolution(struct psmouse *psmouse, int reg_pitch)
> >   	if (reg < 0)
> >   		return reg;
> > -	x_pitch = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
> > +	x_pitch = (signed char)(reg << 4) >> 4; /* sign extend lower 4 bits */
> >   	x_pitch = 50 + 2 * x_pitch; /* In 0.1 mm units */
> > -	y_pitch = (char)reg >> 4; /* sign extend upper 4 bits */
> > +	y_pitch = (signed char)reg >> 4; /* sign extend upper 4 bits */
> >   	y_pitch = 36 + 2 * y_pitch; /* In 0.1 mm units */
> >   	reg = alps_command_mode_read_reg(psmouse, reg_pitch + 1);
> >   	if (reg < 0)
> >   		return reg;
> > -	x_electrode = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
> > +	x_electrode = (signed char)(reg << 4) >> 4; /* sign extend lower 4 bits */
> >   	x_electrode = 17 + x_electrode;
> > -	y_electrode = (char)reg >> 4; /* sign extend upper 4 bits */
> > +	y_electrode = (signed char)reg >> 4; /* sign extend upper 4 bits */
> >   	y_electrode = 13 + y_electrode;
> >   	x_phys = x_pitch * (x_electrode - 1); /* In 0.1 mm units */

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

* Re: [PATCH] input: alps: fix compatibility with -funsigned-char
  2023-03-18 14:42 [PATCH] input: alps: fix compatibility with -funsigned-char msizanoen
  2023-03-18 16:25 ` Hans de Goede
  2023-03-19  9:56 ` msizanoen
@ 2023-03-19 17:45 ` Jason A. Donenfeld
  2023-03-19 19:43   ` Pali Rohár
  2023-03-20  0:17 ` [PATCH v2] " msizanoen
  2023-03-20  4:52 ` [PATCH v3] " msizanoen1
  4 siblings, 1 reply; 10+ messages in thread
From: Jason A. Donenfeld @ 2023-03-19 17:45 UTC (permalink / raw)
  To: msizanoen
  Cc: Pali Rohár, Dmitry Torokhov, Hans de Goede, stable,
	linux-input, linux-kernel

Might be wise to clean up a few other ones in that file? Or not. Up to
you:

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 989228b5a0a4..afbf67c2488a 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -852,8 +852,8 @@ static void alps_process_packet_v6(struct psmouse *psmouse)
 			x = y = z = 0;

 		/* Divide 4 since trackpoint's speed is too fast */
-		input_report_rel(dev2, REL_X, (char)x / 4);
-		input_report_rel(dev2, REL_Y, -((char)y / 4));
+		input_report_rel(dev2, REL_X, (signed char)x / 4);
+		input_report_rel(dev2, REL_Y, -((signed char)y / 4));

 		psmouse_report_standard_buttons(dev2, packet[3]);

@@ -1104,8 +1104,8 @@ static void alps_process_trackstick_packet_v7(struct psmouse *psmouse)
 	    ((packet[3] & 0x20) << 1);
 	z = (packet[5] & 0x3f) | ((packet[3] & 0x80) >> 1);

-	input_report_rel(dev2, REL_X, (char)x);
-	input_report_rel(dev2, REL_Y, -((char)y));
+	input_report_rel(dev2, REL_X, (signed char)x);
+	input_report_rel(dev2, REL_Y, -((signed char)y));
 	input_report_abs(dev2, ABS_PRESSURE, z);

 	psmouse_report_standard_buttons(dev2, packet[1]);
diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c
index 5f0d75a45c80..43a1116c5852 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -382,7 +382,7 @@ static unsigned int elan_convert_resolution(u8 val, u8 pattern)
 	 *	((value from firmware) + 3) * 100 = dpi
 	 */
 	int res = pattern <= 0x01 ?
-		(int)(char)val * 10 + 790 : ((int)(char)val + 3) * 100;
+		(int)(signed char)val * 10 + 790 : ((int)(signed char)val + 3) * 100;
 	/*
 	 * We also have to convert dpi to dots/mm (*10/254 to avoid floating
 	 * point).

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

* Re: [PATCH] input: alps: fix compatibility with -funsigned-char
  2023-03-19 17:45 ` Jason A. Donenfeld
@ 2023-03-19 19:43   ` Pali Rohár
  0 siblings, 0 replies; 10+ messages in thread
From: Pali Rohár @ 2023-03-19 19:43 UTC (permalink / raw)
  To: Jason A. Donenfeld
  Cc: msizanoen, Dmitry Torokhov, Hans de Goede, stable, linux-input,
	linux-kernel

On Sunday 19 March 2023 18:45:08 Jason A. Donenfeld wrote:
> Might be wise to clean up a few other ones in that file? Or not. Up to
> you:
> 
> diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
> index 989228b5a0a4..afbf67c2488a 100644
> --- a/drivers/input/mouse/alps.c
> +++ b/drivers/input/mouse/alps.c
> @@ -852,8 +852,8 @@ static void alps_process_packet_v6(struct psmouse *psmouse)
>  			x = y = z = 0;
> 
>  		/* Divide 4 since trackpoint's speed is too fast */
> -		input_report_rel(dev2, REL_X, (char)x / 4);
> -		input_report_rel(dev2, REL_Y, -((char)y / 4));
> +		input_report_rel(dev2, REL_X, (signed char)x / 4);
> +		input_report_rel(dev2, REL_Y, -((signed char)y / 4));

Anyway, is casting here needed at all? Is not just plain -(y / 4) enough?

> 
>  		psmouse_report_standard_buttons(dev2, packet[3]);
> 
> @@ -1104,8 +1104,8 @@ static void alps_process_trackstick_packet_v7(struct psmouse *psmouse)
>  	    ((packet[3] & 0x20) << 1);
>  	z = (packet[5] & 0x3f) | ((packet[3] & 0x80) >> 1);
> 
> -	input_report_rel(dev2, REL_X, (char)x);
> -	input_report_rel(dev2, REL_Y, -((char)y));
> +	input_report_rel(dev2, REL_X, (signed char)x);
> +	input_report_rel(dev2, REL_Y, -((signed char)y));
>  	input_report_abs(dev2, ABS_PRESSURE, z);
> 
>  	psmouse_report_standard_buttons(dev2, packet[1]);
> diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c
> index 5f0d75a45c80..43a1116c5852 100644
> --- a/drivers/input/mouse/elan_i2c_core.c
> +++ b/drivers/input/mouse/elan_i2c_core.c
> @@ -382,7 +382,7 @@ static unsigned int elan_convert_resolution(u8 val, u8 pattern)
>  	 *	((value from firmware) + 3) * 100 = dpi
>  	 */
>  	int res = pattern <= 0x01 ?
> -		(int)(char)val * 10 + 790 : ((int)(char)val + 3) * 100;
> +		(int)(signed char)val * 10 + 790 : ((int)(signed char)val + 3) * 100;
>  	/*
>  	 * We also have to convert dpi to dots/mm (*10/254 to avoid floating
>  	 * point).

Please move elantech change into separate commit/patch. As it has
nothing with alps driver. It is completely different hardware.

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

* [PATCH v2] input: alps: fix compatibility with -funsigned-char
  2023-03-18 14:42 [PATCH] input: alps: fix compatibility with -funsigned-char msizanoen
                   ` (2 preceding siblings ...)
  2023-03-19 17:45 ` Jason A. Donenfeld
@ 2023-03-20  0:17 ` msizanoen
  2023-03-20  4:43   ` Dmitry Torokhov
  2023-03-20  4:52 ` [PATCH v3] " msizanoen1
  4 siblings, 1 reply; 10+ messages in thread
From: msizanoen @ 2023-03-20  0:17 UTC (permalink / raw)
  To: msizanoen
  Cc: dmitry.torokhov, hdegoede, linux-input, linux-kernel, pali, stable

The AlpsPS/2 code previously relied on the assumption that `char` is a
signed type, which was true on x86 platforms (the only place where this
driver is used) before kernel 6.2. However, on 6.2 and later, this
assumption is broken due to the introduction of -funsigned-char as a new
global compiler flag.

Fix this by explicitly specifying the signedness of `char` when sign
extending the values received from the device.

v2:
	Add explicit signedness to more places

Fixes: f3f33c677699 ("Input: alps - Rushmore and v7 resolution support")
Cc: stable@vger.kernel.org
Signed-off-by: msizanoen <msizanoen@qtmlabs.xyz>
---
 drivers/input/mouse/alps.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 989228b5a0a4..523ba1196c72 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -852,8 +852,8 @@ static void alps_process_packet_v6(struct psmouse *psmouse)
 			x = y = z = 0;
 
 		/* Divide 4 since trackpoint's speed is too fast */
-		input_report_rel(dev2, REL_X, (char)x / 4);
-		input_report_rel(dev2, REL_Y, -((char)y / 4));
+		input_report_rel(dev2, REL_X, (signed char)x / 4);
+		input_report_rel(dev2, REL_Y, -((signed char)y / 4));
 
 		psmouse_report_standard_buttons(dev2, packet[3]);
 
@@ -1104,8 +1104,8 @@ static void alps_process_trackstick_packet_v7(struct psmouse *psmouse)
 	    ((packet[3] & 0x20) << 1);
 	z = (packet[5] & 0x3f) | ((packet[3] & 0x80) >> 1);
 
-	input_report_rel(dev2, REL_X, (char)x);
-	input_report_rel(dev2, REL_Y, -((char)y));
+	input_report_rel(dev2, REL_X, (signed char)x);
+	input_report_rel(dev2, REL_Y, -((signed char)y));
 	input_report_abs(dev2, ABS_PRESSURE, z);
 
 	psmouse_report_standard_buttons(dev2, packet[1]);
@@ -2294,20 +2294,20 @@ static int alps_get_v3_v7_resolution(struct psmouse *psmouse, int reg_pitch)
 	if (reg < 0)
 		return reg;
 
-	x_pitch = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
+	x_pitch = (signed char)(reg << 4) >> 4; /* sign extend lower 4 bits */
 	x_pitch = 50 + 2 * x_pitch; /* In 0.1 mm units */
 
-	y_pitch = (char)reg >> 4; /* sign extend upper 4 bits */
+	y_pitch = (signed char)reg >> 4; /* sign extend upper 4 bits */
 	y_pitch = 36 + 2 * y_pitch; /* In 0.1 mm units */
 
 	reg = alps_command_mode_read_reg(psmouse, reg_pitch + 1);
 	if (reg < 0)
 		return reg;
 
-	x_electrode = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
+	x_electrode = (signed char)(reg << 4) >> 4; /* sign extend lower 4 bits */
 	x_electrode = 17 + x_electrode;
 
-	y_electrode = (char)reg >> 4; /* sign extend upper 4 bits */
+	y_electrode = (signed char)reg >> 4; /* sign extend upper 4 bits */
 	y_electrode = 13 + y_electrode;
 
 	x_phys = x_pitch * (x_electrode - 1); /* In 0.1 mm units */
-- 
2.39.2


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

* Re: [PATCH v2] input: alps: fix compatibility with -funsigned-char
  2023-03-20  0:17 ` [PATCH v2] " msizanoen
@ 2023-03-20  4:43   ` Dmitry Torokhov
  0 siblings, 0 replies; 10+ messages in thread
From: Dmitry Torokhov @ 2023-03-20  4:43 UTC (permalink / raw)
  To: msizanoen; +Cc: hdegoede, linux-input, linux-kernel, pali, stable

Hi,

On Mon, Mar 20, 2023 at 01:17:31AM +0100, msizanoen wrote:
> The AlpsPS/2 code previously relied on the assumption that `char` is a
> signed type, which was true on x86 platforms (the only place where this
> driver is used) before kernel 6.2. However, on 6.2 and later, this
> assumption is broken due to the introduction of -funsigned-char as a new
> global compiler flag.
> 
> Fix this by explicitly specifying the signedness of `char` when sign
> extending the values received from the device.
> 
> v2:
> 	Add explicit signedness to more places
> 
> Fixes: f3f33c677699 ("Input: alps - Rushmore and v7 resolution support")
> Cc: stable@vger.kernel.org
> Signed-off-by: msizanoen <msizanoen@qtmlabs.xyz>

Please use s8 instead of signed char. Also, could you please tell me if
"msizanoen" is your real name? It is required in the DCO. Apologies if
it really is.

Thanks.

-- 
Dmitry

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

* [PATCH v3] input: alps: fix compatibility with -funsigned-char
  2023-03-18 14:42 [PATCH] input: alps: fix compatibility with -funsigned-char msizanoen
                   ` (3 preceding siblings ...)
  2023-03-20  0:17 ` [PATCH v2] " msizanoen
@ 2023-03-20  4:52 ` msizanoen1
  2023-03-20  6:03   ` Dmitry Torokhov
  4 siblings, 1 reply; 10+ messages in thread
From: msizanoen1 @ 2023-03-20  4:52 UTC (permalink / raw)
  To: msizanoen
  Cc: dmitry.torokhov, hdegoede, linux-input, linux-kernel, pali, stable

From: msizanoen <msizanoen@qtmlabs.xyz>

The AlpsPS/2 code previously relied on the assumption that `char` is a
signed type, which was true on x86 platforms (the only place where this
driver is used) before kernel 6.2. However, on 6.2 and later, this
assumption is broken due to the introduction of -funsigned-char as a new
global compiler flag.

Fix this by explicitly specifying the signedness of `char` when sign
extending the values received from the device.

v2:
	Add explicit signedness to more places

v3:
	Use `s8` instead of `signed char`

Fixes: f3f33c677699 ("Input: alps - Rushmore and v7 resolution support")
Cc: stable@vger.kernel.org
Signed-off-by: msizanoen <msizanoen@qtmlabs.xyz>
---
 drivers/input/mouse/alps.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 989228b5a0a4..e2c11d9f3868 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -852,8 +852,8 @@ static void alps_process_packet_v6(struct psmouse *psmouse)
 			x = y = z = 0;
 
 		/* Divide 4 since trackpoint's speed is too fast */
-		input_report_rel(dev2, REL_X, (char)x / 4);
-		input_report_rel(dev2, REL_Y, -((char)y / 4));
+		input_report_rel(dev2, REL_X, (s8)x / 4);
+		input_report_rel(dev2, REL_Y, -((s8)y / 4));
 
 		psmouse_report_standard_buttons(dev2, packet[3]);
 
@@ -1104,8 +1104,8 @@ static void alps_process_trackstick_packet_v7(struct psmouse *psmouse)
 	    ((packet[3] & 0x20) << 1);
 	z = (packet[5] & 0x3f) | ((packet[3] & 0x80) >> 1);
 
-	input_report_rel(dev2, REL_X, (char)x);
-	input_report_rel(dev2, REL_Y, -((char)y));
+	input_report_rel(dev2, REL_X, (s8)x);
+	input_report_rel(dev2, REL_Y, -((s8)y));
 	input_report_abs(dev2, ABS_PRESSURE, z);
 
 	psmouse_report_standard_buttons(dev2, packet[1]);
@@ -2294,20 +2294,20 @@ static int alps_get_v3_v7_resolution(struct psmouse *psmouse, int reg_pitch)
 	if (reg < 0)
 		return reg;
 
-	x_pitch = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
+	x_pitch = (s8)(reg << 4) >> 4; /* sign extend lower 4 bits */
 	x_pitch = 50 + 2 * x_pitch; /* In 0.1 mm units */
 
-	y_pitch = (char)reg >> 4; /* sign extend upper 4 bits */
+	y_pitch = (s8)reg >> 4; /* sign extend upper 4 bits */
 	y_pitch = 36 + 2 * y_pitch; /* In 0.1 mm units */
 
 	reg = alps_command_mode_read_reg(psmouse, reg_pitch + 1);
 	if (reg < 0)
 		return reg;
 
-	x_electrode = (char)(reg << 4) >> 4; /* sign extend lower 4 bits */
+	x_electrode = (s8)(reg << 4) >> 4; /* sign extend lower 4 bits */
 	x_electrode = 17 + x_electrode;
 
-	y_electrode = (char)reg >> 4; /* sign extend upper 4 bits */
+	y_electrode = (s8)reg >> 4; /* sign extend upper 4 bits */
 	y_electrode = 13 + y_electrode;
 
 	x_phys = x_pitch * (x_electrode - 1); /* In 0.1 mm units */
-- 
2.39.2


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

* Re: [PATCH v3] input: alps: fix compatibility with -funsigned-char
  2023-03-20  4:52 ` [PATCH v3] " msizanoen1
@ 2023-03-20  6:03   ` Dmitry Torokhov
  0 siblings, 0 replies; 10+ messages in thread
From: Dmitry Torokhov @ 2023-03-20  6:03 UTC (permalink / raw)
  To: msizanoen1; +Cc: hdegoede, linux-input, linux-kernel, pali, stable

On Mon, Mar 20, 2023 at 05:52:29AM +0100, msizanoen1 wrote:
> From: msizanoen <msizanoen@qtmlabs.xyz>
> 
> The AlpsPS/2 code previously relied on the assumption that `char` is a
> signed type, which was true on x86 platforms (the only place where this
> driver is used) before kernel 6.2. However, on 6.2 and later, this
> assumption is broken due to the introduction of -funsigned-char as a new
> global compiler flag.
> 
> Fix this by explicitly specifying the signedness of `char` when sign
> extending the values received from the device.
> 
> v2:
> 	Add explicit signedness to more places
> 
> v3:
> 	Use `s8` instead of `signed char`
> 
> Fixes: f3f33c677699 ("Input: alps - Rushmore and v7 resolution support")
> Cc: stable@vger.kernel.org
> Signed-off-by: msizanoen <msizanoen@qtmlabs.xyz>

Applied, thank you.

-- 
Dmitry

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

end of thread, other threads:[~2023-03-20  6:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-18 14:42 [PATCH] input: alps: fix compatibility with -funsigned-char msizanoen
2023-03-18 16:25 ` Hans de Goede
2023-03-19  9:56 ` msizanoen
2023-03-19 16:54   ` Pali Rohár
2023-03-19 17:45 ` Jason A. Donenfeld
2023-03-19 19:43   ` Pali Rohár
2023-03-20  0:17 ` [PATCH v2] " msizanoen
2023-03-20  4:43   ` Dmitry Torokhov
2023-03-20  4:52 ` [PATCH v3] " msizanoen1
2023-03-20  6:03   ` 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).