From patchwork Thu Oct 15 13:08:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 55009 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lf0-f70.google.com (mail-lf0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id 3BCBF2301F for ; Thu, 15 Oct 2015 13:11:50 +0000 (UTC) Received: by lfaz124 with SMTP id z124sf2150620lfa.0 for ; Thu, 15 Oct 2015 06:11:49 -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=2mw0JKHE8P1zy5doe6VfKSVgt9ZeSx0zokkpmkvVbOM=; b=bsgts0d2qEmn9L61YziqLGy3SChpOOv0fefODF8k4RLCW3d7IyJUBFvBjW3O1IsBrU Q21r8Mbkg0xhiFGt4USeC4ywAKRTK5GyciyTkabYgkgAkMrK26rgB807QRYiFlILvo0W HtNAlkU5l2+p1Cy+Eea4yfnJVZPoWBxv/d8BmsTg+OJUgtY0vR8oyIVX42t8SMyekRTL bpXxBM6SBZYLB3Aq3UihHcEGL8KamdWcnsHMkE+Xp3Pid/5y31BrBJhbEKWuCEcPHFqR LS7Nq1+m2Tx+PFYqsQK6SgvBeNVcvPe7BsaDy431wnENkZt1KxZwXndJDXjDQ5OYm2s1 g5TA== X-Gm-Message-State: ALoCoQmSkhxiLQiHqdX0VjgDjtY/jq/UGUKnp7AwILWBeJ4JN/UJmKR/tt+Ej2/Rwpn8dSQ8hJeY X-Received: by 10.112.136.99 with SMTP id pz3mr2187537lbb.11.1444914709229; Thu, 15 Oct 2015 06:11:49 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.39.6 with SMTP id n6ls155581lfn.36.gmail; Thu, 15 Oct 2015 06:11:48 -0700 (PDT) X-Received: by 10.25.160.133 with SMTP id j127mr2859468lfe.85.1444914708958; Thu, 15 Oct 2015 06:11:48 -0700 (PDT) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id l85si9103044lfi.89.2015.10.15.06.11.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:11:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lfaz124 with SMTP id z124so27290588lfa.1 for ; Thu, 15 Oct 2015 06:11:48 -0700 (PDT) X-Received: by 10.25.40.130 with SMTP id o124mr2871890lfo.41.1444914708540; Thu, 15 Oct 2015 06:11:48 -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 w3csp625546lbq; Thu, 15 Oct 2015 06:11:47 -0700 (PDT) X-Received: by 10.66.184.203 with SMTP id ew11mr9865039pac.24.1444914707505; Thu, 15 Oct 2015 06:11:47 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id tg7si21563634pbc.190.2015.10.15.06.11.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:11:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-mtd-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 1ZmiJc-0008D8-FF; Thu, 15 Oct 2015 13:11:28 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZmiIA-0005az-Eb for linux-mtd@bombadil.infradead.org; Thu, 15 Oct 2015 13:09:58 +0000 Received: from mail-lf0-f51.google.com ([209.85.215.51]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZmiI7-0006hU-FH for linux-mtd@lists.infradead.org; Thu, 15 Oct 2015 13:09:56 +0000 Received: by lffy185 with SMTP id y185so27266720lff.2 for ; Thu, 15 Oct 2015 06:09:34 -0700 (PDT) X-Received: by 10.25.16.92 with SMTP id f89mr2902636lfi.1.1444914574130; Thu, 15 Oct 2015 06:09:34 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id rf8sm2036081lbb.20.2015.10.15.06.09.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:09:33 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , linux-mtd@lists.infradead.org Subject: [PATCH 08/10] mtd: afs: factor footer parsing into the v1 part parsing Date: Thu, 15 Oct 2015 15:08:51 +0200 Message-Id: <1444914533-27782-9-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_140955_605615_5C5ED597 X-CRM114-Status: GOOD ( 20.45 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on casper.infradead.org summary: Content analysis details: (-2.6 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.215.51 listed in wl.mailspike.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.215.51 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-mtd@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-mtd" Errors-To: linux-mtd-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.53 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 This simplifies the code by factoring in the image footer parsing into the single function parsing the AFSv1 partitions. Cc: Ryan Harkin Cc: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/afs.c | 98 ++++++++++++++++++++++--------------------------------- 1 file changed, 39 insertions(+), 59 deletions(-) diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c index ace27f447abc..cdee8295d4c0 100644 --- a/drivers/mtd/afs.c +++ b/drivers/mtd/afs.c @@ -89,63 +89,6 @@ static bool afs_is_v1(struct mtd_info *mtd, u_int off) } static int -afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, - u_int off, u_int mask) -{ - struct footer_v1 fs; - u_int ptr = off + mtd->erasesize - sizeof(fs); - size_t sz; - int ret; - - ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs); - if (ret >= 0 && sz != sizeof(fs)) - ret = -EINVAL; - - if (ret < 0) { - printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", - ptr, ret); - return ret; - } - - /* - * Does it contain the magic number? - */ - if (fs.signature != AFSV1_FOOTER_MAGIC) - return 0; - - /* - * Check the checksum. - */ - if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) - return 0; - - /* - * Don't touch the SIB. - */ - if (fs.type == 2) - return 0; - - *iis_start = fs.image_info_base & mask; - *img_start = fs.image_start & mask; - - /* - * Check the image info base. This can not - * be located after the footer structure. - */ - if (*iis_start >= ptr) - return 0; - - /* - * Check the start of this image. The image - * data can not be located after this block. - */ - if (*img_start > off) - return 0; - - return 1; -} - -static int afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) { size_t sz; @@ -184,6 +127,7 @@ afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) static int afs_parse_v1_partition(struct mtd_info *mtd, u_int off, struct mtd_partition *part) { + struct footer_v1 fs; struct image_info_v1 iis; u_int mask; /* @@ -192,6 +136,8 @@ static int afs_parse_v1_partition(struct mtd_info *mtd, */ u_int uninitialized_var(iis_ptr); u_int uninitialized_var(img_ptr); + u_int ptr; + size_t sz; int ret; /* @@ -200,9 +146,43 @@ static int afs_parse_v1_partition(struct mtd_info *mtd, */ mask = mtd->size - 1; - ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); - if (ret < 0) + ptr = off + mtd->erasesize - sizeof(fs); + ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs); + if (ret >= 0 && sz != sizeof(fs)) + ret = -EINVAL; + if (ret < 0) { + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", + ptr, ret); return ret; + } + /* + * Check the checksum. + */ + if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) + return -EINVAL; + + /* + * Hide the SIB (System Information Block) + */ + if (fs.type == 2) + return 0; + + iis_ptr = fs.image_info_base & mask; + img_ptr = fs.image_start & mask; + + /* + * Check the image info base. This can not + * be located after the footer structure. + */ + if (iis_ptr >= ptr) + return 0; + + /* + * Check the start of this image. The image + * data can not be located after this block. + */ + if (img_ptr > off) + return 0; /* Read the image info block */ ret = afs_read_iis_v1(mtd, &iis, iis_ptr);