From patchwork Wed Sep 21 09:55:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Walter X-Patchwork-Id: 672747 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sfFS51DG2z9svs for ; Wed, 21 Sep 2016 19:58:12 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bmeHG-0007Np-4J; Wed, 21 Sep 2016 09:57:18 +0000 Received: from mail.sigma-star.at ([95.130.255.111]) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bmeFN-0004sY-TZ for linux-mtd@lists.infradead.org; Wed, 21 Sep 2016 09:56:02 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.sigma-star.at (Postfix) with ESMTP id C082124E0001; Wed, 21 Sep 2016 11:55:04 +0200 (CEST) X-Virus-Scanned: amavisd-new at mail.sigma-star.at Received: from dw (unknown [82.150.214.13]) by mail.sigma-star.at (Postfix) with ESMTPSA id 4B72524E0003; Wed, 21 Sep 2016 11:55:03 +0200 (CEST) Received: by dw (sSMTP sendmail emulation); Wed, 21 Sep 2016 11:55:04 +0200 From: Daniel Walter To: linux-mtd@lists.infradead.org Subject: [PATCH v2 33/46] mtd: nandsim: Relax page size restrictions Date: Wed, 21 Sep 2016 11:55:03 +0200 Message-Id: <9a23a7a5c34f10253e4e333bf547524a5e5a59ab.1474450296.git.dwalter@sigma-star.at> X-Mailer: git-send-email 2.8.3 In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160921_025522_521348_2EA936A3 X-CRM114-Status: GOOD ( 14.30 ) X-Spam-Score: -3.3 (---) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-3.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.4 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] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: boris.brezillon@free-electrons.com, computersforpeace@gmail.com, dwmw2@infradead.org, linux-kernel@vger.kernel.org, Richard Weinberger MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Richard Weinberger Allow any page size as long it is a power of two and less than KMALLOC_MAX_SIZE. Signed-off-by: Richard Weinberger --- drivers/mtd/nand/nandsim.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index 971f7b4..8cfdfea 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c @@ -176,9 +176,6 @@ MODULE_PARM_DESC(bch, "Enable BCH ecc and set how many bits should " MODULE_PARM_DESC(defaults, "Register a MTD during module load using default values and module parametes. " "Set to N if you want to use the nandsimctl user space tool to setup nandsim."); -/* The largest possible page size */ -#define NS_LARGEST_PAGE_SIZE 4096 - /* Busy-wait delay macros (microseconds, milliseconds) */ #define NS_UDELAY(ns, us) \ do { if (ns->do_delays) udelay(us); } while (0) @@ -247,10 +244,8 @@ MODULE_PARM_DESC(defaults, "Register a MTD during module load using default val #define OPT_ANY 0xFFFFFFFF /* any chip supports this operation */ #define OPT_PAGE512 0x00000002 /* 512-byte page chips */ -#define OPT_PAGE2048 0x00000008 /* 2048-byte page chips */ +#define OPT_LARGEPAGE 0x00000008 /* >= 2048-byte page chips */ #define OPT_PAGE512_8BIT 0x00000040 /* 512-byte page chips with 8-bit bus width */ -#define OPT_PAGE4096 0x00000080 /* 4096-byte page chips */ -#define OPT_LARGEPAGE (OPT_PAGE2048 | OPT_PAGE4096) /* 2048 & 4096-byte page chips */ #define OPT_SMALLPAGE (OPT_PAGE512) /* 512-byte page chips */ /* Remove action bits from state */ @@ -858,13 +853,18 @@ static int init_nandsim(struct mtd_info *mtd, struct nandsim_params *nsparam) ns->options |= OPT_PAGE512; if (ns->busw == 8) ns->options |= OPT_PAGE512_8BIT; - } else if (ns->geom.pgsz == 2048) { - ns->options |= OPT_PAGE2048; - } else if (ns->geom.pgsz == 4096) { - ns->options |= OPT_PAGE4096; - } else { - pr_err("unknown page size %u\n", ns->geom.pgsz); - return -EIO; + } else if (ns->geom.pgsz >= 2048) { + ns->options |= OPT_LARGEPAGE; + } + + if (!is_power_of_2(ns->geom.pgsz)) { + pr_err("page size is not a power of two.\n"); + return -EINVAL; + } + + if (ns->geom.pgszoob > KMALLOC_MAX_SIZE) { + pr_err("page size plus oob too large: %u.\n", ns->geom.pgszoob); + return -EINVAL; } if (ns->options & OPT_SMALLPAGE) {