From patchwork Mon Jan 28 13:54:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 156742 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3453891jaa; Mon, 28 Jan 2019 05:55:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN6FAAuwY6zWsl9376wa+DXRdr6ATfihBJoLIbWhGAcz+IgYAYuJ76vkg7Mc+dJHOwMA3575 X-Received: by 2002:a62:1b83:: with SMTP id b125mr22805857pfb.42.1548683753698; Mon, 28 Jan 2019 05:55:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548683753; cv=none; d=google.com; s=arc-20160816; b=tkk9LmpVwpNfQcVpfB4knBQJ5C8/jLK7l2RL5xIa9TzdYrfQxip0kgi3XiRCwVyKBx kzYUX77YC8sa1OHtEMvMfgA8BV/IS4prIoptXdex6FB1Qpk0HHegTTIq72opwELDtaoF ZDA53V+grVrG003rXqyVeZpzTkxWzQzTuP9K1dTDE5R/6uLOfRXhEfjFdBGPYJa9x15r nJY0BBAo9NkIHBPRMUFpUTF0xKtp214HC/M7xrqkd6ALM3XnYjHtSa8gZ3moyRzEBm6C V2O6kuZXXR6A9Q6j18TOP9TUda8BNRJ9OBUEHG8ZO/1/iYDv0S1aMGmh6ffzEHPtqXzz QnHg== 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=MKXedS5IYS1lONMMRTD+CVJWxMtCZHZzjMP4zuhr5gQ=; b=CJi7iLlQMvvszmnItZ/DYBBGQhPPgBlE2yiR7UaFg1izZzMo65g7N7lH0OryRjfHRs MiySrrE3+koiGOXp6J0q/HugqswYSi1YpLM1Q182YTf3z1eHz3mW3vzNVzgVxroJg14S 3PxB9ZNAw3XSRrmr4qiVCwb+SYFiIhBKMIjXlLzfLz2iKo1yPqcYTUGGzXvae5MvlsD4 1z8lJ0V8cjnZXi3iJ1JGZJlDZBDlbrwftCoLRf7WqhZYy3aJ88V2JC0Yd7G+QPcB+00X t77xVXkb8ofkAW29F66F2nHbTADgf5ncA2X6pClWeF2zAMph8NtS+hrAIGYCZ5RRJupD qHUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=ME2VQ8RS; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jofZ87qy; 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 bi2si32815979plb.200.2019.01.28.05.55.53 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 05:55:53 -0800 (PST) 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=ME2VQ8RS; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jofZ87qy; 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=MKXedS5IYS1lONMMRTD+CVJWxMtCZHZzjMP4zuhr5gQ=; b=ME2VQ8RSM3pJIf 6SKG7mgxZOXZTv1IpUOSMyViKsZGVbRaQ079V7mGcQ+hfgZjp1IO4a+sey3bDEPLHL+ot6NTczDrH MBpOGsNESqgrMq5hD/6Gm9AhJETJ5KO+41e1GAcDkXq4v2jgvANTdGK+GAnyGiBhJO+PcJNkut5TK B4a6Pn2b6S6bIr646FgCvz6rWmhALuYMiwFcFOiJXjH90EpyHNBaz2izqZlksKV26IQbPBvsjhTth 3y4Jkrd09tVhiKrPVobNj92lFn0afxAdxTUpZhEokeISuV5irXmE6fJ3/LJjxuBmQb2dKxKeCnfoU 4kVSaSNVXacW0sFg5Hxg==; 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 1go7O3-0001I3-Lf; Mon, 28 Jan 2019 13:55:43 +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 1go7Na-0000TA-Dm for linux-mtd@lists.infradead.org; Mon, 28 Jan 2019 13:55:21 +0000 Received: by mail-lj1-x241.google.com with SMTP id n18-v6so14274056lji.7 for ; Mon, 28 Jan 2019 05:55:14 -0800 (PST) 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=OWmZxsQVuMIf2AkP/1PkW+ARHBWjvKhuF5HT3GrzPJc=; b=jofZ87qy0FvOkvCkbIV9gynM1Px1dX3tehlorXzgYUwOsCBJ9waU3OKpZVAlNvIrj+ l9c0Hy9jbYNPbIH3vQ7UgaQZ3uy/HaQM7VRA4P/l+9bV8wG9OAsNy/WUJNWFdzdpy5/i cLJZSM2tR235N9vb+pzOhnEYzWLGNjnAOfSxw= 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=OWmZxsQVuMIf2AkP/1PkW+ARHBWjvKhuF5HT3GrzPJc=; b=j/uHDYlgbTbhJbCDdaOyJp5jZhzxWhdaHVXkI2Al3JN6zykjccnjO2XVyPwecX08RK wralcoeeTO5nRZmvMoJWmcOZ1X0YXLIs7jd8HRekO3gBsbGtFWOMxgR1NDD4jGD98n9j 9TaKmqyTBuWNWX+171kdvqu2bzLwYyG7wmmgSuztvwbrmqLD3hSwD0iGxs3eHLut+zBW 7Od/ciJg4jWKA0QdVgn8tREt1S31iBSaomm4/XndXaEUQb4fex27NbOItEAxEt/NZbmQ GlaxaogxixQewfrMWoFCo9UuTB7SRAmVbW80riq+Gs8pL5v2VOcotjJ1PsNNBoSb1qW6 DsrA== X-Gm-Message-State: AHQUAubPI0rEwrrfaXqp749kGRDRTbcOqk4RCvD2ePnjj9d1AbxGVezp sHVe/S6q93cFZ48T83ByS58FyA== X-Received: by 2002:a2e:8786:: with SMTP id n6-v6mr6574348lji.100.1548683712405; Mon, 28 Jan 2019 05:55:12 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id a2-v6sm3050503lji.13.2019.01.28.05.55.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 05:55:11 -0800 (PST) From: Linus Walleij To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Cyrille Pitchen , linux-mtd@lists.infradead.org Subject: [PATCH 3/6] mtd: factor out v1 partition parsing Date: Mon, 28 Jan 2019 14:54:46 +0100 Message-Id: <20190128135449.15555-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190128135449.15555-1-linus.walleij@linaro.org> References: <20190128135449.15555-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-20190128_055515_006450_6D9B9DB5 X-CRM114-Status: GOOD ( 22.22 ) 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 http://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_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 Message has at least one valid DKIM or DK signature -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 breaks out the parsing of v1 partitions so we can later add a v2 partition parser. Cc: Ryan Harkin Cc: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/parsers/afs.c | 88 ++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 38 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 ccc198818057..32ded91ae66c 100644 --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -181,14 +181,18 @@ afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) return ret; } -static int parse_afs_partitions(struct mtd_info *mtd, - const struct mtd_partition **pparts, - struct mtd_part_parser_data *data) +static int afs_parse_v1_partition(struct mtd_info *mtd, + u_int off, struct mtd_partition *part) { - struct mtd_partition *parts; - u_int mask, off, sz; - int ret = 0; - int i; + struct image_info_v1 iis; + u_int mask; + /* + * Static checks cannot see that we bail out if we have an error + * reading the footer. + */ + u_int uninitialized_var(iis_ptr); + u_int uninitialized_var(img_ptr); + int ret; /* * This is the address mask; we use this to mask off out of @@ -196,6 +200,39 @@ static int parse_afs_partitions(struct mtd_info *mtd, */ mask = mtd->size - 1; + ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); + if (ret < 0) + return ret; + + /* Read the image info block */ + ret = afs_read_iis_v1(mtd, &iis, iis_ptr); + if (ret < 0) + return ret; + + part->name = kstrdup(iis.name, GFP_KERNEL); + if (!part->name) + return -ENOMEM; + + part->size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1); + part->offset = img_ptr; + part->mask_flags = 0; + + printk(" mtd: at 0x%08x, %5lluKiB, %8u, %s\n", + img_ptr, part->size / 1024, + iis.imageNumber, part->name); + + return 0; +} + +static int parse_afs_partitions(struct mtd_info *mtd, + const struct mtd_partition **pparts, + struct mtd_part_parser_data *data) +{ + struct mtd_partition *parts; + u_int off, sz; + int ret = 0; + int i; + /* Count the partitions by looping over all erase blocks */ for (i = off = sz = 0; off < mtd->size; off += mtd->erasesize) { if (afs_is_v1(mtd, off)) { @@ -215,38 +252,13 @@ static int parse_afs_partitions(struct mtd_info *mtd, * Identify the partitions */ for (i = off = 0; off < mtd->size; off += mtd->erasesize) { - struct image_info_v1 iis; - u_int iis_ptr, img_ptr; - - /* Read the footer. */ - ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); - if (ret < 0) - goto out_free_parts; - if (ret == 0) - continue; - - /* Read the image info block */ - ret = afs_read_iis_v1(mtd, &iis, iis_ptr); - if (ret < 0) - goto out_free_parts; - if (ret == 0) - continue; - - parts[i].name = kstrdup(iis.name, GFP_KERNEL); - if (!parts[i].name) { - ret = -ENOMEM; - goto out_free_parts; - } - parts[i].size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1); - parts[i].offset = img_ptr; - parts[i].mask_flags = 0; - - printk(" mtd%d: at 0x%08x, %5lluKiB, %8u, %s\n", - i, img_ptr, parts[i].size / 1024, - iis.imageNumber, parts[i].name); - - i += 1; + if (afs_is_v1(mtd, off)) { + ret = afs_parse_v1_partition(mtd, off, &parts[i]); + if (ret) + goto out_free_parts; + i++; + } } *pparts = parts;