Skip to contentSkip to conversation

sound:pci:Change return type of function, shift_bits in xonar_dg.c to avoid overflow

PATCH In review Nicholas Krause 3 participants 3 messages Mar 12, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sound:pci:Change return type of function, shift_bits in xonar_dg.c to avoid overflow

This changes the return type of the function,shift_bits to unsigned long in order to avoid overflowing issues with this function when called as found when running sparse on the kernel source tree.

---
 sound/pci/oxygen/xonar_dg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/oxygen/xonar_dg.c +1 -1
index 4cf3200..2337a76 100644
@@ -238,7 +238,7 @@ void set_cs4245_adc_params(struct oxygen *chip,
 	cs4245_write_spi(chip, CS4245_MCLK_FREQ);
 }
 
-static inline unsigned int shift_bits(unsigned int value,
+static inline unsigned long shift_bits(unsigned int value,
 				      unsigned int shift_from,
 				      unsigned int shift_to,
 				      unsigned int mask)
Signature · 1 line
2.1.0
#1 lore raw

Re: [PATCH] sound:pci:Change return type of function,shift_bits in xonar_dg.c to avoid overflow

At Thu, 12 Mar 2015 00:35:46 -0400,

Quoted 4 lines · Nicholas Krause

This changes the return type of the function,shift_bits to unsigned long in order to avoid overflowing issues with this function when called as found when running sparse on the kernel source tree.

What overflows exactly? Did you follow the code?

thanks,

Takashi

Quoted 22 lines
---
 sound/pci/oxygen/xonar_dg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/oxygen/xonar_dg.c +1 -1
index 4cf3200..2337a76 100644
@@ -238,7 +238,7 @@ void set_cs4245_adc_params(struct oxygen *chip,
 	cs4245_write_spi(chip, CS4245_MCLK_FREQ);
 }
 
-static inline unsigned int shift_bits(unsigned int value,
+static inline unsigned long shift_bits(unsigned int value,
 				      unsigned int shift_from,
 				      unsigned int shift_to,
 				      unsigned int mask)
Signature · 1 line
2.1.0
maintainer
#2 lore raw
In reply to Nicholas Krause
Quoted 3 lines · Nicholas Krause

This changes the return type of the function,shift_bits to unsigned long in order to avoid overflowing issues with this function when called as found when running sparse on the kernel source tree.

sparse is just a tool to help finding problems. The goal is not to do something to shut it up, but the remove the actual problem.

In this case, if the return type of shift_bits() were a problem, you would have just moved the problem to its caller where the value is then returned as unsigned int anyway.

Stop spamming us with patches for code that you do not understand.

Regards,
Clemens

Quoted 18 lines
---
 sound/pci/oxygen/xonar_dg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/oxygen/xonar_dg.c +1 -1
index 4cf3200..2337a76 100644
@@ -238,7 +238,7 @@ void set_cs4245_adc_params(struct oxygen *chip,
 	cs4245_write_spi(chip, CS4245_MCLK_FREQ);
 }
 
-static inline unsigned int shift_bits(unsigned int value,
+static inline unsigned long shift_bits(unsigned int value,
 				      unsigned int shift_from,
 				      unsigned int shift_to,
 				      unsigned int mask)