* [PATCH] twl4030: Add some error checking to twl4030 init
@ 2009-04-20 12:49 Amit Kucheria
2009-04-20 20:38 ` Premi, Sanjeev
0 siblings, 1 reply; 9+ messages in thread
From: Amit Kucheria @ 2009-04-20 12:49 UTC (permalink / raw)
To: linux-omap
Check for return values of i2c read/write operations and size of scripts being
uploaded to TWL4030
Signed-off-by: Amit Kucheria <amit.kucheria@verdurent.com>
---
drivers/mfd/twl4030-core.c | 2 +-
drivers/mfd/twl4030-power.c | 52 +++++++++++++++++++++++++++++++-----------
2 files changed, 39 insertions(+), 15 deletions(-)
diff --git a/drivers/mfd/twl4030-core.c b/drivers/mfd/twl4030-core.c
index 769b34b..067b02e 100644
--- a/drivers/mfd/twl4030-core.c
+++ b/drivers/mfd/twl4030-core.c
@@ -358,7 +358,7 @@ EXPORT_SYMBOL(twl4030_i2c_read);
int twl4030_i2c_write_u8(u8 mod_no, u8 value, u8 reg)
{
- /* 2 bytes offset 1 contains the data offset 0 is used by i2c_write */
+ /* 2 bytes: offset 1 contains the data, offset 0 is used by i2c_write */
u8 temp_buffer[2] = { 0 };
/* offset 1 contains the data */
temp_buffer[1] = value;
diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
index 9dc493b..8f5d149 100644
--- a/drivers/mfd/twl4030-power.c
+++ b/drivers/mfd/twl4030-power.c
@@ -257,36 +257,40 @@ static int __init config_warmreset_sequence(u8 address)
return err;
}
-void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
+static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
{
int rconfig_addr;
+ int err;
u8 type;
if (rconfig->resource > NUM_OF_RESOURCES) {
printk(KERN_ERR
"TWL4030 Resource %d does not exist\n",
rconfig->resource);
- return;
+ return -EINVAL;
}
rconfig_addr = res_config_addrs[rconfig->resource];
/* Set resource group */
-
if (rconfig->devgroup >= 0)
- twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
+ err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
rconfig->devgroup << 5,
rconfig_addr + DEVGROUP_OFFSET);
+ if (err < 0) {
+ printk(KERN_ERR
+ "TWL4030 failed to program devgroup");
+ return err;
+ }
/* Set resource types */
-
- if (twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER,
- &type,
- rconfig_addr + TYPE_OFFSET) < 0) {
+ err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &type,
+ rconfig_addr + TYPE_OFFSET);
+ if (err < 0) {
printk(KERN_ERR
- "TWL4030 Resource %d type could not read\n",
- rconfig->resource);
- return;
+ "TWL4030 Resource %d type could not be read\n",
+ rconfig->resource);
+ return err;
}
if (rconfig->type >= 0) {
@@ -299,8 +303,15 @@ void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
type |= rconfig->type2 << 3;
}
- twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
+ err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
type, rconfig_addr + TYPE_OFFSET);
+ if (err < 0) {
+ printk(KERN_ERR
+ "TWL4030 failed to program resource type");
+ return err;
+ }
+
+ return 0;
}
@@ -309,6 +320,12 @@ static int __init load_triton_script(struct twl4030_script *tscript)
u8 address = triton_next_free_address;
int err;
+ /* Make sure the script isn't going beyond last valid address */
+ if ((address + tscript->size) > (END_OF_SCRIPT-1)) {
+ printk(KERN_ERR "TWL4030 script too big error\n");
+ return -EINVAL;
+ }
+
err = twl4030_write_script(address, tscript->script, tscript->size);
if (err)
return err;
@@ -346,15 +363,22 @@ void __init twl4030_power_init(struct twl4030_power_data *triton2_scripts)
for (i = 0; i < triton2_scripts->size; i++) {
err = load_triton_script(triton2_scripts->scripts[i]);
- if (err)
+ if (err < 0) {
+ printk(KERN_ERR "TWL4030 failed to load scripts");
break;
+ }
}
resconfig = triton2_scripts->resource_config;
if (resconfig) {
while (resconfig->resource) {
- twl4030_configure_resource(resconfig);
+ err = twl4030_configure_resource(resconfig);
resconfig++;
+ if (err < 0) {
+ printk(KERN_ERR
+ "TWL4030 failed to configure resource");
+ break;
+ }
}
}
--
1.5.6.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* RE: [PATCH] twl4030: Add some error checking to twl4030 init
2009-04-20 12:49 [PATCH] twl4030: Add some error checking to twl4030 init Amit Kucheria
@ 2009-04-20 20:38 ` Premi, Sanjeev
2009-04-20 21:28 ` Amit Kucheria
0 siblings, 1 reply; 9+ messages in thread
From: Premi, Sanjeev @ 2009-04-20 20:38 UTC (permalink / raw)
To: Amit Kucheria, linux-omap
> -----Original Message-----
> From: linux-omap-owner@vger.kernel.org
> [mailto:linux-omap-owner@vger.kernel.org] On Behalf Of Amit Kucheria
> Sent: Monday, April 20, 2009 6:20 PM
> To: linux-omap@vger.kernel.org
> Subject: [PATCH] twl4030: Add some error checking to twl4030 init
>
> Check for return values of i2c read/write operations and size
> of scripts being
> uploaded to TWL4030
>
> Signed-off-by: Amit Kucheria <amit.kucheria@verdurent.com>
[sp] You may want to fix the leading whitespaces in some places.
see few instanes below.
Otherwise, looks pretty straight.
> ---
> drivers/mfd/twl4030-core.c | 2 +-
> drivers/mfd/twl4030-power.c | 52
> +++++++++++++++++++++++++++++++-----------
> 2 files changed, 39 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/mfd/twl4030-core.c b/drivers/mfd/twl4030-core.c
> index 769b34b..067b02e 100644
> --- a/drivers/mfd/twl4030-core.c
> +++ b/drivers/mfd/twl4030-core.c
> @@ -358,7 +358,7 @@ EXPORT_SYMBOL(twl4030_i2c_read);
> int twl4030_i2c_write_u8(u8 mod_no, u8 value, u8 reg)
> {
>
> - /* 2 bytes offset 1 contains the data offset 0 is used
> by i2c_write */
> + /* 2 bytes: offset 1 contains the data, offset 0 is
> used by i2c_write */
> u8 temp_buffer[2] = { 0 };
> /* offset 1 contains the data */
> temp_buffer[1] = value;
> diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
> index 9dc493b..8f5d149 100644
> --- a/drivers/mfd/twl4030-power.c
> +++ b/drivers/mfd/twl4030-power.c
> @@ -257,36 +257,40 @@ static int __init
> config_warmreset_sequence(u8 address)
> return err;
> }
>
> -void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
> +static int __init twl4030_configure_resource(struct
> twl4030_resconfig *rconfig)
> {
> int rconfig_addr;
> + int err;
> u8 type;
>
> if (rconfig->resource > NUM_OF_RESOURCES) {
> printk(KERN_ERR
> "TWL4030 Resource %d does not exist\n",
> rconfig->resource);
> - return;
> + return -EINVAL;
> }
>
> rconfig_addr = res_config_addrs[rconfig->resource];
>
> /* Set resource group */
> -
> if (rconfig->devgroup >= 0)
> - twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> + err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> rconfig->devgroup << 5,
> rconfig_addr + DEVGROUP_OFFSET);
> + if (err < 0) {
> + printk(KERN_ERR
> + "TWL4030 failed to program devgroup");
[sp] ...here...
> + return err;
> + }
>
> /* Set resource types */
> -
> - if (twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER,
> - &type,
> - rconfig_addr +
> TYPE_OFFSET) < 0) {
> + err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &type,
> + rconfig_addr + TYPE_OFFSET);
> + if (err < 0) {
> printk(KERN_ERR
> - "TWL4030 Resource %d type could not read\n",
> - rconfig->resource);
> - return;
> + "TWL4030 Resource %d type could not be read\n",
> + rconfig->resource);
[sp] ...here...
> + return err;
> }
>
> if (rconfig->type >= 0) {
> @@ -299,8 +303,15 @@ void twl4030_configure_resource(struct
> twl4030_resconfig *rconfig)
> type |= rconfig->type2 << 3;
> }
>
> - twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> + err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> type, rconfig_addr + TYPE_OFFSET);
> + if (err < 0) {
> + printk(KERN_ERR
> + "TWL4030 failed to program resource type");
[sp] ...here...
> + return err;
> + }
> +
> + return 0;
>
> }
>
> @@ -309,6 +320,12 @@ static int __init
> load_triton_script(struct twl4030_script *tscript)
> u8 address = triton_next_free_address;
> int err;
>
> + /* Make sure the script isn't going beyond last valid address */
> + if ((address + tscript->size) > (END_OF_SCRIPT-1)) {
> + printk(KERN_ERR "TWL4030 script too big error\n");
> + return -EINVAL;
> + }
> +
> err = twl4030_write_script(address, tscript->script,
> tscript->size);
> if (err)
> return err;
> @@ -346,15 +363,22 @@ void __init twl4030_power_init(struct
> twl4030_power_data *triton2_scripts)
>
> for (i = 0; i < triton2_scripts->size; i++) {
> err = load_triton_script(triton2_scripts->scripts[i]);
> - if (err)
> + if (err < 0) {
> + printk(KERN_ERR "TWL4030 failed to load
> scripts");
> break;
> + }
> }
>
> resconfig = triton2_scripts->resource_config;
> if (resconfig) {
> while (resconfig->resource) {
> - twl4030_configure_resource(resconfig);
> + err = twl4030_configure_resource(resconfig);
> resconfig++;
> + if (err < 0) {
> + printk(KERN_ERR
> + "TWL4030 failed to
[sp] ...here...
> configure resource");
> + break;
> + }
> }
> }
>
> --
> 1.5.6.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] twl4030: Add some error checking to twl4030 init
2009-04-20 20:38 ` Premi, Sanjeev
@ 2009-04-20 21:28 ` Amit Kucheria
2009-04-22 13:11 ` Peter 'p2' De Schrijver
2009-04-23 21:16 ` David Brownell
0 siblings, 2 replies; 9+ messages in thread
From: Amit Kucheria @ 2009-04-20 21:28 UTC (permalink / raw)
To: linux-omap
Whitespace-fixed version and passed through checkpatch.pl
Check for return values of i2c read/write operations and size of scripts being
uploaded to TWL4030
Signed-off-by: Amit Kucheria <amit.kucheria@verdurent.com>
---
drivers/mfd/twl4030-core.c | 2 +-
drivers/mfd/twl4030-power.c | 49 ++++++++++++++++++++++++++++++------------
2 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/drivers/mfd/twl4030-core.c b/drivers/mfd/twl4030-core.c
index 769b34b..067b02e 100644
--- a/drivers/mfd/twl4030-core.c
+++ b/drivers/mfd/twl4030-core.c
@@ -358,7 +358,7 @@ EXPORT_SYMBOL(twl4030_i2c_read);
int twl4030_i2c_write_u8(u8 mod_no, u8 value, u8 reg)
{
- /* 2 bytes offset 1 contains the data offset 0 is used by i2c_write */
+ /* 2 bytes: offset 1 contains the data, offset 0 is used by i2c_write */
u8 temp_buffer[2] = { 0 };
/* offset 1 contains the data */
temp_buffer[1] = value;
diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
index 9dc493b..b4b636d 100644
--- a/drivers/mfd/twl4030-power.c
+++ b/drivers/mfd/twl4030-power.c
@@ -257,36 +257,38 @@ static int __init config_warmreset_sequence(u8 address)
return err;
}
-void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
+static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
{
int rconfig_addr;
+ int err;
u8 type;
if (rconfig->resource > NUM_OF_RESOURCES) {
printk(KERN_ERR
"TWL4030 Resource %d does not exist\n",
rconfig->resource);
- return;
+ return -EINVAL;
}
rconfig_addr = res_config_addrs[rconfig->resource];
/* Set resource group */
-
if (rconfig->devgroup >= 0)
- twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
+ err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
rconfig->devgroup << 5,
rconfig_addr + DEVGROUP_OFFSET);
+ if (err < 0) {
+ printk(KERN_ERR "TWL4030 failed to program devgroup");
+ return err;
+ }
/* Set resource types */
-
- if (twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER,
- &type,
- rconfig_addr + TYPE_OFFSET) < 0) {
- printk(KERN_ERR
- "TWL4030 Resource %d type could not read\n",
+ err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &type,
+ rconfig_addr + TYPE_OFFSET);
+ if (err < 0) {
+ printk(KERN_ERR "TWL4030 Resource %d type could not be read\n",
rconfig->resource);
- return;
+ return err;
}
if (rconfig->type >= 0) {
@@ -299,8 +301,14 @@ void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
type |= rconfig->type2 << 3;
}
- twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
+ err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
type, rconfig_addr + TYPE_OFFSET);
+ if (err < 0) {
+ printk(KERN_ERR "TWL4030 failed to program resource type");
+ return err;
+ }
+
+ return 0;
}
@@ -309,6 +317,12 @@ static int __init load_triton_script(struct twl4030_script *tscript)
u8 address = triton_next_free_address;
int err;
+ /* Make sure the script isn't going beyond last valid address */
+ if ((address + tscript->size) > (END_OF_SCRIPT-1)) {
+ printk(KERN_ERR "TWL4030 script too big error\n");
+ return -EINVAL;
+ }
+
err = twl4030_write_script(address, tscript->script, tscript->size);
if (err)
return err;
@@ -346,15 +360,22 @@ void __init twl4030_power_init(struct twl4030_power_data *triton2_scripts)
for (i = 0; i < triton2_scripts->size; i++) {
err = load_triton_script(triton2_scripts->scripts[i]);
- if (err)
+ if (err < 0) {
+ printk(KERN_ERR "TWL4030 failed to load scripts");
break;
+ }
}
resconfig = triton2_scripts->resource_config;
if (resconfig) {
while (resconfig->resource) {
- twl4030_configure_resource(resconfig);
+ err = twl4030_configure_resource(resconfig);
resconfig++;
+ if (err < 0) {
+ printk(KERN_ERR
+ "TWL4030 failed to configure resource");
+ break;
+ }
}
}
--
1.6.0.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] twl4030: Add some error checking to twl4030 init
2009-04-20 21:28 ` Amit Kucheria
@ 2009-04-22 13:11 ` Peter 'p2' De Schrijver
2009-04-23 21:16 ` David Brownell
1 sibling, 0 replies; 9+ messages in thread
From: Peter 'p2' De Schrijver @ 2009-04-22 13:11 UTC (permalink / raw)
To: ext Amit Kucheria; +Cc: linux-omap
Hi,
> Whitespace-fixed version and passed through checkpatch.pl
>
> Check for return values of i2c read/write operations and size of scripts being
> uploaded to TWL4030
>
> Signed-off-by: Amit Kucheria <amit.kucheria@verdurent.com>
Acked-by: Peter De Schrijver <peter.de-schrijver@nokia.com>
--
goa is a state of mind
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] twl4030: Add some error checking to twl4030 init
2009-04-20 21:28 ` Amit Kucheria
2009-04-22 13:11 ` Peter 'p2' De Schrijver
@ 2009-04-23 21:16 ` David Brownell
2009-05-06 12:03 ` [PATCH] " Amit Kucheria
1 sibling, 1 reply; 9+ messages in thread
From: David Brownell @ 2009-04-23 21:16 UTC (permalink / raw)
To: Amit Kucheria; +Cc: linux-omap
On Monday 20 April 2009, Amit Kucheria wrote:
> Whitespace-fixed version and passed through checkpatch.pl
>
> Check for return values of i2c read/write operations and size of scripts being
> uploaded to TWL4030
>
> Signed-off-by: Amit Kucheria <amit.kucheria@verdurent.com>
> ---
> drivers/mfd/twl4030-core.c | 2 +-
> drivers/mfd/twl4030-power.c | 49 ++++++++++++++++++++++++++++++------------
The changes look OK ... but what this needs is to be
split into two patches. The -core one should go to
mainline; it's trivial, comment-only, unrelated to the
$SUBJECT patch. The -power one seems OK for merge to
the OMAP tree.
(Of course, the -power driver should probably go mainline
at some point. Once it stops breaking warm-reset!)
> 2 files changed, 36 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/mfd/twl4030-core.c b/drivers/mfd/twl4030-core.c
> index 769b34b..067b02e 100644
> --- a/drivers/mfd/twl4030-core.c
> +++ b/drivers/mfd/twl4030-core.c
> @@ -358,7 +358,7 @@ EXPORT_SYMBOL(twl4030_i2c_read);
> int twl4030_i2c_write_u8(u8 mod_no, u8 value, u8 reg)
> {
>
> - /* 2 bytes offset 1 contains the data offset 0 is used by i2c_write */
> + /* 2 bytes: offset 1 contains the data, offset 0 is used by i2c_write */
> u8 temp_buffer[2] = { 0 };
> /* offset 1 contains the data */
> temp_buffer[1] = value;
> diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
> index 9dc493b..b4b636d 100644
> --- a/drivers/mfd/twl4030-power.c
> +++ b/drivers/mfd/twl4030-power.c
> @@ -257,36 +257,38 @@ static int __init config_warmreset_sequence(u8 address)
> return err;
> }
>
> -void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
> +static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
> {
> int rconfig_addr;
> + int err;
> u8 type;
>
> if (rconfig->resource > NUM_OF_RESOURCES) {
> printk(KERN_ERR
> "TWL4030 Resource %d does not exist\n",
> rconfig->resource);
> - return;
> + return -EINVAL;
> }
>
> rconfig_addr = res_config_addrs[rconfig->resource];
>
> /* Set resource group */
> -
> if (rconfig->devgroup >= 0)
> - twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> + err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> rconfig->devgroup << 5,
> rconfig_addr + DEVGROUP_OFFSET);
> + if (err < 0) {
> + printk(KERN_ERR "TWL4030 failed to program devgroup");
> + return err;
> + }
>
> /* Set resource types */
> -
> - if (twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER,
> - &type,
> - rconfig_addr + TYPE_OFFSET) < 0) {
> - printk(KERN_ERR
> - "TWL4030 Resource %d type could not read\n",
> + err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &type,
> + rconfig_addr + TYPE_OFFSET);
> + if (err < 0) {
> + printk(KERN_ERR "TWL4030 Resource %d type could not be read\n",
> rconfig->resource);
> - return;
> + return err;
> }
>
> if (rconfig->type >= 0) {
> @@ -299,8 +301,14 @@ void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
> type |= rconfig->type2 << 3;
> }
>
> - twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> + err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> type, rconfig_addr + TYPE_OFFSET);
> + if (err < 0) {
> + printk(KERN_ERR "TWL4030 failed to program resource type");
> + return err;
> + }
> +
> + return 0;
>
> }
>
> @@ -309,6 +317,12 @@ static int __init load_triton_script(struct twl4030_script *tscript)
> u8 address = triton_next_free_address;
> int err;
>
> + /* Make sure the script isn't going beyond last valid address */
> + if ((address + tscript->size) > (END_OF_SCRIPT-1)) {
> + printk(KERN_ERR "TWL4030 script too big error\n");
> + return -EINVAL;
> + }
> +
> err = twl4030_write_script(address, tscript->script, tscript->size);
> if (err)
> return err;
> @@ -346,15 +360,22 @@ void __init twl4030_power_init(struct twl4030_power_data *triton2_scripts)
>
> for (i = 0; i < triton2_scripts->size; i++) {
> err = load_triton_script(triton2_scripts->scripts[i]);
> - if (err)
> + if (err < 0) {
> + printk(KERN_ERR "TWL4030 failed to load scripts");
> break;
> + }
> }
>
> resconfig = triton2_scripts->resource_config;
> if (resconfig) {
> while (resconfig->resource) {
> - twl4030_configure_resource(resconfig);
> + err = twl4030_configure_resource(resconfig);
> resconfig++;
> + if (err < 0) {
> + printk(KERN_ERR
> + "TWL4030 failed to configure resource");
> + break;
> + }
> }
> }
>
> --
> 1.6.0.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] [PATCH] twl4030: Add some error checking to twl4030 init
2009-04-23 21:16 ` David Brownell
@ 2009-05-06 12:03 ` Amit Kucheria
2009-06-03 8:49 ` Amit Kucheria
2009-06-03 16:53 ` [APPLIED] " Tony Lindgren
0 siblings, 2 replies; 9+ messages in thread
From: Amit Kucheria @ 2009-05-06 12:03 UTC (permalink / raw)
To: linux-omap
Check for return values of i2c read/write operations and size of scripts being
uploaded to TWL4030
(Removed the unrelated string changes based on David Brownell's comment)
Signed-off-by: Amit Kucheria <amit.kucheria@verdurent.com>
---
drivers/mfd/twl4030-power.c | 52 +++++++++++++++++++++++++++++++-----------
1 files changed, 38 insertions(+), 14 deletions(-)
diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
index 9dc493b..8f5d149 100644
--- a/drivers/mfd/twl4030-power.c
+++ b/drivers/mfd/twl4030-power.c
@@ -257,36 +257,40 @@ static int __init config_warmreset_sequence(u8 address)
return err;
}
-void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
+static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
{
int rconfig_addr;
+ int err;
u8 type;
if (rconfig->resource > NUM_OF_RESOURCES) {
printk(KERN_ERR
"TWL4030 Resource %d does not exist\n",
rconfig->resource);
- return;
+ return -EINVAL;
}
rconfig_addr = res_config_addrs[rconfig->resource];
/* Set resource group */
-
if (rconfig->devgroup >= 0)
- twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
+ err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
rconfig->devgroup << 5,
rconfig_addr + DEVGROUP_OFFSET);
+ if (err < 0) {
+ printk(KERN_ERR
+ "TWL4030 failed to program devgroup");
+ return err;
+ }
/* Set resource types */
-
- if (twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER,
- &type,
- rconfig_addr + TYPE_OFFSET) < 0) {
+ err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &type,
+ rconfig_addr + TYPE_OFFSET);
+ if (err < 0) {
printk(KERN_ERR
- "TWL4030 Resource %d type could not read\n",
- rconfig->resource);
- return;
+ "TWL4030 Resource %d type could not be read\n",
+ rconfig->resource);
+ return err;
}
if (rconfig->type >= 0) {
@@ -299,8 +303,15 @@ void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
type |= rconfig->type2 << 3;
}
- twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
+ err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
type, rconfig_addr + TYPE_OFFSET);
+ if (err < 0) {
+ printk(KERN_ERR
+ "TWL4030 failed to program resource type");
+ return err;
+ }
+
+ return 0;
}
@@ -309,6 +320,12 @@ static int __init load_triton_script(struct twl4030_script *tscript)
u8 address = triton_next_free_address;
int err;
+ /* Make sure the script isn't going beyond last valid address */
+ if ((address + tscript->size) > (END_OF_SCRIPT-1)) {
+ printk(KERN_ERR "TWL4030 script too big error\n");
+ return -EINVAL;
+ }
+
err = twl4030_write_script(address, tscript->script, tscript->size);
if (err)
return err;
@@ -346,15 +363,22 @@ void __init twl4030_power_init(struct twl4030_power_data *triton2_scripts)
for (i = 0; i < triton2_scripts->size; i++) {
err = load_triton_script(triton2_scripts->scripts[i]);
- if (err)
+ if (err < 0) {
+ printk(KERN_ERR "TWL4030 failed to load scripts");
break;
+ }
}
resconfig = triton2_scripts->resource_config;
if (resconfig) {
while (resconfig->resource) {
- twl4030_configure_resource(resconfig);
+ err = twl4030_configure_resource(resconfig);
resconfig++;
+ if (err < 0) {
+ printk(KERN_ERR
+ "TWL4030 failed to configure resource");
+ break;
+ }
}
}
--
1.6.0.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] [PATCH] twl4030: Add some error checking to twl4030 init
2009-05-06 12:03 ` [PATCH] " Amit Kucheria
@ 2009-06-03 8:49 ` Amit Kucheria
2009-06-03 16:53 ` Tony Lindgren
2009-06-03 16:53 ` [APPLIED] " Tony Lindgren
1 sibling, 1 reply; 9+ messages in thread
From: Amit Kucheria @ 2009-06-03 8:49 UTC (permalink / raw)
To: linux-omap
Bump..
This patch was acked by David Brownell earlier in the thread.
Regards,
Amit
On Wed, May 06, 2009 at 03:03:38PM +0300, Amit Kucheria wrote:
> Check for return values of i2c read/write operations and size of scripts being
> uploaded to TWL4030
>
> (Removed the unrelated string changes based on David Brownell's comment)
>
> Signed-off-by: Amit Kucheria <amit.kucheria@verdurent.com>
> ---
> drivers/mfd/twl4030-power.c | 52 +++++++++++++++++++++++++++++++-----------
> 1 files changed, 38 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
> index 9dc493b..8f5d149 100644
> --- a/drivers/mfd/twl4030-power.c
> +++ b/drivers/mfd/twl4030-power.c
> @@ -257,36 +257,40 @@ static int __init config_warmreset_sequence(u8 address)
> return err;
> }
>
> -void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
> +static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
> {
> int rconfig_addr;
> + int err;
> u8 type;
>
> if (rconfig->resource > NUM_OF_RESOURCES) {
> printk(KERN_ERR
> "TWL4030 Resource %d does not exist\n",
> rconfig->resource);
> - return;
> + return -EINVAL;
> }
>
> rconfig_addr = res_config_addrs[rconfig->resource];
>
> /* Set resource group */
> -
> if (rconfig->devgroup >= 0)
> - twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> + err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> rconfig->devgroup << 5,
> rconfig_addr + DEVGROUP_OFFSET);
> + if (err < 0) {
> + printk(KERN_ERR
> + "TWL4030 failed to program devgroup");
> + return err;
> + }
>
> /* Set resource types */
> -
> - if (twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER,
> - &type,
> - rconfig_addr + TYPE_OFFSET) < 0) {
> + err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &type,
> + rconfig_addr + TYPE_OFFSET);
> + if (err < 0) {
> printk(KERN_ERR
> - "TWL4030 Resource %d type could not read\n",
> - rconfig->resource);
> - return;
> + "TWL4030 Resource %d type could not be read\n",
> + rconfig->resource);
> + return err;
> }
>
> if (rconfig->type >= 0) {
> @@ -299,8 +303,15 @@ void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
> type |= rconfig->type2 << 3;
> }
>
> - twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> + err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> type, rconfig_addr + TYPE_OFFSET);
> + if (err < 0) {
> + printk(KERN_ERR
> + "TWL4030 failed to program resource type");
> + return err;
> + }
> +
> + return 0;
>
> }
>
> @@ -309,6 +320,12 @@ static int __init load_triton_script(struct twl4030_script *tscript)
> u8 address = triton_next_free_address;
> int err;
>
> + /* Make sure the script isn't going beyond last valid address */
> + if ((address + tscript->size) > (END_OF_SCRIPT-1)) {
> + printk(KERN_ERR "TWL4030 script too big error\n");
> + return -EINVAL;
> + }
> +
> err = twl4030_write_script(address, tscript->script, tscript->size);
> if (err)
> return err;
> @@ -346,15 +363,22 @@ void __init twl4030_power_init(struct twl4030_power_data *triton2_scripts)
>
> for (i = 0; i < triton2_scripts->size; i++) {
> err = load_triton_script(triton2_scripts->scripts[i]);
> - if (err)
> + if (err < 0) {
> + printk(KERN_ERR "TWL4030 failed to load scripts");
> break;
> + }
> }
>
> resconfig = triton2_scripts->resource_config;
> if (resconfig) {
> while (resconfig->resource) {
> - twl4030_configure_resource(resconfig);
> + err = twl4030_configure_resource(resconfig);
> resconfig++;
> + if (err < 0) {
> + printk(KERN_ERR
> + "TWL4030 failed to configure resource");
> + break;
> + }
> }
> }
>
> --
> 1.6.0.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
-------------------------------------------------------------------------
Amit Kucheria, Kernel Developer, Verdurent
-------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] [PATCH] twl4030: Add some error checking to twl4030 init
2009-06-03 8:49 ` Amit Kucheria
@ 2009-06-03 16:53 ` Tony Lindgren
0 siblings, 0 replies; 9+ messages in thread
From: Tony Lindgren @ 2009-06-03 16:53 UTC (permalink / raw)
To: linux-omap
* Amit Kucheria <amit.kucheria@verdurent.com> [090603 01:51]:
> Bump..
>
> This patch was acked by David Brownell earlier in the thread.
OK, I add it, but will reset all the twl stuff to mainline after 2.6.30.
These patches need to get submitted to mainline, all the other twl code is
there already.
Tony
> Regards,
> Amit
>
> On Wed, May 06, 2009 at 03:03:38PM +0300, Amit Kucheria wrote:
> > Check for return values of i2c read/write operations and size of scripts being
> > uploaded to TWL4030
> >
> > (Removed the unrelated string changes based on David Brownell's comment)
> >
> > Signed-off-by: Amit Kucheria <amit.kucheria@verdurent.com>
> > ---
> > drivers/mfd/twl4030-power.c | 52 +++++++++++++++++++++++++++++++-----------
> > 1 files changed, 38 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
> > index 9dc493b..8f5d149 100644
> > --- a/drivers/mfd/twl4030-power.c
> > +++ b/drivers/mfd/twl4030-power.c
> > @@ -257,36 +257,40 @@ static int __init config_warmreset_sequence(u8 address)
> > return err;
> > }
> >
> > -void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
> > +static int __init twl4030_configure_resource(struct twl4030_resconfig *rconfig)
> > {
> > int rconfig_addr;
> > + int err;
> > u8 type;
> >
> > if (rconfig->resource > NUM_OF_RESOURCES) {
> > printk(KERN_ERR
> > "TWL4030 Resource %d does not exist\n",
> > rconfig->resource);
> > - return;
> > + return -EINVAL;
> > }
> >
> > rconfig_addr = res_config_addrs[rconfig->resource];
> >
> > /* Set resource group */
> > -
> > if (rconfig->devgroup >= 0)
> > - twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> > + err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> > rconfig->devgroup << 5,
> > rconfig_addr + DEVGROUP_OFFSET);
> > + if (err < 0) {
> > + printk(KERN_ERR
> > + "TWL4030 failed to program devgroup");
> > + return err;
> > + }
> >
> > /* Set resource types */
> > -
> > - if (twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER,
> > - &type,
> > - rconfig_addr + TYPE_OFFSET) < 0) {
> > + err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &type,
> > + rconfig_addr + TYPE_OFFSET);
> > + if (err < 0) {
> > printk(KERN_ERR
> > - "TWL4030 Resource %d type could not read\n",
> > - rconfig->resource);
> > - return;
> > + "TWL4030 Resource %d type could not be read\n",
> > + rconfig->resource);
> > + return err;
> > }
> >
> > if (rconfig->type >= 0) {
> > @@ -299,8 +303,15 @@ void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
> > type |= rconfig->type2 << 3;
> > }
> >
> > - twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> > + err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
> > type, rconfig_addr + TYPE_OFFSET);
> > + if (err < 0) {
> > + printk(KERN_ERR
> > + "TWL4030 failed to program resource type");
> > + return err;
> > + }
> > +
> > + return 0;
> >
> > }
> >
> > @@ -309,6 +320,12 @@ static int __init load_triton_script(struct twl4030_script *tscript)
> > u8 address = triton_next_free_address;
> > int err;
> >
> > + /* Make sure the script isn't going beyond last valid address */
> > + if ((address + tscript->size) > (END_OF_SCRIPT-1)) {
> > + printk(KERN_ERR "TWL4030 script too big error\n");
> > + return -EINVAL;
> > + }
> > +
> > err = twl4030_write_script(address, tscript->script, tscript->size);
> > if (err)
> > return err;
> > @@ -346,15 +363,22 @@ void __init twl4030_power_init(struct twl4030_power_data *triton2_scripts)
> >
> > for (i = 0; i < triton2_scripts->size; i++) {
> > err = load_triton_script(triton2_scripts->scripts[i]);
> > - if (err)
> > + if (err < 0) {
> > + printk(KERN_ERR "TWL4030 failed to load scripts");
> > break;
> > + }
> > }
> >
> > resconfig = triton2_scripts->resource_config;
> > if (resconfig) {
> > while (resconfig->resource) {
> > - twl4030_configure_resource(resconfig);
> > + err = twl4030_configure_resource(resconfig);
> > resconfig++;
> > + if (err < 0) {
> > + printk(KERN_ERR
> > + "TWL4030 failed to configure resource");
> > + break;
> > + }
> > }
> > }
> >
> > --
> > 1.6.0.4
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
>
> --
> -------------------------------------------------------------------------
> Amit Kucheria, Kernel Developer, Verdurent
> -------------------------------------------------------------------------
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [APPLIED] [PATCH] [PATCH] twl4030: Add some error checking to twl4030 init
2009-05-06 12:03 ` [PATCH] " Amit Kucheria
2009-06-03 8:49 ` Amit Kucheria
@ 2009-06-03 16:53 ` Tony Lindgren
1 sibling, 0 replies; 9+ messages in thread
From: Tony Lindgren @ 2009-06-03 16:53 UTC (permalink / raw)
To: linux-omap
This patch has been applied to the linux-omap
by youw fwiendly patch wobot.
Initial commit ID (Likely to change): 944f94235969c15b3012aa4dc832ed3e2f08e4da
PatchWorks
http://patchwork.kernel.org/patch/22012/
Git (Likely to change, and takes a while to get mirrored)
http://git.kernel.org/?p=linux/kernel/git/tmlind/linux-omap-2.6.git;a=commit;h=944f94235969c15b3012aa4dc832ed3e2f08e4da
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2009-06-03 16:53 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-20 12:49 [PATCH] twl4030: Add some error checking to twl4030 init Amit Kucheria
2009-04-20 20:38 ` Premi, Sanjeev
2009-04-20 21:28 ` Amit Kucheria
2009-04-22 13:11 ` Peter 'p2' De Schrijver
2009-04-23 21:16 ` David Brownell
2009-05-06 12:03 ` [PATCH] " Amit Kucheria
2009-06-03 8:49 ` Amit Kucheria
2009-06-03 16:53 ` Tony Lindgren
2009-06-03 16:53 ` [APPLIED] " Tony Lindgren
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.