From patchwork Thu Oct 15 13:08:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 55007 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 EA0FD2301F for ; Thu, 15 Oct 2015 13:11:21 +0000 (UTC) Received: by lbcao8 with SMTP id ao8sf10045308lbc.1 for ; Thu, 15 Oct 2015 06:11:20 -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=kBHXHnLzxm0tjrUhkSWpI2ky/GihOGdFOD0BXDdnlBc=; b=A3eJA/El2SJ06dtz/fa/mQa3AQ6LKRGDrVhe7gh1nPk8V+v1L50iOMLXte4mWMdXH1 /MWo9RgVHypNQx1htsnKgt9DUqYIXkq3xziOWg1rNH/N0stpFRuUMZTwiLP+BlXQA9+5 Nqn9NeXCio0HO5VkIam2EQm9NCMCFy3fojN5T019x0Qamrb/hOYI1i9COlJKYd/AQGtM CVhg/OTlLzfv49J4jr1FqO66FjUldlgSm87Y2Cu+Ry4iWao8KbWokK773nvETEcfFtfi 9UDUDH8ADc9OVvpgzwrvl1rRZag2Bh6TqMW+f/dfFIFJssRAiUVbzPF3WI4b2O79EAoP P0MA== X-Gm-Message-State: ALoCoQlpW7TX2Uun+QGpHUAdIsg39a9SoZ16e4fScH1oDGFJvPqKB4uCY+zFFNk0SIlHhK4Z/ZCc X-Received: by 10.112.63.165 with SMTP id h5mr2212241lbs.18.1444914680924; Thu, 15 Oct 2015 06:11:20 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.43.135 with SMTP id r129ls173443lfr.93.gmail; Thu, 15 Oct 2015 06:11:20 -0700 (PDT) X-Received: by 10.112.13.34 with SMTP id e2mr3524684lbc.120.1444914680701; Thu, 15 Oct 2015 06:11:20 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id mj2si9101563lbc.55.2015.10.15.06.11.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:11:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by lbwr8 with SMTP id r8so68329738lbw.2 for ; Thu, 15 Oct 2015 06:11:20 -0700 (PDT) X-Received: by 10.112.168.228 with SMTP id zz4mr4534933lbb.73.1444914680509; Thu, 15 Oct 2015 06:11:20 -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 w3csp625208lbq; Thu, 15 Oct 2015 06:11:19 -0700 (PDT) X-Received: by 10.68.219.4 with SMTP id pk4mr10196572pbc.138.1444914679359; Thu, 15 Oct 2015 06:11:19 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id z5si21593759pbt.98.2015.10.15.06.11.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:11:19 -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 1ZmiIN-0006Yy-Fl; Thu, 15 Oct 2015 13:10:11 +0000 Received: from mail-lb0-f175.google.com ([209.85.217.175]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZmiHs-0005MV-7I for linux-arm-kernel@lists.infradead.org; Thu, 15 Oct 2015 13:09:41 +0000 Received: by lbbpp2 with SMTP id pp2so39337953lbb.0 for ; Thu, 15 Oct 2015 06:09:23 -0700 (PDT) X-Received: by 10.112.150.201 with SMTP id uk9mr4532922lbb.102.1444914563165; Thu, 15 Oct 2015 06:09:23 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id rf8sm2036081lbb.20.2015.10.15.06.09.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:09:22 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , linux-mtd@lists.infradead.org Subject: [PATCH 04/10] mtd: afs: refactor v1 partition parsing Date: Thu, 15 Oct 2015 15:08:47 +0200 Message-Id: <1444914533-27782-5-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_060940_501806_A775746B X-CRM114-Status: GOOD ( 18.18 ) 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_H2 RBL: Average reputation (+2) [209.85.217.175 listed in wl.mailspike.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.217.175 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] 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.217.181 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 Return immediately if we are not finding a valid v1 partition in afs_read_footer_v1(), invert scanning logic so we continue to read image information on v1 if we found a footer. This is needed for the logic we introduce to parse v2 footers. Cc: Ryan Harkin Cc: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/afs.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c index d09280ae12bd..a1eea50ce180 100644 --- a/drivers/mtd/afs.c +++ b/drivers/mtd/afs.c @@ -87,25 +87,23 @@ afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, return ret; } - ret = 1; - /* * Does it contain the magic number? */ if (fs.signature != AFSV1_FOOTER_MAGIC) - ret = 0; + return 0; /* * Check the checksum. */ if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) - ret = 0; + return 0; /* * Don't touch the SIB. */ if (fs.type == 2) - ret = 0; + return 0; *iis_start = fs.image_info_base & mask; *img_start = fs.image_start & mask; @@ -115,16 +113,16 @@ afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, * be located after the footer structure. */ if (*iis_start >= ptr) - ret = 0; + return 0; /* * Check the start of this image. The image * data can not be located after this block. */ if (*img_start > off) - ret = 0; + return 0; - return ret; + return 1; } static int @@ -190,18 +188,17 @@ static int parse_afs_partitions(struct mtd_info *mtd, ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); if (ret < 0) break; - if (ret == 0) - continue; - - ret = afs_read_iis_v1(mtd, &iis, iis_ptr); - if (ret < 0) - break; - if (ret == 0) - continue; - - sz += sizeof(struct mtd_partition); - sz += strlen(iis.name) + 1; - idx += 1; + if (ret) { + ret = afs_read_iis_v1(mtd, &iis, iis_ptr); + if (ret < 0) + break; + if (ret == 0) + continue; + + sz += sizeof(struct mtd_partition); + sz += strlen(iis.name) + 1; + idx += 1; + } } if (!sz)