From patchwork Thu May 2 14:30:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 163269 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp5810422ill; Thu, 2 May 2019 07:34:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqy36k/kMmQV/uz9335LSdaGzXRsSRGMPh+iGGe4QiNgdHGzFRjkiiYC7TaOOGhP5SvBifGw X-Received: by 2002:a17:902:294b:: with SMTP id g69mr4105737plb.57.1556807661193; Thu, 02 May 2019 07:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556807661; cv=none; d=google.com; s=arc-20160816; b=Bjp6hxt6ynAzlW61+w7yIsPksXh9/nT4vXVy4tKTFsoGyTJR/SWNN7X3F0STLebhbo SH4/e0ozBNa0fWs2Tx6Gxg7dcSV8iVvAlj8lkJgyQPRMmu8fNKIryy15gFokf/JPHbRe ck1CMHx/wv2yQ2ORvNZgDW4sa7xlSFy7V64wI55h+AYd0J05vIlvsvKifVSwxQ9FrsSS ZSGdO0cYoxVhJWuHxqT8yFdIIlRxB0tRLtscg1M5mlbDXW/A23iOcuHhnbytrI4oQcFz +lnsnynLLBbS5VsCDbfaMgeogDGHAW5NrdXYhxbZGhGytxcgezJttyLbAnm5e5QljApj veww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:dkim-signature; bh=YFpsCRb+VDkKHNFadVWETTUK20jCdxzZrg5Dp2XYUic=; b=vJIMsSu/+0YethuTNe27XEyDctJN1Ii+HPZhCkPgApQiGbWkex+S/oXuLgqD3wNQT0 HJFZC/XLql0Klk2MgHSfWCnTeaAoIvymjCfsZZtAIgOwLI0MNCLiE0dK5zrAW5GNXRaP PqMh+qiAFBN/fGIXkt2lbfbYn20HRW243u6U6T2cuzjNiQ0/+muYV0VeGGWwHNOkogIM HOEZm8rcXI7+OOnNZanyqeQ2XRgszONESgdX7XBPhS5gVKENGWrESOyYffdEcmdK0Er4 cZE5lnGaWuNrCdtf36AG8RkMfpL69BEbhkHFSB2zpYbJwfaVVUOsiaMJ53sZUaFu0pcc jr+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Q1jtGjlW; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D7mY8KNN; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id 30si31821898plc.8.2019.05.02.07.34.21 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:34:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Q1jtGjlW; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D7mY8KNN; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YFpsCRb+VDkKHNFadVWETTUK20jCdxzZrg5Dp2XYUic=; b=Q1jtGjlWpsRl0p vZr9JEYbXg+rDqQ5atFNUVbJL0rzETs0BrlVkQFgTDwDA9VYR78zvWwdJQGLOC6ww3ug5rQTZ9Hd4 CtwIi0J8+Dl1z+MmUaNdiShojWltfMcCEWADOcl4qpZSzqIYmVemcVK/m9Bnx9vjyDHiaRqj/3CqK 2a26QK72PePF2FcDuCCf7G0Of5FHqD8b8Iysm7V83hQ6wo/ekDbcNPuIShdGhKURXGT0EeHf2NvFr pTJw25lx96XP/2UMABEIfgwAZlE6GyxGeWbzIxffZz3tJ6B1aDurfAmNkKWBnPHQGIhm/6AAPt9tJ wjTmxVVftzGvAqgSIjiw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCmu-0002R1-M5; Thu, 02 May 2019 14:34:16 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCly-00019J-MO for linux-mtd@lists.infradead.org; Thu, 02 May 2019 14:33:34 +0000 Received: by mail-lj1-x241.google.com with SMTP id t1so2369906lje.10 for ; Thu, 02 May 2019 07:33:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rj711N4u+SYqDnZQYL9jQuymU6HES5b6qp0qWAvrKoQ=; b=D7mY8KNNHfwil5hxYax+JTkRllxmZ+8WgLY7qWAfx9AdL1gSo3m4/izbROLE1LSG+A +iBSsTbFaPkZuTZj3AE1I09F7dGYDWeNdb3drV/ev0mLrcgOLgRGpI7g/QObVgVoGOQ4 bIFQ7g2WekCbENIGTP3NiB8r6ntDNN4J1tgf+M+oOC6rTwpYsw7IKpDzR/SeYRYL494M RY98M7k5uCv4WUQDHHSA2lHDp9S6M5em+F5ACvHcbzLxvD+Q8zwYlc1u3YaBpoLpr87o d0rsPVPZj39X/wjPqi/J4eeVAuv05FH6p3jLVQDQXt8BygmBaGDlIJNEGKIzUc8+x78w 0wrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rj711N4u+SYqDnZQYL9jQuymU6HES5b6qp0qWAvrKoQ=; b=ft8wewyfn+3c+0ngl+qhKbz8Ufy/d8lZU/yeyPoaaLx8gh4Fm4jmQglcEu9eLH5N7X uRgmZ3++S0T7Eywq+ysAEOPmB+rSmkUdfbjRKE44YR1od6cRikmIJc45UoCSr8ZamgmH R+rrWZlX+vyoXibNcDuDFdH6AcQJg6p5u5x5oH+wWjI3joj1LMjWhgmfEWMTs9YlpHz9 tF49E2e9KP96+ltd9fKnJ7IODz73ldUSEUbcZuc0LL6a5GitSLaBwJsRRezDVxg87k4q xGXQVIQJ4dX422BP8Uped5ahH1MCoPVaCYr4MPwfcV7dr4JfBEhUC95Og6dsBwVUD5T1 0Wlw== X-Gm-Message-State: APjAAAV0UeIvEQtFuLlaK+LRhwSXiuWWXdIEjo4plZ/3UETxr8Q3Axn4 LguAX/HjFXiM5O21GMW66+7JDw== X-Received: by 2002:a2e:99d5:: with SMTP id l21mr2250903ljj.113.1556807596581; Thu, 02 May 2019 07:33:16 -0700 (PDT) Received: from localhost.localdomain (c-d2cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.210]) by smtp.gmail.com with ESMTPSA id l79sm9430625lfe.92.2019.05.02.07.33.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:15 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Miquel Raynal , linux-mtd@lists.infradead.org Subject: [PATCH 7/9 RESEND 2] mtd: afs: factor footer parsing into the v1 part parsing Date: Thu, 2 May 2019 16:30:32 +0200 Message-Id: <20190502143034.16781-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502143034.16781-1-linus.walleij@linaro.org> References: <20190502143034.16781-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190502_073319_518712_5A353BA0 X-CRM114-Status: GOOD ( 19.41 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:241 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij , Liviu Dudau , Ryan Harkin Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org This simplifies the code by factoring in the image footer parsing into the single function parsing the AFSv1 partitions. Cc: Ryan Harkin Acked-by: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/parsers/afs.c | 98 ++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 59 deletions(-) -- 2.20.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/parsers/afs.c b/drivers/mtd/parsers/afs.c index 32ded91ae66c..8ff82a548252 100644 --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -88,63 +88,6 @@ static bool afs_is_v1(struct mtd_info *mtd, u_int off) 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) -{ - 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) { @@ -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);