mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] remove pointless <0 comparisons for unsigned vars, and avoid a few signed vs unsigned comparisons in drivers/char/keyboard.c
@ 2004-11-21 23:21 Jesper Juhl
  2004-11-21 23:44 ` Jesper Juhl
  2005-02-06 19:47 ` Vojtech Pavlik
  0 siblings, 2 replies; 3+ messages in thread
From: Jesper Juhl @ 2004-11-21 23:21 UTC (permalink / raw)
  To: linux-kernel; +Cc: Johan Myreen, Vojtech Pavlik, Andrew Morton


Hi,

Sorry about the possibly irrelevant CC list, but I couldn't find a 
maintainer for drivers/char/keyboard.c listed anywhere, so I ended up 
sending to lkml and CC'ing a few people who has worked on the file, and 
akpm as a fallback person due to his 2.6 maintainer role.

Here's a patch that removes a few pointless comparisons; "scancode" is 
unsigned so it can never be <0 which makes the test pointless.
Also, there are a few instances where signed and unsigned variables are 
comared, and as far as I can tell they really should just all be unsigned.

Comments welcome (I must confess that I've only compile tested this so 
far).

Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>

diff -up linux-2.6.10-rc2-bk6-orig/drivers/char/keyboard.c linux-2.6.10-rc2-bk6/drivers/char/keyboard.c
--- linux-2.6.10-rc2-bk6-orig/drivers/char/keyboard.c	2004-10-18 23:55:36.000000000 +0200
+++ linux-2.6.10-rc2-bk6/drivers/char/keyboard.c	2004-11-22 00:05:45.000000000 +0100
@@ -174,7 +174,7 @@ int getkeycode(unsigned int scancode)
 	if (!dev)
 		return -ENODEV;
 
-	if (scancode < 0 || scancode >= dev->keycodemax)
+	if (scancode >= dev->keycodemax)
 		return -EINVAL;
 
 	return INPUT_KEYCODE(dev, scancode);
@@ -184,7 +184,7 @@ int setkeycode(unsigned int scancode, un
 {
 	struct list_head * node;
 	struct input_dev *dev = NULL;
-	int i, oldkey;
+	unsigned int i, oldkey;
 
 	list_for_each(node,&kbd_handler.h_list) {
 		struct input_handle *handle = to_handle_h(node);
@@ -197,7 +197,7 @@ int setkeycode(unsigned int scancode, un
 	if (!dev)
 		return -ENODEV;
 
-	if (scancode < 0 || scancode >= dev->keycodemax)
+	if (scancode >= dev->keycodemax)
 		return -EINVAL;
 
 	oldkey = SET_INPUT_KEYCODE(dev, scancode, keycode);
@@ -354,7 +354,7 @@ void to_utf8(struct vc_data *vc, ushort 
  */
 void compute_shiftstate(void)
 {
-	int i, j, k, sym, val;
+	unsigned int i, j, k, sym, val;
 
 	shift_state = 0;
 	memset(shift_down, 0, sizeof(shift_down));
@@ -395,7 +395,7 @@ void compute_shiftstate(void)
 unsigned char handle_diacr(struct vc_data *vc, unsigned char ch)
 {
 	int d = diacr;
-	int i;
+	unsigned int i;
 
 	diacr = 0;
 


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

* Re: [PATCH] remove pointless <0 comparisons for unsigned vars, and avoid a few signed vs unsigned comparisons in drivers/char/keyboard.c
  2004-11-21 23:21 [PATCH] remove pointless <0 comparisons for unsigned vars, and avoid a few signed vs unsigned comparisons in drivers/char/keyboard.c Jesper Juhl
@ 2004-11-21 23:44 ` Jesper Juhl
  2005-02-06 19:47 ` Vojtech Pavlik
  1 sibling, 0 replies; 3+ messages in thread
From: Jesper Juhl @ 2004-11-21 23:44 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: linux-kernel, Johan Myreen, Vojtech Pavlik, Andrew Morton

On Mon, 22 Nov 2004, Jesper Juhl wrote:

> 
> Hi,
> 
> Sorry about the possibly irrelevant CC list, but I couldn't find a 
> maintainer for drivers/char/keyboard.c listed anywhere, so I ended up 
> sending to lkml and CC'ing a few people who has worked on the file, and 
> akpm as a fallback person due to his 2.6 maintainer role.
> 
> Here's a patch that removes a few pointless comparisons; "scancode" is 
> unsigned so it can never be <0 which makes the test pointless.
> Also, there are a few instances where signed and unsigned variables are 
> comared, and as far as I can tell they really should just all be unsigned.
> 
> Comments welcome (I must confess that I've only compile tested this so 
> far).
> 

Just boot tested it as well and things seem to be fine on my box.


> Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
> 
> diff -up linux-2.6.10-rc2-bk6-orig/drivers/char/keyboard.c linux-2.6.10-rc2-bk6/drivers/char/keyboard.c
> --- linux-2.6.10-rc2-bk6-orig/drivers/char/keyboard.c	2004-10-18 23:55:36.000000000 +0200
> +++ linux-2.6.10-rc2-bk6/drivers/char/keyboard.c	2004-11-22 00:05:45.000000000 +0100
> @@ -174,7 +174,7 @@ int getkeycode(unsigned int scancode)
>  	if (!dev)
>  		return -ENODEV;
>  
> -	if (scancode < 0 || scancode >= dev->keycodemax)
> +	if (scancode >= dev->keycodemax)
>  		return -EINVAL;
>  
>  	return INPUT_KEYCODE(dev, scancode);
> @@ -184,7 +184,7 @@ int setkeycode(unsigned int scancode, un
>  {
>  	struct list_head * node;
>  	struct input_dev *dev = NULL;
> -	int i, oldkey;
> +	unsigned int i, oldkey;
>  
>  	list_for_each(node,&kbd_handler.h_list) {
>  		struct input_handle *handle = to_handle_h(node);
> @@ -197,7 +197,7 @@ int setkeycode(unsigned int scancode, un
>  	if (!dev)
>  		return -ENODEV;
>  
> -	if (scancode < 0 || scancode >= dev->keycodemax)
> +	if (scancode >= dev->keycodemax)
>  		return -EINVAL;
>  
>  	oldkey = SET_INPUT_KEYCODE(dev, scancode, keycode);
> @@ -354,7 +354,7 @@ void to_utf8(struct vc_data *vc, ushort 
>   */
>  void compute_shiftstate(void)
>  {
> -	int i, j, k, sym, val;
> +	unsigned int i, j, k, sym, val;
>  
>  	shift_state = 0;
>  	memset(shift_down, 0, sizeof(shift_down));
> @@ -395,7 +395,7 @@ void compute_shiftstate(void)
>  unsigned char handle_diacr(struct vc_data *vc, unsigned char ch)
>  {
>  	int d = diacr;
> -	int i;
> +	unsigned int i;
>  
>  	diacr = 0;
>  
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

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

* Re: [PATCH] remove pointless <0 comparisons for unsigned vars, and avoid a few signed vs unsigned comparisons in drivers/char/keyboard.c
  2004-11-21 23:21 [PATCH] remove pointless <0 comparisons for unsigned vars, and avoid a few signed vs unsigned comparisons in drivers/char/keyboard.c Jesper Juhl
  2004-11-21 23:44 ` Jesper Juhl
@ 2005-02-06 19:47 ` Vojtech Pavlik
  1 sibling, 0 replies; 3+ messages in thread
From: Vojtech Pavlik @ 2005-02-06 19:47 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: linux-kernel, Johan Myreen, Andrew Morton

On Mon, Nov 22, 2004 at 12:21:55AM +0100, Jesper Juhl wrote:
> 
> Hi,
> 
> Sorry about the possibly irrelevant CC list, but I couldn't find a 
> maintainer for drivers/char/keyboard.c listed anywhere, so I ended up 
> sending to lkml and CC'ing a few people who has worked on the file, and 
> akpm as a fallback person due to his 2.6 maintainer role.
> 
> Here's a patch that removes a few pointless comparisons; "scancode" is 
> unsigned so it can never be <0 which makes the test pointless.
> Also, there are a few instances where signed and unsigned variables are 
> comared, and as far as I can tell they really should just all be unsigned.
> 
> Comments welcome (I must confess that I've only compile tested this so 
> far).
> 
> Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
 
Looks sane: Applied.

-- 
Vojtech Pavlik
SuSE Labs, SuSE CR

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

end of thread, other threads:[~2005-02-06 19:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-21 23:21 [PATCH] remove pointless <0 comparisons for unsigned vars, and avoid a few signed vs unsigned comparisons in drivers/char/keyboard.c Jesper Juhl
2004-11-21 23:44 ` Jesper Juhl
2005-02-06 19:47 ` Vojtech Pavlik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®