2009-10-14 12:17:32

by Aaro Koskinen

[permalink] [raw]
Subject: [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script

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 <[email protected]>
---
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


2009-10-14 12:17:42

by Aaro Koskinen

[permalink] [raw]
Subject: [PATCH 2/2] mfd: twl4030-power: fix undefined resconfig value checks

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 <[email protected]>
---
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

2009-10-19 16:35:17

by Samuel Ortiz

[permalink] [raw]
Subject: Re: [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script

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 <[email protected]>
> ---
> 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/

2009-10-20 10:21:53

by Aaro Koskinen

[permalink] [raw]
Subject: Re: [PATCH 1/2] mfd: twl4030-power: do not allow negative or zero length script

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 <[email protected]>
>> ---
>> 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
>>
>