From patchwork Tue Aug 18 22:06:28 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dimitri.gorokhovik@free.fr X-Patchwork-Id: 31603 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 78477B70B3 for ; Wed, 19 Aug 2009 08:11:33 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1MdWpD-0004oD-4m; Tue, 18 Aug 2009 22:06:39 +0000 Received: from wmproxy1-g27.free.fr ([212.27.42.91]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1MdWp2-0004mc-Uk for linux-mtd@lists.infradead.org; Tue, 18 Aug 2009 22:06:37 +0000 Received: from wmproxy1-g27.free.fr (localhost [127.0.0.1]) by wmproxy1-g27.free.fr (Postfix) with ESMTP id C22FE2E70; Wed, 19 Aug 2009 00:06:27 +0200 (CEST) Received: from zimbra3-e1.priv.proxad.net (zimbra3-e1.priv.proxad.net [172.20.243.153]) by wmproxy1-g27.free.fr (Postfix) with ESMTP id B09CD334D; Wed, 19 Aug 2009 00:06:27 +0200 (CEST) Date: Wed, 19 Aug 2009 00:06:28 +0200 (CEST) From: dimitri.gorokhovik@free.fr To: David Woodhouse , David Woodhouse , Tim Gardner , Scott James Remnant , Julia Lawall , David Brownell Message-ID: <785022442.3397251250633188592.JavaMail.root@zimbra3-e1.priv.proxad.net> In-Reply-To: <605152405.3397101250633087167.JavaMail.root@zimbra3-e1.priv.proxad.net> Subject: [PATCH] nftl: fix offset alignments MIME-Version: 1.0 X-Originating-IP: [79.85.212.132] X-Mailer: Zimbra 5.0 (ZimbraWebClient - [unknown] (Linux)/5.0.15_GA_2815.UBUNTU8_64) X-Authenticated-User: dimitri.gorokhovik@free.fr X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Score: 0.0 (/) Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Arithmetic conversion in the mask computation makes the upper word of the second argument passed down to mtd->read_oob(), be always 0 (assuming 'offs' being a 64-bit signed long long type, and 'mtd->writesize' being a 32-bit unsigned int type). This patch applies over the other one adding masking in nftl_write, "nftl: write support is broken". Signed-off-by: diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c index 665d3eb..d2fd066 100644 --- a/drivers/mtd/nftlcore.c +++ b/drivers/mtd/nftlcore.c @@ -135,16 +135,17 @@ static void nftl_remove_dev(struct mtd_blktrans_dev *dev) int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len, size_t *retlen, uint8_t *buf) { + typeof(offs) mask = mtd->writesize - 1; struct mtd_oob_ops ops; int res; ops.mode = MTD_OOB_PLACE; - ops.ooboffs = offs & (mtd->writesize - 1); + ops.ooboffs = offs & mask; ops.ooblen = len; ops.oobbuf = buf; ops.datbuf = NULL; - res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops); + res = mtd->read_oob(mtd, offs & ~mask, &ops); *retlen = ops.oobretlen; return res; } @@ -155,16 +156,17 @@ int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len, int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len, size_t *retlen, uint8_t *buf) { + typeof(offs) mask = mtd->writesize - 1; struct mtd_oob_ops ops; int res; ops.mode = MTD_OOB_PLACE; - ops.ooboffs = offs & (mtd->writesize - 1); + ops.ooboffs = offs & mask; ops.ooblen = len; ops.oobbuf = buf; ops.datbuf = NULL; - res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); + res = mtd->write_oob(mtd, offs & ~mask, &ops); *retlen = ops.oobretlen; return res; } @@ -177,17 +179,18 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len, static int nftl_write(struct mtd_info *mtd, loff_t offs, size_t len, size_t *retlen, uint8_t *buf, uint8_t *oob) { + typeof(offs) mask = mtd->writesize - 1; struct mtd_oob_ops ops; int res; ops.mode = MTD_OOB_PLACE; - ops.ooboffs = offs & (mtd->writesize - 1); + ops.ooboffs = offs & mask; ops.ooblen = mtd->oobsize; ops.oobbuf = oob; ops.datbuf = buf; ops.len = len; - res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); + res = mtd->write_oob(mtd, offs & ~mask, &ops); *retlen = ops.retlen; return res; }