From patchwork Mon Apr 20 12:49:51 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 19010 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n3KCoRte020379 for ; Mon, 20 Apr 2009 12:50:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754633AbZDTMu0 (ORCPT ); Mon, 20 Apr 2009 08:50:26 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754645AbZDTMu0 (ORCPT ); Mon, 20 Apr 2009 08:50:26 -0400 Received: from smtp.nokia.com ([192.100.105.134]:35472 "EHLO mgw-mx09.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754633AbZDTMuZ (ORCPT ); Mon, 20 Apr 2009 08:50:25 -0400 Received: from vaebh105.NOE.Nokia.com (vaebh105.europe.nokia.com [10.160.244.31]) by mgw-mx09.nokia.com (Switch-3.2.6/Switch-3.2.6) with ESMTP id n3KCo6Xl024122 for ; Mon, 20 Apr 2009 07:50:24 -0500 Received: from esebh102.NOE.Nokia.com ([172.21.138.183]) by vaebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 20 Apr 2009 15:49:54 +0300 Received: from mgw-int02.ntc.nokia.com ([172.21.143.97]) by esebh102.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Mon, 20 Apr 2009 15:49:54 +0300 Received: from localhost.localdomain (esdhcp041167.research.nokia.com [172.21.41.167]) by mgw-int02.ntc.nokia.com (Switch-3.2.5/Switch-3.2.5) with ESMTP id n3KCnqaf005821 for ; Mon, 20 Apr 2009 15:49:53 +0300 From: Amit Kucheria To: linux-omap@vger.kernel.org Subject: [PATCH] twl4030: Add some error checking to twl4030 init Date: Mon, 20 Apr 2009 15:49:51 +0300 Message-Id: <1240231791-21636-1-git-send-email-amit.kucheria@verdurent.com> X-Mailer: git-send-email 1.5.6.3 X-OriginalArrivalTime: 20 Apr 2009 12:49:54.0411 (UTC) FILETIME=[80B1BBB0:01C9C1B6] X-Nokia-AV: Clean Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Check for return values of i2c read/write operations and size of scripts being uploaded to TWL4030 Signed-off-by: Amit Kucheria --- 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; + } } }