From patchwork Wed Oct 11 13:30:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrice CHOTARD X-Patchwork-Id: 824417 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yBvyy4tY2z9s7m for ; Thu, 12 Oct 2017 00:31:54 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 770E6C21ECA; Wed, 11 Oct 2017 13:31:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9B708C21E55; Wed, 11 Oct 2017 13:30:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8467DC21E18; Wed, 11 Oct 2017 13:30:51 +0000 (UTC) Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lists.denx.de (Postfix) with ESMTPS id 70B84C21E31 for ; Wed, 11 Oct 2017 13:30:49 +0000 (UTC) Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9BDTTB8030716; Wed, 11 Oct 2017 15:30:45 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2dh2pmwtca-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 11 Oct 2017 15:30:45 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6405A38; Wed, 11 Oct 2017 13:30:44 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag6node3.st.com [10.75.127.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 45A092895; Wed, 11 Oct 2017 13:30:44 +0000 (GMT) Received: from localhost (10.75.127.44) by SFHDAG6NODE3.st.com (10.75.127.18) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Wed, 11 Oct 2017 15:30:43 +0200 From: To: Heiko Schocher , Date: Wed, 11 Oct 2017 15:30:34 +0200 Message-ID: <1507728635-31611-2-git-send-email-patrice.chotard@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507728635-31611-1-git-send-email-patrice.chotard@st.com> References: <1507728635-31611-1-git-send-email-patrice.chotard@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG5NODE3.st.com (10.75.127.15) To SFHDAG6NODE3.st.com (10.75.127.18) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-11_05:, , signatures=0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 1/2] i2c: stm32f7_i2c: fix data abort X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Christophe Kerello As "v" is a local variable in stm32_i2c_choose_solution() "v" has to be copied into "s" to avoid data abort in stm32_i2c_compute_timing(). Signed-off-by: Christophe Kerello Reviewed-by: Patrick DELAUNAY Signed-off-by: Patrice Chotard --- drivers/i2c/stm32f7_i2c.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/i2c/stm32f7_i2c.c b/drivers/i2c/stm32f7_i2c.c index bf5fefa..d519c17 100644 --- a/drivers/i2c/stm32f7_i2c.c +++ b/drivers/i2c/stm32f7_i2c.c @@ -571,6 +571,7 @@ static int stm32_i2c_choose_solution(struct stm32_i2c_setup *setup, u32 dnf_delay; u32 tsync; u16 l, h; + bool sol_found = false; int ret = 0; af_delay_min = setup->analog_filter ? @@ -619,14 +620,15 @@ static int stm32_i2c_choose_solution(struct stm32_i2c_setup *setup, clk_error_prev = clk_error; v->scll = l; v->sclh = h; - s = v; + sol_found = true; + memcpy(s, v, sizeof(*s)); } } } } } - if (!s) { + if (!sol_found) { error("%s: no solution at all\n", __func__); ret = -EPERM; } @@ -638,7 +640,7 @@ static int stm32_i2c_compute_timing(struct stm32_i2c_priv *i2c_priv, struct stm32_i2c_setup *setup, struct stm32_i2c_timings *output) { - struct stm32_i2c_timings *v, *_v, *s; + struct stm32_i2c_timings *v, *_v, s; struct list_head solutions; int ret; @@ -669,21 +671,20 @@ static int stm32_i2c_compute_timing(struct stm32_i2c_priv *i2c_priv, return -EINVAL; } - s = NULL; INIT_LIST_HEAD(&solutions); ret = stm32_i2c_compute_solutions(setup, &solutions); if (ret) goto exit; - ret = stm32_i2c_choose_solution(setup, &solutions, s); + ret = stm32_i2c_choose_solution(setup, &solutions, &s); if (ret) goto exit; - output->presc = s->presc; - output->scldel = s->scldel; - output->sdadel = s->sdadel; - output->scll = s->scll; - output->sclh = s->sclh; + output->presc = s.presc; + output->scldel = s.scldel; + output->sdadel = s.sdadel; + output->scll = s.scll; + output->sclh = s.sclh; debug("%s: Presc: %i, scldel: %i, sdadel: %i, scll: %i, sclh: %i\n", __func__, output->presc, From patchwork Wed Oct 11 13:30:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrice CHOTARD X-Patchwork-Id: 824415 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yBvxs2vYMz9s7m for ; Thu, 12 Oct 2017 00:30:57 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 0F200C21E92; Wed, 11 Oct 2017 13:30:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 31BE2C21E18; Wed, 11 Oct 2017 13:30:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5EC86C21E32; Wed, 11 Oct 2017 13:30:51 +0000 (UTC) Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lists.denx.de (Postfix) with ESMTPS id 6CEFEC21E18 for ; Wed, 11 Oct 2017 13:30:49 +0000 (UTC) Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9BDOBAE026895; Wed, 11 Oct 2017 15:30:45 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2dg8bn7kee-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 11 Oct 2017 15:30:45 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2BC953F; Wed, 11 Oct 2017 13:30:45 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag6node3.st.com [10.75.127.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1232C2893; Wed, 11 Oct 2017 13:30:45 +0000 (GMT) Received: from localhost (10.75.127.44) by SFHDAG6NODE3.st.com (10.75.127.18) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Wed, 11 Oct 2017 15:30:44 +0200 From: To: Heiko Schocher , Date: Wed, 11 Oct 2017 15:30:35 +0200 Message-ID: <1507728635-31611-3-git-send-email-patrice.chotard@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507728635-31611-1-git-send-email-patrice.chotard@st.com> References: <1507728635-31611-1-git-send-email-patrice.chotard@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG3NODE1.st.com (10.75.127.7) To SFHDAG6NODE3.st.com (10.75.127.18) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-11_05:, , signatures=0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 2/2] i2c: stm32f7_i2c: fix usage of useless local variable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Patrice Chotard Remove useless local variable "s" and use directly function's parameter "output" Signed-off-by: Patrice Chotard Reviewed-by: Simon Glass --- drivers/i2c/stm32f7_i2c.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/stm32f7_i2c.c b/drivers/i2c/stm32f7_i2c.c index d519c17..610a9ef 100644 --- a/drivers/i2c/stm32f7_i2c.c +++ b/drivers/i2c/stm32f7_i2c.c @@ -640,7 +640,7 @@ static int stm32_i2c_compute_timing(struct stm32_i2c_priv *i2c_priv, struct stm32_i2c_setup *setup, struct stm32_i2c_timings *output) { - struct stm32_i2c_timings *v, *_v, s; + struct stm32_i2c_timings *v, *_v; struct list_head solutions; int ret; @@ -676,16 +676,10 @@ static int stm32_i2c_compute_timing(struct stm32_i2c_priv *i2c_priv, if (ret) goto exit; - ret = stm32_i2c_choose_solution(setup, &solutions, &s); + ret = stm32_i2c_choose_solution(setup, &solutions, output); if (ret) goto exit; - output->presc = s.presc; - output->scldel = s.scldel; - output->sdadel = s.sdadel; - output->scll = s.scll; - output->sclh = s.sclh; - debug("%s: Presc: %i, scldel: %i, sdadel: %i, scll: %i, sclh: %i\n", __func__, output->presc, output->scldel, output->sdadel,