ALSA: Cleanup redundant tests on unsigned
Subsystems (3)
PATCH 1/1 ALSA: Cleanup redundant tests on unsigned
The variables are unsigned so the test >= 0' is always true, the < 0' test always fails. In these cases the other part of the test catches wrapped values.
In dac_audio_write() there does not occur a test for wrapped values, but the test appears redundant.
---
I think the test in dac_audio_write() can go, or should it change?
sound/oss/sh_dac_audio.c | 3 --- sound/pci/ca0106/ca0106_proc.c | 4 ++-- sound/pci/ctxfi/ctatc.c | 2 +- sound/pci/emu10k1/emu10k1x.c | 3 +-- sound/pci/emu10k1/emuproc.c | 4 ++-- sound/pci/emu10k1/io.c | 2 +- sound/soc/codecs/tlv320aic23.c | 2 +- 7 files changed, 8 insertions(+), 12 deletions(-)
sound/oss/sh_dac_audio.c +0 -3
@@ -164,9 +164,6 @@ static ssize_t dac_audio_write(struct file *file, const char *buf, size_t count,int free;int nbytes; -if (count <0 ) -return -EINVAL ; -if (!count) {dac_audio_sync ();return 0 ;
sound/pci/ca0106/ca0106_proc.c +2 -2
@@ -304,7 +304,7 @@ static void snd_ca0106_proc_reg_write32(struct snd_info_entry *entry,while (!snd_info_get_line (buffer, line,sizeof (line))) {if (sscanf (line,"%x %x" , ®, &val) !=2 )continue ; -if ((reg <0x40 ) && (reg >=0 ) && (val <=0xffffffff ) ) { +if (reg <0x40 && val <=0xffffffff ) {spin_lock_irqsave (&emu->emu_lock, flags);outl (val, emu->port + (reg &0xfffffffc ));spin_unlock_irqrestore (&emu->emu_lock, flags);
@@ -405,7 +405,7 @@ static void snd_ca0106_proc_reg_write(struct snd_info_entry *entry,while (!snd_info_get_line (buffer, line,sizeof (line))) {if (sscanf (line,"%x %x %x" , ®, &channel_id, &val) !=3 )continue ; -if ((reg <0x80 ) && (reg >=0 ) && (val <=0xffffffff ) && (channel_id >=0 ) && (channel_id <=3 ) ) +if (reg <0x80 && val <=0xffffffff && channel_id <=3 )snd_ca0106_ptr_write (emu, reg, channel_id, val); } }
sound/pci/ctxfi/ctatc.c +1 -1
@@ -240,7 +240,7 @@ static int select_rom(unsigned int pitch) }else if (pitch ==0x02000000 ) {/* pitch == 2 */ return 3 ; - }else if (pitch >=0x0 && pitch <=0x08000000 ) { + }else if (pitch <=0x08000000 ) {/* 0 <= pitch <= 8 */ return 0 ; }else {
sound/pci/emu10k1/emu10k1x.c +1 -2
@@ -1040,8 +1040,7 @@ static void snd_emu10k1x_proc_reg_write(struct snd_info_entry *entry,if (sscanf (line,"%x %x %x" , ®, &channel_id, &val) !=3 )continue ; -if ((reg <0x49 ) && (reg >=0 ) && (val <=0xffffffff ) - && (channel_id >=0 ) && (channel_id <=2 ) ) +if (reg <0x49 && val <=0xffffffff && channel_id <=2 )snd_emu10k1x_ptr_write (emu, reg, channel_id, val); } }
sound/pci/emu10k1/emuproc.c +2 -2
@@ -451,7 +451,7 @@ static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry,while (!snd_info_get_line (buffer, line,sizeof (line))) {if (sscanf (line,"%x %x" , ®, &val) !=2 )continue ; -if ((reg <0x40 ) && (reg >=0 ) && (val <=0xffffffff ) ) { +if (reg <0x40 && val <=0xffffffff ) {spin_lock_irqsave (&emu->emu_lock, flags);outl (val, emu->port + (reg &0xfffffffc ));spin_unlock_irqrestore (&emu->emu_lock, flags);
@@ -527,7 +527,7 @@ static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry,while (!snd_info_get_line (buffer, line,sizeof (line))) {if (sscanf (line,"%x %x %x" , ®, &channel_id, &val) !=3 )continue ; -if ((reg <0xa0 ) && (reg >=0 ) && (val <=0xffffffff ) && (channel_id >=0 ) && (channel_id <=3 ) ) +if (reg <0xa0 && val <=0xffffffff && channel_id <=3 )snd_ptr_write (emu, iobase, reg, channel_id, val); } }
sound/pci/emu10k1/io.c +1 -1
@@ -256,7 +256,7 @@ int snd_emu1010_fpga_write(struct snd_emu10k1 * emu, u32 reg, u32 value)if (reg >0x3f )return 1 ; reg +=0x40 ;/* 0x40 upwards are registers. */ -if (value <0 || value >0x3f )/* 0 to 0x3f are values */ +if (value >0x3f )/* 0 to 0x3f are values */ return 1 ;spin_lock_irqsave (&emu->emu_lock, flags);outl (reg, emu->port +A_IOCFG );
sound/soc/codecs/tlv320aic23.c +1 -1
@@ -85,7 +85,7 @@ static int tlv320aic23_write(struct snd_soc_codec *codec, unsigned int reg,* of data into val */ -if ((reg <0 || reg >9 ) && (reg !=15 )) { +if (reg >9 && reg !=15 ) {printk (KERN_WARNING "%s Invalid register R%u\n" , __func__, reg);return -1 ; }
Takashi Iwai
AppliedAt Fri, 23 Oct 2009 16:03:08 +0200,
Quoted 11 lines · Roel Kluin
The variables are unsigned so the test
>= 0' is always true, the< 0' test always fails. In these cases the other part of the test catches wrapped values.In
dac_audio_write()there does not occur a test for wrapped values, but the test appears redundant.Signed-off-by Roel Kluin <[email protected]>---
I think the test indac_audio_write()can go, or should it change?
It's obviously superfluous.
I applied your patch as is now. Thanks!
Takashi
Quoted 121 lines
sound/oss/sh_dac_audio.c | 3 --- sound/pci/ca0106/ca0106_proc.c | 4 ++-- sound/pci/ctxfi/ctatc.c | 2 +- sound/pci/emu10k1/emu10k1x.c | 3 +-- sound/pci/emu10k1/emuproc.c | 4 ++-- sound/pci/emu10k1/io.c | 2 +- sound/soc/codecs/tlv320aic23.c | 2 +- 7 files changed, 8 insertions(+), 12 deletions(-)sound/oss/sh_dac_audio.c +0
-3@@ -164,9 +164,6 @@ static ssize_t dac_audio_write(struct file *file, const char *buf, size_t count,int free;int nbytes; -if (count <0 ) -return -EINVAL ; -if (!count) {dac_audio_sync ();return 0 ;sound/pci/ca0106/ca0106_proc.c +2
-2@@ -304,7 +304,7 @@ static void snd_ca0106_proc_reg_write32(struct snd_info_entry *entry,while (!snd_info_get_line (buffer, line,sizeof (line))) {if (sscanf (line,"%x %x" , ®, &val) !=2 )continue ; -if ((reg <0x40 ) && (reg >=0 ) && (val <=0xffffffff ) ) { +if (reg <0x40 && val <=0xffffffff ) {spin_lock_irqsave (&emu->emu_lock, flags);outl (val, emu->port + (reg &0xfffffffc ));spin_unlock_irqrestore (&emu->emu_lock, flags);@@ -405,7 +405,7 @@ static void snd_ca0106_proc_reg_write(struct snd_info_entry *entry,while (!snd_info_get_line (buffer, line,sizeof (line))) {if (sscanf (line,"%x %x %x" , ®, &channel_id, &val) !=3 )continue ; -if ((reg <0x80 ) && (reg >=0 ) && (val <=0xffffffff ) && (channel_id >=0 ) && (channel_id <=3 ) ) +if (reg <0x80 && val <=0xffffffff && channel_id <=3 )snd_ca0106_ptr_write (emu, reg, channel_id, val); } }sound/pci/ctxfi/ctatc.c +1
-1@@ -240,7 +240,7 @@ static int select_rom(unsigned int pitch) }else if (pitch ==0x02000000 ) {/* pitch == 2 */ return 3 ; - }else if (pitch >=0x0 && pitch <=0x08000000 ) { + }else if (pitch <=0x08000000 ) {/* 0 <= pitch <= 8 */ return 0 ; }else {sound/pci/emu10k1/emu10k1x.c +1
-2@@ -1040,8 +1040,7 @@ static void snd_emu10k1x_proc_reg_write(struct snd_info_entry *entry,if (sscanf (line,"%x %x %x" , ®, &channel_id, &val) !=3 )continue ; -if ((reg <0x49 ) && (reg >=0 ) && (val <=0xffffffff ) - && (channel_id >=0 ) && (channel_id <=2 ) ) +if (reg <0x49 && val <=0xffffffff && channel_id <=2 )snd_emu10k1x_ptr_write (emu, reg, channel_id, val); } }sound/pci/emu10k1/emuproc.c +2
-2@@ -451,7 +451,7 @@ static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry,while (!snd_info_get_line (buffer, line,sizeof (line))) {if (sscanf (line,"%x %x" , ®, &val) !=2 )continue ; -if ((reg <0x40 ) && (reg >=0 ) && (val <=0xffffffff ) ) { +if (reg <0x40 && val <=0xffffffff ) {spin_lock_irqsave (&emu->emu_lock, flags);outl (val, emu->port + (reg &0xfffffffc ));spin_unlock_irqrestore (&emu->emu_lock, flags);@@ -527,7 +527,7 @@ static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry,while (!snd_info_get_line (buffer, line,sizeof (line))) {if (sscanf (line,"%x %x %x" , ®, &channel_id, &val) !=3 )continue ; -if ((reg <0xa0 ) && (reg >=0 ) && (val <=0xffffffff ) && (channel_id >=0 ) && (channel_id <=3 ) ) +if (reg <0xa0 && val <=0xffffffff && channel_id <=3 )snd_ptr_write (emu, iobase, reg, channel_id, val); } }sound/pci/emu10k1/io.c +1
-1@@ -256,7 +256,7 @@ int snd_emu1010_fpga_write(struct snd_emu10k1 * emu, u32 reg, u32 value)if (reg >0x3f )return 1 ; reg +=0x40 ;/* 0x40 upwards are registers. */ -if (value <0 || value >0x3f )/* 0 to 0x3f are values */ +if (value >0x3f )/* 0 to 0x3f are values */ return 1 ;spin_lock_irqsave (&emu->emu_lock, flags);outl (reg, emu->port +A_IOCFG );sound/soc/codecs/tlv320aic23.c +1
-1@@ -85,7 +85,7 @@ static int tlv320aic23_write(struct snd_soc_codec *codec, unsigned int reg,* of data into val */ -if ((reg <0 || reg >9 ) && (reg !=15 )) { +if (reg >9 && reg !=15 ) {printk (KERN_WARNING "%s Invalid register R%u\n" , __func__, reg);return -1 ; }