From patchwork Thu Oct 15 13:08:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 55010 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 165352301F for ; Thu, 15 Oct 2015 13:12:06 +0000 (UTC) Received: by lbbpc3 with SMTP id pc3sf10074403lbb.2 for ; Thu, 15 Oct 2015 06:12:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:cc:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=1grst1Jydsd/PZqUdZRsmkbo2hqcbeU3XqznBaTXLDQ=; b=KioGZnXLWgtgwYtk4QhqvvBBepb4rfurBuvGsxtuSIcVl3UHNqZQq+0YZ94TjrTrbv JcO90YKi0Qggavmt3p8QDqaMHMSRNxFQSE0C4M2Hd8k++uSDaBlxXUq/XAC/nPVwWZLp akJ7m9Qczce+0awY0RA5Jf84UuG5oNW99JYO22Sh9dKX7QCerqlmNVW/BGiggCEuo5jG JCTdFavABsGZlTD1+m4aYhIH2LIrQPdSRhgIVRR7iaqKjeWpLngmXaZupH9/oWXAt4w9 nXb0NZEWmCvpuvINdCYw2FpnxWYnNtZ9EIhHB480+Q4dq6UlBF4a4zXn+1bmPFg2GH7t EyvA== X-Gm-Message-State: ALoCoQmb/j1YaewLrE5vTalM9CsAKPt2HycD2F6NOFl5BpMLk7te6JzI6pGTH8rmfWd0uxu1A7BW X-Received: by 10.195.18.100 with SMTP id gl4mr2141871wjd.4.1444914725046; Thu, 15 Oct 2015 06:12:05 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.206.211 with SMTP id e202ls172327lfg.109.gmail; Thu, 15 Oct 2015 06:12:04 -0700 (PDT) X-Received: by 10.112.134.102 with SMTP id pj6mr4570216lbb.14.1444914724895; Thu, 15 Oct 2015 06:12:04 -0700 (PDT) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id wp6si9083436lbb.145.2015.10.15.06.12.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:12:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by lfaz124 with SMTP id z124so27294390lfa.1 for ; Thu, 15 Oct 2015 06:12:04 -0700 (PDT) X-Received: by 10.25.207.82 with SMTP id f79mr2998618lfg.73.1444914724352; Thu, 15 Oct 2015 06:12:04 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp625700lbq; Thu, 15 Oct 2015 06:12:03 -0700 (PDT) X-Received: by 10.66.220.1 with SMTP id ps1mr10240709pac.104.1444914723335; Thu, 15 Oct 2015 06:12:03 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id bw10si21572843pab.111.2015.10.15.06.12.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:12:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZmiJA-0007cq-DW; Thu, 15 Oct 2015 13:11:00 +0000 Received: from mail-lb0-f182.google.com ([209.85.217.182]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZmiI0-0005Ne-UB for linux-arm-kernel@lists.infradead.org; Thu, 15 Oct 2015 13:09:50 +0000 Received: by lbbwb3 with SMTP id wb3so6356468lbb.1 for ; Thu, 15 Oct 2015 06:09:28 -0700 (PDT) X-Received: by 10.112.63.135 with SMTP id g7mr4485624lbs.16.1444914568299; Thu, 15 Oct 2015 06:09:28 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id rf8sm2036081lbb.20.2015.10.15.06.09.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:09:27 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , linux-mtd@lists.infradead.org Subject: [PATCH 06/10] mtd: afs: simplify partition detection Date: Thu, 15 Oct 2015 15:08:49 +0200 Message-Id: <1444914533-27782-7-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1444914533-27782-1-git-send-email-linus.walleij@linaro.org> References: <1444914533-27782-1-git-send-email-linus.walleij@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151015_060949_231589_F5B1F066 X-CRM114-Status: GOOD ( 19.00 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.217.182 listed in wl.mailspike.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.217.182 listed in list.dnswl.org] -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.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Cc: Linus Walleij , Liviu Dudau , Ryan Harkin , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Instead of reading out the AFS footers twice, create a separate function to just check if there is a footer or not. Rids a few local variables and prepare us to join the actual parser into one function. Cc: Ryan Harkin Cc: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/afs.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c index 9e6089615f16..2307f54195f5 100644 --- a/drivers/mtd/afs.c +++ b/drivers/mtd/afs.c @@ -68,6 +68,26 @@ static u32 word_sum(void *words, int num) return sum; } +static bool afs_is_v1(struct mtd_info *mtd, u_int off) +{ + /* The magic is 12 bytes from the end of the erase block */ + u_int ptr = off + mtd->erasesize - 12; + u32 magic; + size_t sz; + int ret; + + ret = mtd_read(mtd, ptr, 4, &sz, (u_char *)&magic); + if (ret < 0) { + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", + ptr, ret); + return false; + } + if (ret >= 0 && sz != 4) + return false; + + return (magic == AFSV1_FOOTER_MAGIC); +} + static int afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, u_int off, u_int mask) @@ -176,18 +196,9 @@ static int parse_afs_partitions(struct mtd_info *mtd, */ mask = mtd->size - 1; - /* - * First, calculate the size of the array we need for the - * partition information. We include in this the size of - * the strings. - */ + /* Count the partitions by looping over all erase blocks */ for (i = off = sz = 0; off < mtd->size; off += mtd->erasesize) { - u_int iis_ptr, img_ptr; - - ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); - if (ret < 0) - return ret; - if (ret) { + if (afs_is_v1(mtd, off)) { sz += sizeof(struct mtd_partition); i += 1; }