linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script
@ 2009-10-14 12:15 Aaro Koskinen
  2009-10-14 12:15 ` [PATCH 2/2] mfd: twl4030-power: fix undefined resconfig value checks Aaro Koskinen
  2009-10-19 16:37 ` [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script Samuel Ortiz
  0 siblings, 2 replies; 4+ messages in thread
From: Aaro Koskinen @ 2009-10-14 12:15 UTC (permalink / raw)
  To: sameo, linux-kernel

The script length cannot be negative. If the length is zero, return
an error.

The patch eliminates the following compiler warning:

drivers/mfd/twl4030-power.c: In function 'twl4030_power_init':
drivers/mfd/twl4030-power.c:151: warning: 'err' may be used uninitialized in this function
drivers/mfd/twl4030-power.c:151: note: 'err' was declared here

Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com>
---
 drivers/mfd/twl4030-power.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
index d423e0c..eae6cda 100644
--- a/drivers/mfd/twl4030-power.c
+++ b/drivers/mfd/twl4030-power.c
@@ -146,9 +146,9 @@ out:
 }
 
 static int __init twl4030_write_script(u8 address, struct twl4030_ins *script,
-				       int len)
+				       unsigned len)
 {
-	int err;
+	int err = EINVAL;
 
 	for (; len; len--, address++, script++) {
 		if (len == 1) {
-- 
1.6.0.4


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

* [PATCH 2/2] mfd: twl4030-power: fix undefined resconfig value checks
  2009-10-14 12:15 [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script Aaro Koskinen
@ 2009-10-14 12:15 ` Aaro Koskinen
  2009-10-19 16:37 ` [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script Samuel Ortiz
  1 sibling, 0 replies; 4+ messages in thread
From: Aaro Koskinen @ 2009-10-14 12:15 UTC (permalink / raw)
  To: sameo, linux-kernel

The code tries to skip values initialized with -1, but since the values
are unsigned the comparison is always true.

The patch eliminates the following compiler warnings:

drivers/mfd/twl4030-power.c: In function 'twl4030_configure_resource':
drivers/mfd/twl4030-power.c:338: warning: comparison is always true due to limited range of data type
drivers/mfd/twl4030-power.c:358: warning: comparison is always true due to limited range of data type
drivers/mfd/twl4030-power.c:363: warning: comparison is always true due to limited range of data type

Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com>
---
 drivers/mfd/twl4030-power.c |    6 +++---
 include/linux/i2c/twl4030.h |    1 +
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
index eae6cda..2f7c805 100644
--- a/drivers/mfd/twl4030-power.c
+++ b/drivers/mfd/twl4030-power.c
@@ -335,7 +335,7 @@ static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
 		return err;
 	}
 
-	if (rconfig->devgroup >= 0) {
+	if (rconfig->devgroup != TWL4030_RESCONFIG_UNDEF) {
 		grp &= ~DEVGROUP_MASK;
 		grp |= rconfig->devgroup << DEVGROUP_SHIFT;
 		err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
@@ -355,12 +355,12 @@ static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
 		return err;
 	}
 
-	if (rconfig->type >= 0) {
+	if (rconfig->type != TWL4030_RESCONFIG_UNDEF) {
 		type &= ~TYPE_MASK;
 		type |= rconfig->type << TYPE_SHIFT;
 	}
 
-	if (rconfig->type2 >= 0) {
+	if (rconfig->type2 != TWL4030_RESCONFIG_UNDEF) {
 		type &= ~TYPE2_MASK;
 		type |= rconfig->type2 << TYPE2_SHIFT;
 	}
diff --git a/include/linux/i2c/twl4030.h b/include/linux/i2c/twl4030.h
index 508824e..99e5d7b 100644
--- a/include/linux/i2c/twl4030.h
+++ b/include/linux/i2c/twl4030.h
@@ -391,6 +391,7 @@ struct twl4030_resconfig {
 	u8 devgroup;	/* Processor group that Power resource belongs to */
 	u8 type;	/* Power resource addressed, 6 / broadcast message */
 	u8 type2;	/* Power resource addressed, 3 / broadcast message */
+#define TWL4030_RESCONFIG_UNDEF	((u8)-1)
 };
 
 struct twl4030_power_data {
-- 
1.6.0.4


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

* Re: [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script
  2009-10-14 12:15 [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script Aaro Koskinen
  2009-10-14 12:15 ` [PATCH 2/2] mfd: twl4030-power: fix undefined resconfig value checks Aaro Koskinen
@ 2009-10-19 16:37 ` Samuel Ortiz
  2009-10-20 10:21   ` Aaro Koskinen
  1 sibling, 1 reply; 4+ messages in thread
From: Samuel Ortiz @ 2009-10-19 16:37 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-kernel

Hi Aaro,

On Wed, Oct 14, 2009 at 03:15:49PM +0300, Aaro Koskinen wrote:
> The script length cannot be negative. If the length is zero, return
> an error.
> 
> The patch eliminates the following compiler warning:
Out of curiosity, which toolchain are you using ? I cross compile my mfd tree
for ARM, and I dont get this error...

 
> drivers/mfd/twl4030-power.c: In function 'twl4030_power_init':
twl4030_power_init ? Isnt it twl4030_write_script ?

Cheers,
Samuel.


> drivers/mfd/twl4030-power.c:151: warning: 'err' may be used uninitialized in this function
> drivers/mfd/twl4030-power.c:151: note: 'err' was declared here
> 
> Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com>
> ---
>  drivers/mfd/twl4030-power.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
> index d423e0c..eae6cda 100644
> --- a/drivers/mfd/twl4030-power.c
> +++ b/drivers/mfd/twl4030-power.c
> @@ -146,9 +146,9 @@ out:
>  }
>  
>  static int __init twl4030_write_script(u8 address, struct twl4030_ins *script,
> -				       int len)
> +				       unsigned len)
>  {
> -	int err;
> +	int err = EINVAL;
>  
>  	for (; len; len--, address++, script++) {
>  		if (len == 1) {
> -- 
> 1.6.0.4
> 

-- 
Intel Open Source Technology Centre
http://oss.intel.com/

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

* Re: [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script
  2009-10-19 16:37 ` [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script Samuel Ortiz
@ 2009-10-20 10:21   ` Aaro Koskinen
  0 siblings, 0 replies; 4+ messages in thread
From: Aaro Koskinen @ 2009-10-20 10:21 UTC (permalink / raw)
  To: ext Samuel Ortiz; +Cc: linux-kernel@vger.kernel.org

Hello,

Samuel Ortiz wrote:
> On Wed, Oct 14, 2009 at 03:15:49PM +0300, Aaro Koskinen wrote:
>> The script length cannot be negative. If the length is zero, return
>> an error.
>>
>> The patch eliminates the following compiler warning:
> Out of curiosity, which toolchain are you using ? I cross compile my mfd tree
> for ARM, and I dont get this error...

It seems I was accidentally using an older version of CodeSourcery
toolchain (2007q3-51). I tried now with the recent one and warnings
do not appear. I'm still not sure if they were totally bogus or not...

>> drivers/mfd/twl4030-power.c: In function 'twl4030_power_init':
> twl4030_power_init ? Isnt it twl4030_write_script ?

You are right, it seems the compiler does some inlining and
reports a wrong function name.

A.

> Cheers,
> Samuel.
> 
> 
>> drivers/mfd/twl4030-power.c:151: warning: 'err' may be used uninitialized in this function
>> drivers/mfd/twl4030-power.c:151: note: 'err' was declared here
>>
>> Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com>
>> ---
>>  drivers/mfd/twl4030-power.c |    4 ++--
>>  1 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
>> index d423e0c..eae6cda 100644
>> --- a/drivers/mfd/twl4030-power.c
>> +++ b/drivers/mfd/twl4030-power.c
>> @@ -146,9 +146,9 @@ out:
>>  }
>>  
>>  static int __init twl4030_write_script(u8 address, struct twl4030_ins *script,
>> -				       int len)
>> +				       unsigned len)
>>  {
>> -	int err;
>> +	int err = EINVAL;
>>  
>>  	for (; len; len--, address++, script++) {
>>  		if (len == 1) {
>> -- 
>> 1.6.0.4
>>
> 


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

end of thread, other threads:[~2009-10-20 10:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-14 12:15 [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script Aaro Koskinen
2009-10-14 12:15 ` [PATCH 2/2] mfd: twl4030-power: fix undefined resconfig value checks Aaro Koskinen
2009-10-19 16:37 ` [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script Samuel Ortiz
2009-10-20 10:21   ` Aaro Koskinen

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