From patchwork Fri Aug 17 14:35:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 1338871 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 5B00FDF266 for ; Fri, 17 Aug 2012 14:40:00 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T2NfN-0001Qb-DR; Fri, 17 Aug 2012 14:36:49 +0000 Received: from mail-we0-f177.google.com ([74.125.82.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T2Neb-0001AC-TA; Fri, 17 Aug 2012 14:36:05 +0000 Received: by weyr3 with SMTP id r3so2709764wey.36 for ; Fri, 17 Aug 2012 07:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=VbZ1es93Qp1o8r+FpM7SuiMkhSNtGPnZeyqgyFCiPzE=; b=p5Q7NZXwUJS3wDGCotaNcYezavs138XygxIcCmJ2vnb6YbYTMqs8nD4QfALl4fHMUG U3lVci5af+QInbuP3ftrZZ0cMRzb80UFAxVEB1uGSYQXq8Nmh440MTSB6pbDS1taKOC7 3hjj15L+1b1zbHCAE+Dgvv+mU0Gn/c9PgDwYLG4eSchqh0q4A9rPse0WeTVaB6DXdkWP Y0gVihJCePbW//hPmPS2/Kh0OlSxixvekUI7txwQUCa1kiaCDeLtCVxcQOy9MEM0tNUc 3BvSB387bc4vm59Ir8amttmmZ2ejc3HrIuyOkVwMVjjUZmgtf3lHWhTh9+9wkuWQzarO lt/A== Received: by 10.180.98.200 with SMTP id ek8mr5674667wib.0.1345214153051; Fri, 17 Aug 2012 07:35:53 -0700 (PDT) Received: from localhost.localdomain (lyon.paratronic.fr. [213.41.177.106]) by mx.google.com with ESMTPS id dc3sm10053154wib.7.2012.08.17.07.35.51 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 17 Aug 2012 07:35:52 -0700 (PDT) From: Richard Genoud To: Artem Bityutskiy Subject: [PATCH 2/8] UBI: separate bad_peb_limit in a function Date: Fri, 17 Aug 2012 16:35:18 +0200 Message-Id: <1345214124-5478-3-git-send-email-richard.genoud@gmail.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1345214124-5478-1-git-send-email-richard.genoud@gmail.com> References: <1345214124-5478-1-git-send-email-richard.genoud@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (richard.genoud[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Richard Genoud , linux-mtd@lists.infradead.org, Shmulik Ladkani , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org No functional changes here, just to prepare for next patch. Signed-off-by: Richard Genoud Reviewed-by: Shmulik Ladkani --- drivers/mtd/ubi/build.c | 57 ++++++++++++++++++++++++++++------------------- 1 files changed, 34 insertions(+), 23 deletions(-) diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 738772c..82d11e1 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -565,6 +565,37 @@ void ubi_free_internal_volumes(struct ubi_device *ubi) } } +static int get_bad_peb_limit(const struct ubi_device *ubi, int max_beb_per1024) +{ + int limit, device_pebs; + uint64_t device_size; + + /* + * We don't want a division by 0, and having max_beb_per1024 == 0 is ok + */ + if (!max_beb_per1024) + return 0; + + /* + * Here we are using size of the entire flash chip and + * not just the MTD partition size because the maximum + * number of bad eraseblocks is a percentage of the + * whole device and bad eraseblocks are not fairly + * distributed over the flash chip. So the worst case + * is that all the bad eraseblocks of the chip are in + * the MTD partition we are attaching (ubi->mtd). + */ + device_size = mtd_get_device_size(ubi->mtd); + device_pebs = mtd_div_by_eb(device_size, ubi->mtd); + limit = mult_frac(device_pebs, max_beb_per1024, 1024); + + /* Round it up */ + if (mult_frac(limit, 1024, max_beb_per1024) < device_pebs) + limit += 1; + + return limit; +} + /** * io_init - initialize I/O sub-system for a given UBI device. * @ubi: UBI device description object @@ -582,6 +613,8 @@ void ubi_free_internal_volumes(struct ubi_device *ubi) */ static int io_init(struct ubi_device *ubi) { + const int max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT; + if (ubi->mtd->numeraseregions != 0) { /* * Some flashes have several erase regions. Different regions @@ -610,29 +643,7 @@ static int io_init(struct ubi_device *ubi) if (mtd_can_have_bb(ubi->mtd)) { ubi->bad_allowed = 1; - if (CONFIG_MTD_UBI_BEB_LIMIT > 0) { - int per1024 = CONFIG_MTD_UBI_BEB_LIMIT; - int limit, device_pebs; - uint64_t device_size; - - /* - * Here we are using size of the entire flash chip and - * not just the MTD partition size because the maximum - * number of bad eraseblocks is a percentage of the - * whole device and bad eraseblocks are not fairly - * distributed over the flash chip. So the worst case - * is that all the bad eraseblocks of the chip are in - * the MTD partition we are attaching (ubi->mtd). - */ - device_size = mtd_get_device_size(ubi->mtd); - device_pebs = mtd_div_by_eb(device_size, ubi->mtd); - limit = mult_frac(device_pebs, per1024, 1024); - - /* Round it up */ - if (mult_frac(limit, 1024, per1024) < device_pebs) - limit += 1; - ubi->bad_peb_limit = limit; - } + ubi->bad_peb_limit = get_bad_peb_limit(ubi, max_beb_per1024); } if (ubi->mtd->type == MTD_NORFLASH) {