From patchwork Wed Dec 10 10:20:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sonic Zhang X-Patchwork-Id: 419643 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id CF0141400B7 for ; Wed, 10 Dec 2014 23:57:45 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 924614B7DC; Wed, 10 Dec 2014 13:57:43 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TVtuZhMIfGET; Wed, 10 Dec 2014 13:57:43 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 138B94B7D5; Wed, 10 Dec 2014 13:57:43 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0E1C64B7D5 for ; Wed, 10 Dec 2014 13:57:38 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id P2XRckaD+aU4 for ; Wed, 10 Dec 2014 13:57:37 +0100 (CET) X-Greylist: delayed 8352 seconds by postgrey-1.32 at theia; Wed, 10 Dec 2014 13:57:33 CET X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0075.outbound.protection.outlook.com [65.55.169.75]) by theia.denx.de (Postfix) with ESMTPS id 9A06B4B7D4 for ; Wed, 10 Dec 2014 13:57:33 +0100 (CET) Received: from BY2PR03CA058.namprd03.prod.outlook.com (10.141.249.31) by BL2PR03MB1011.namprd03.prod.outlook.com (10.141.182.149) with Microsoft SMTP Server (TLS) id 15.1.26.15; Wed, 10 Dec 2014 10:23:28 +0000 Received: from BL2FFO11FD038.protection.gbl (2a01:111:f400:7c09::107) by BY2PR03CA058.outlook.office365.com (2a01:111:e400:2c5d::31) with Microsoft SMTP Server (TLS) id 15.1.31.17 via Frontend Transport; Wed, 10 Dec 2014 10:23:28 +0000 Received: from nwd2mta1.analog.com (137.71.25.55) by BL2FFO11FD038.mail.protection.outlook.com (10.173.161.134) with Microsoft SMTP Server (TLS) id 15.1.26.17 via Frontend Transport; Wed, 10 Dec 2014 10:23:27 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.72.140]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id sBAAMqrd023776 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 10 Dec 2014 02:22:52 -0800 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS7.ad.analog.com (10.64.72.140) with Microsoft SMTP Server id 14.3.210.2; Wed, 10 Dec 2014 05:22:20 -0500 Received: from linux.site ([10.99.22.20]) by zeus.spd.analog.com (8.14.6/8.14.6) with ESMTP id sBAAMIAe000347; Wed, 10 Dec 2014 05:22:19 -0500 Received: from nine.ad.analog.com (unknown [10.99.24.95]) by linux.site (Postfix) with ESMTP id ABF613AEBE57; Tue, 9 Dec 2014 19:24:18 -0700 (MST) From: Sonic Zhang To: , Date: Wed, 10 Dec 2014 18:20:53 +0800 Message-ID: <1418206853-29337-1-git-send-email-sonic.adi@gmail.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Matching-Connectors: 130626806076524469; (52f37747-95c3-483a-bd05-08d153b03fac); () X-Forefront-Antispam-Report: CIP:137.71.25.55; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(229853001)(107046002)(47776003)(46102003)(61266001)(20776003)(4396001)(76482003)(62966003)(77156002)(73392002)(36756003)(105596002)(82202001)(77096005)(64706001)(106466001)(120916001)(87936001)(99396003)(87572001)(55446002)(31966008)(81442002)(73972006)(83322999)(33646002)(86362001)(92566001)(50226001)(21056001)(89996001)(50466002)(50986999)(19580405001)(48376002)(19580395003)(6806004); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2PR03MB1011; H:nwd2mta1.analog.com; FPR:; SPF:SoftFail; MLV:sfv; PTR:nwd2mail10.analog.com; MX:1; A:1; LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB1011; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(602002); SRVR:BL2PR03MB1011; X-Forefront-PRVS: 0421BF7135 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning gmail.com discourages use of 137.71.25.55 as permitted sender) Authentication-Results: spf=softfail (sender IP is 137.71.25.55) smtp.mailfrom=sonic.adi@gmail.com; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(402001)(401002)(400003); SRVR:BL2PR03MB1011; Cc: u-boot@lists.denx.de, Sonic Zhang , adi-u-boot-devel@lists.sourceforge.net Subject: [U-Boot] [PATCH] memmove_wd: copy chunk down from big address if parameter to is larger than from X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Sonic Zhang When watchdog is enabled, memmove_wd() always copy chunk up from small address. This damanges overlapped memory data if destination address is smaller than source address. Signed-off-by: Sonic Zhang Acked-by: Simon Glass --- common/image.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/common/image.c b/common/image.c index b75a5ce..e691a51 100644 --- a/common/image.c +++ b/common/image.c @@ -485,12 +485,22 @@ void memmove_wd(void *to, void *from, size_t len, ulong chunksz) return; #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) + if (to > from) { + from += len; + to += len; + } while (len > 0) { size_t tail = (len > chunksz) ? chunksz : len; WATCHDOG_RESET(); + if (to > from) { + to -= tail; + from -= tail; + } memmove(to, from, tail); - to += tail; - from += tail; + if (to < from) { + to += tail; + from += tail; + } len -= tail; } #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */