From patchwork Thu May 2 14:30:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 163268 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp5810329ill; Thu, 2 May 2019 07:34:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwj5rKzQZlKXsE8EEBBSIA51H+6UgfrKbf2AUXpx/eWKKUiYA+a4G4FCPUmeo1vlPOE13Bd X-Received: by 2002:a63:d408:: with SMTP id a8mr4260395pgh.184.1556807657940; Thu, 02 May 2019 07:34:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556807657; cv=none; d=google.com; s=arc-20160816; b=QMFKox3fd6LMJoGfKz30N8WgfZFGMYzJEUtbRo/N9wBr0C4wNuhQO1WskzyJxvk/dh zYTJKj4D/l1ZbrMWMi+Olir0ri0xUyc+C7s0en+nYCmwClW/DKDLT4v6wMzbAJ09o8f5 uZytZ23pT8bGMybksdQrVuGQ4ILKDTqdGYMzzpLiHDxbW4XsT7Y2VqUhjjcwOb0ZtXva u3582i/N0eUCkv0S8GI8Yv5H2PLGpbYhfs05wk4hNZyc/y3cDTXWXeR/bsJtrzWl0A9W smksuOSJV6YefEUkO6nAXzOwYHF/akuSW1Ozq2uFMTnPp4slnLMAdGH61sXCBrXOw7p9 pA8A== 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=32g4R+o6Kgn45gK8Rj91pX+/5009gOMXzAIc3aIEiY0=; b=R+IKBLDHmJemIZUkLqKQYxkHA4diS4/t+hGl66h0atAG7lUDrK5hmpW171XRaDhJ1w HDSUhFvq2QIzGmChVwfjbI9k5v+eWwDE6J0Hh07G/RnMluiGn5AP6YDE1TD0LP7Ig1ze +B1+QvEPOqe0l411gSW+bYjD55LJgL2aj+6HI93b163tsctJqxN4iDOzBPao5MBRxh5m /Fgdb5sY61osadKp07v0qSM3WrJ6NkjDnMg7I5oRV1aPmnIoNS2SF4xJO8HvKBre1Ij3 /dSdJSflGTrJmFcZhwuhiAmucva8LlHo7G+PAK5fNxBt7/7CFn0EkYcGsYLNKW/uLbPy SGtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Ye5KOw38; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ifnaU5YL; 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 q22si23294589pll.184.2019.05.02.07.34.17 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:34:17 -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=Ye5KOw38; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ifnaU5YL; 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=32g4R+o6Kgn45gK8Rj91pX+/5009gOMXzAIc3aIEiY0=; b=Ye5KOw38t34uAG z9GpcL0AePkVDPxaW0ux0lqjZSZndtXv+J3aLmiiW0eGkH42KaTCMyr+kmzirzozuoPOkhlIcp8pS oyxNCO3L9xPRCKyqXW0ricvFK2WwwueRvpAqFgV2SR2qi0H/QVtYbFi1r+Ox1P5ugfxBeduQ9hIkN j2DBwjuTEOBcTklnkVeh5VWfGYeyIFPKI9AUUhnH98iBtnuiccFxvBUwGuyFykS1wa1DLgHsADHmB 8mjJVLOj3gK/euUGIUUqQCNIOx962w/Xc1gXkjqYCxpsJu4Y0V8faxZFZH6vOytwkjJVA28FNbYXh SnYl5pYoRD2WjfDJevjQ==; 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 1hMCml-0002Df-A4; Thu, 02 May 2019 14:34:07 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCm1-0001DK-6P for linux-mtd@lists.infradead.org; Thu, 02 May 2019 14:33:34 +0000 Received: by mail-lf1-x142.google.com with SMTP id j20so2068658lfh.2 for ; Thu, 02 May 2019 07:33:20 -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=o4x2AwA/3CLBONjG7dpZpyuRhgYfsOiX68AZc6HGuSQ=; b=ifnaU5YL8TOetW2sEUOBvTwzLn3XYh8p46Mu3ByasHC79TnX5LkzcJYj0lrt9GAufY u3HCJDusK4e2Mm6O5/KFbjUpiZtSwULT/OwQzhnrFrNNFmJYxKv0jh2wcLM2Jj8Eb76J 5nRi4zC5PpvdlrxnYgzlUfW5/aCX69IHiFKB4cY9GO12gUf8bkIVJOB8k5OqXiIzLh0p KLwylVzcK0o8k3ivYK9hIjlOyPSCI45Z97H4MMNMhHJFLjCB52zPoOgw6XlMZiYkor9j yEvN7v0P6Mau3Nqqxc33Kb1yMX4I054+mbWG13NGfOlvgwFrQVD5ZlGXxxdm3IGiKUSR bQAA== 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=o4x2AwA/3CLBONjG7dpZpyuRhgYfsOiX68AZc6HGuSQ=; b=P3PmQtmt5UKkElBllVLTsBW+PsVIjHERUt6aFNuxwXhu1TN1lmCDPRIk09Yzre4nyW HC4HFfbLwdPhyCQkXnztsUW80GtFajv8bQrT07EBeaqVFqDAPaWwyBo0EjpgQ5PPGe9A 3PmNt+uFyiFaTa5qqLb5z+i6WzPHSvB2POYNDbx9TGUnCS3zu+yPTwTBF9JiH0F0lESk 9sD3CR9eGJUXaPQmHBogH7T5GS6COO8hVix08G//JhAuWQMzYVpfZKtIegCqE0tPMTyf q9DACVSejmKPSjs+yrE05y6vU3hI06qo2swTyFcPNi05Hj1cWl6dNjvAYEw2H4dMmJwR wZyA== X-Gm-Message-State: APjAAAVqq+YZggI5PB40vliknfVS/ulYFzxqYwnjOPEcwuXYqlWj8cgk WFLbLIsNYPP04mFFVgq0u/w5lw== X-Received: by 2002:a19:189:: with SMTP id 131mr650254lfb.74.1556807599102; Thu, 02 May 2019 07:33:19 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:17 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Miquel Raynal , linux-mtd@lists.infradead.org Subject: [PATCH 8/9 RESEND 2] mtd: afs: factor the IIS read into partition parser Date: Thu, 2 May 2019 16:30:33 +0200 Message-Id: <20190502143034.16781-9-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_073321_863816_86E26DE8 X-CRM114-Status: GOOD ( 17.87 ) 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:142 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 Factor the IIS (Image Information Structure) reading into the partition parser, giving us a single, clean partition parser function. Cc: Ryan Harkin Acked-by: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/parsers/afs.c | 59 +++++++++++++-------------------------- 1 file changed, 20 insertions(+), 39 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 8ff82a548252..72c688b8a383 100644 --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -88,42 +88,6 @@ static bool afs_is_v1(struct mtd_info *mtd, u_int off) return (magic == AFSV1_FOOTER_MAGIC); } -static int -afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) -{ - size_t sz; - int ret, i; - - memset(iis, 0, sizeof(*iis)); - ret = mtd_read(mtd, ptr, sizeof(*iis), &sz, (u_char *)iis); - if (ret < 0) - goto failed; - - if (sz != sizeof(*iis)) { - ret = -EINVAL; - goto failed; - } - - ret = 0; - - /* - * Validate the name - it must be NUL terminated. - */ - for (i = 0; i < sizeof(iis->name); i++) - if (iis->name[i] == '\0') - break; - - if (i < sizeof(iis->name)) - ret = 1; - - return ret; - - failed: - printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", - ptr, ret); - return ret; -} - static int afs_parse_v1_partition(struct mtd_info *mtd, u_int off, struct mtd_partition *part) { @@ -139,6 +103,7 @@ static int afs_parse_v1_partition(struct mtd_info *mtd, u_int ptr; size_t sz; int ret; + int i; /* * This is the address mask; we use this to mask off out of @@ -185,9 +150,25 @@ static int afs_parse_v1_partition(struct mtd_info *mtd, return 0; /* Read the image info block */ - ret = afs_read_iis_v1(mtd, &iis, iis_ptr); - if (ret < 0) - return ret; + memset(&iis, 0, sizeof(iis)); + ret = mtd_read(mtd, iis_ptr, sizeof(iis), &sz, (u_char *)&iis); + if (ret < 0) { + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", + iis_ptr, ret); + return -EINVAL; + } + + if (sz != sizeof(iis)) + return -EINVAL; + + /* + * Validate the name - it must be NUL terminated. + */ + for (i = 0; i < sizeof(iis.name); i++) + if (iis.name[i] == '\0') + break; + if (i > sizeof(iis.name)) + return -EINVAL; part->name = kstrdup(iis.name, GFP_KERNEL); if (!part->name)