From patchwork Wed Aug 7 07:34:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wang Haitao X-Patchwork-Id: 265364 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 632FF2C00E7 for ; Wed, 7 Aug 2013 17:32:36 +1000 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6yE1-00010Y-GR; Wed, 07 Aug 2013 07:32:05 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6yDy-0006aH-5G; Wed, 07 Aug 2013 07:32:02 +0000 Received: from mx5.zte.com.cn ([63.217.80.70] helo=zte.com.cn) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6yDn-0006Ys-UF for linux-mtd@lists.infradead.org; Wed, 07 Aug 2013 07:31:53 +0000 Received: from mse02.zte.com.cn (unknown [10.30.3.21]) by Websense Email Security Gateway with ESMTPS id E83C612A1AA1; Wed, 7 Aug 2013 15:30:59 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse02.zte.com.cn with ESMTP id r777UxNh032698; Wed, 7 Aug 2013 15:30:59 +0800 (GMT-8) (envelope-from wang.haitao1@zte.com.cn) Received: from ztewanghaitao ([10.74.208.48]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP4) with ESMTP id 2013080715311824-81274 ; Wed, 7 Aug 2013 15:31:18 +0800 From: "Wang Haitao" To: Subject: [PATCH]mtd: map: fixed bug in 64-bit systems Date: Wed, 7 Aug 2013 15:34:20 +0800 Message-ID: <001f01ce9340$8880b750$998225f0$@haitao1@zte.com.cn> MIME-Version: 1.0 X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac6TQIe46B9MMuYaQDWr+M0oxn5oxQ== X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP4|March 27, 2013) at 2013-08-07 15:31:18, Serialize by Router on notes_smtp/zte_ltd(Release 8.5.3FP1 HF212|May 23, 2012) at 2013-08-07 15:30:57, Serialize complete at 2013-08-07 15:30:57 Content-Language: zh-cn X-MAIL: mse02.zte.com.cn r777UxNh032698 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130807_033152_515474_EACE1827 X-CRM114-Status: UNSURE ( 1.52 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- 1.0 MSGID_MULTIPLE_AT Message-ID contains multiple '@' characters -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: artem.bityutskiy@linux.intel.com, dwmw2@infradead.org, wang.haitao1@zte.com.cn X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Hardware: CPU:XLP832,the 64-bit OS NOR Flash:S29GL128S 128M Software: Kernel:2.6.32.41 Filesystem:JFFS2 When writing files, errors appear: Write len 182 but return retlen 180 Write of 182 bytes at 0x072c815c failed. returned -5, retlen 180 Write len 186 but return retlen 184 Write of 186 bytes at 0x072caff4 failed. returned -5, retlen 184 These errors exist only in 64-bit systems,not in 32-bit systems. After analysis, we found that the left shift operation is wrong in map_word_load_partial. For instance: unsigned char buf[3] ={0x9e,0x3a,0xea}; map_bankwidth(map) is 4; for (i=0; i < 3; i++) { int bitpos; bitpos = (map_bankwidth(map)-1-i)*8; orig.x[0] &= ~(0xff << bitpos); orig.x[0] |= buf[i] << bitpos; } The value of orig.x[0] is expected to be 0x9e3aeaff, but in this situation(64-bit System) we'll get the wrong value of 0xffffffff9e3aeaff due to the 64-bit sign extension: buf[i] is defined as "unsigned char" and the left-shift operation will convert it to the type of "signed int", so when left-shift buf[i] by 24 bits, the final result will get the wrong value: 0xffffffff9e3aeaff. If the left-shift bits are less than 24, then sign extension will not occur. Whereas the bankwidth of the nor flash we used is 4, therefore this BUG emerges. Signed-off-by:Pang Xunlei Signed-off-by: Zhang Yi Signed-off-by:Lu Zhongjun Reviewed-by: Jiang Biao Tested-by: Ma Chenggong if (map_bankwidth(map) < MAP_FF_LIMIT) { int bw = 8 * map_bankwidth(map); - r.x[0] = (1 << bw) - 1; + r.x[0] = (1UL << bw) - 1; } else { for (i=0; i