From patchwork Sat Apr 23 17:31:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Williamson X-Patchwork-Id: 729371 Received: from comal.ext.ti.com (comal.ext.ti.com [198.47.26.152]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3NHV0J1013895 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 23 Apr 2011 17:31:27 GMT Received: from dlep33.itg.ti.com ([157.170.170.112]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id p3NHTWAu022281 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 23 Apr 2011 12:29:32 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by dlep33.itg.ti.com (8.13.7/8.13.7) with ESMTP id p3NHTVuW002815; Sat, 23 Apr 2011 12:29:31 -0500 (CDT) Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 51A7B80627; Sat, 23 Apr 2011 12:29:31 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflp53.itg.ti.com (dflp53.itg.ti.com [128.247.5.6]) by linux.omap.com (Postfix) with ESMTP id 8791880626 for ; Sat, 23 Apr 2011 12:29:29 -0500 (CDT) Received: from white.ext.ti.com (localhost [127.0.0.1]) by dflp53.itg.ti.com (8.13.8/8.13.8) with ESMTP id p3NHTS1C007997 for ; Sat, 23 Apr 2011 12:29:28 -0500 (CDT) Received: from psmtp.com (na3sys009amx193.postini.com [74.125.149.174]) by white.ext.ti.com (8.13.7/8.13.7) with SMTP id p3NHTRiW031031 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 23 Apr 2011 12:29:28 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]) (using TLSv1) by na3sys009amx193.postini.com ([74.125.148.10]) with SMTP; Sat, 23 Apr 2011 17:29:28 GMT Received: by iym10 with SMTP id 10so1321675iym.4 for ; Sat, 23 Apr 2011 10:29:27 -0700 (PDT) Received: by 10.231.24.70 with SMTP id u6mr1698192ibb.108.1303579767253; Sat, 23 Apr 2011 10:29:27 -0700 (PDT) Received: from localhost.localdomain (rrcs-24-39-249-130.nys.biz.rr.com [24.39.249.130]) by mx.google.com with ESMTPS id 19sm1551085ibx.52.2011.04.23.10.29.25 (version=SSLv3 cipher=OTHER); Sat, 23 Apr 2011 10:29:26 -0700 (PDT) From: Michael Williamson To: linux-i2c@vger.kernel.org Subject: [PATCH] i2c: davinci: Fix null dereference bug in i2c_davinci_calc_clk_dividers Date: Sat, 23 Apr 2011 13:31:35 -0400 Message-Id: <1303579895-9441-1-git-send-email-michael.williamson@criticallink.com> X-Mailer: git-send-email 1.7.0.4 X-pstn-neptune: 0/0/0.00/0 X-pstn-levels: (S:46.57066/99.90000 CV:99.9000 FC:95.5390 LC:95.5390 R:95.9108 P:95.9108 M:97.0282 C:98.6951 ) X-pstn-settings: 2 (0.5000:0.0750) s cv GT3 gt2 gt1 r p m c X-pstn-addresses: from [db-null] Cc: davinci-linux-open-source@linux.davincidsp.com, ben-linux@fluff.org X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: davinci-linux-open-source-bounces@linux.davincidsp.com Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com X-Greylist: Sender succeeded STARTTLS authentication, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 23 Apr 2011 17:31:49 +0000 (UTC) The davinci-i2c bus driver currently supports being probed with a NULL platform_data structure by using a default configuration when none is provided. However, the i2c_davinci_calc_clk_dividers does not check the provided platform_data for NULL prior to using it, so the support is incomplete. Rather than have each runtime call check for NULL and avoid future problems, copy a pointer to the default data to the device structure during the probe. This should be OK, as the information in this structure is not modified by the driver. Tested on a MityDSP-L138 module (OMAP-L138 based SOM). Signed-off-by: Micahel Williamson --- drivers/i2c/busses/i2c-davinci.c | 12 +++++------- 1 files changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index 5795c83..1db8fc9 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c @@ -163,8 +163,7 @@ static void i2c_recover_bus(struct davinci_i2c_dev *dev) flag |= DAVINCI_I2C_MDR_NACK; /* write the data into mode register */ davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); - if (pdata) - generic_i2c_clock_pulse(pdata->scl_pin); + generic_i2c_clock_pulse(pdata->scl_pin); /* Send STOP */ flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); flag |= DAVINCI_I2C_MDR_STP; @@ -235,10 +234,11 @@ static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev) */ static int i2c_davinci_init(struct davinci_i2c_dev *dev) { - struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; + struct davinci_i2c_platform_data *pdata; - if (!pdata) - pdata = &davinci_i2c_platform_data_default; + if (!dev->dev->platform_data) + dev->dev->platform_data = &davinci_i2c_platform_data_default; + pdata = dev->dev->platform_data; /* put I2C into reset */ davinci_i2c_reset_ctrl(dev, 0); @@ -313,8 +313,6 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) u16 w; int r; - if (!pdata) - pdata = &davinci_i2c_platform_data_default; /* Introduce a delay, required for some boards (e.g Davinci EVM) */ if (pdata->bus_delay) udelay(pdata->bus_delay);