From patchwork Mon Jan 28 13:54:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 156744 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3454284jaa; Mon, 28 Jan 2019 05:56:19 -0800 (PST) X-Google-Smtp-Source: ALg8bN52pW65qMCWi2nadkXjF3IH0xJkvlr8Vbcmk3IGsHuz2atT5gg9PJlOQKB1+eLK63UpT3+X X-Received: by 2002:a62:6f88:: with SMTP id k130mr21880680pfc.234.1548683779812; Mon, 28 Jan 2019 05:56:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548683779; cv=none; d=google.com; s=arc-20160816; b=KXubC1a42NQJ83336WUi2Db/Ur+PFn0Y52WB+DXdiAhQkDbSnoM7sNGshNXP0FjaH1 LGPtN9DutxCz+/VR9+V6XG8WW1FZSbVHjbJj5CgOPNFcDVGUbjSYYEcfqBvFRWmUih7+ SZ4pHoxOZKQuNbRaoK/PZ+4tR9og+nJ8psel4TDyA9tJ4lSm6GS+cl2+Wc+nO3UNKo6F LCIfK/Dg4WlsEipq/hrNvoQuHr+A7EQoTiSqNf+zXLEgGuekcetwb6emE2TVzvY9/Fw2 0g3WhWG22RAzfvlCTlnTwA04c9KNqHZy+4yvS0JFlSgWii07LuC9An5nFObzKMAMtpR3 sCgA== 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=93fWBYsnQGgybrfRnUMaHX7XQkIq7KE1E3vcEzzSrd0=; b=P1Rumv7E1cGwgaCaBAloUo9DKmj7mlS/P8kWthFTfgvad4mFczWtpnLJBe6D8hWwuv JJd5Ga4zFrV4xvW09Iiebh1rbxAv3uF+QwE+DSPjOaPjXte8/LWb326cEA8geLYzo4p2 yJtNFw/DHUdPuqDT1e0++H6K9lllYDCms2H/L36iL81+lJjJB6xmSjhSSWK3i9zbDmXT +9+y6WSvSq3gMRqaHveMGyY6WvoTXeADCF5b8Td1LAeBoNlbz76FrDogS9mY5lGD0RdJ NHxp2+TGxI5mFNnQd3Wpp7IE0okiS3bHOjRgZwhl2XaGEe1Pvay0JDGc7d8TbsT/wGri Lu4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=mDqDX3Md; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=NjnkcihM; 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 g26si31955841pfe.127.2019.01.28.05.56.19 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 05:56:19 -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=mDqDX3Md; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=NjnkcihM; 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=93fWBYsnQGgybrfRnUMaHX7XQkIq7KE1E3vcEzzSrd0=; b=mDqDX3MdFHmi0t qsybhq41M0OBVcxWoWWtpdOPKY/tXCJkMDxYBh1jXZA7fXCzXsWv1CoxTBD84t+MAhzuRywoFf9fI gQXYaGHzNpXPVlrUtloCUnYYeIDO5AGN9qdEJFE3vq0G46t5F4RL7k347Ot1SynQXw5kcNnMG6xgP k5Jjo7/rd1PADGHPTqcIQOh7isbPcC3TdFgCfknsvqU/dLB4SHU5gim0btPNO0BiVoW4OZ1EJG4aa umJlSgp5p2qpfxht0z2Ao0cGf5rt4aT585/lDdGfblkCE9lGSR5JollD/HQZEDpC8qA2E4ijADoUf V0ElLk7qAfgPT6LBcnZw==; 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 1go7OW-0001lN-Ex; Mon, 28 Jan 2019 13:56:12 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1go7Nh-0000sK-AW for linux-mtd@lists.infradead.org; Mon, 28 Jan 2019 13:55:28 +0000 Received: by mail-lj1-x244.google.com with SMTP id s5-v6so14245666ljd.12 for ; Mon, 28 Jan 2019 05:55:21 -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=m9CK2FIaqX5ahLo+vJZ7bZ0fFWNyscRpfdYobu3qH8I=; b=NjnkcihM6WybI/+gOLacqjiy7inKNIfsfldgKk4+pRQVloWJXFVm3eMuS4Vx611Nfp hHVfJSwR3u6d+PQonWLaTo9rW4a5obBL/6coOHz88+xqWIcGSCT7ev4w6eR54tSMfHRi Rl1ZcI7sfWAuR8/q9VhUjmSZBa1aQOECtnl1M= 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=m9CK2FIaqX5ahLo+vJZ7bZ0fFWNyscRpfdYobu3qH8I=; b=Ed3fxsk8BPzronzEI7+qO+Xzsv/T6UnCiPHiQhsditvc0cVN2QEq0mycAyjoUMEx5g g3p54VeqYM0pY2JJ+Xq/enrPUHJZQGK3vaDpPl43v6cSGyoOgNqM4jI8EG7Ptz/W6vst rFg4B85TfdSKNgL9UmSKBIYXGN2fTXBhEcfE3F75yZlyHZPG+sVvziMIAYwFojS8IbDw 9p53CyQGAtoE2xZgHA+vafjdFHU3jlGxYmmKBs+2jSRgP2xqztOdmWsRfriH2wTFYlwz 1a9q7mWnxrorgNRY2vGIiqk7K+5OQ9ceLNwebYWdWtXfFlI6meZIcNCLr7ZNw8JaSt4A XUHg== X-Gm-Message-State: AJcUukdI4JsPYYgojSSOM6VndiGHcnYvGEWR1CXPAg6YpJFpChQ57BQd zYPyuUT0KD9gsqXyztLQs942vg== X-Received: by 2002:a2e:91d1:: with SMTP id u17-v6mr17513569ljg.160.1548683719439; Mon, 28 Jan 2019 05:55:19 -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.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 05:55:18 -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 5/6] mtd: afs: factor the IIS read into partition parser Date: Mon, 28 Jan 2019 14:54:48 +0100 Message-Id: <20190128135449.15555-6-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_055522_299287_98FE6154 X-CRM114-Status: GOOD ( 20.08 ) 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:244 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 Factor the IIS (Image Information Structure) reading into the partition parser, giving us a single, clean partition parser function. Cc: Ryan Harkin Cc: 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)