From patchwork Thu Oct 15 13:08:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 55012 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id 71C6A2301F for ; Thu, 15 Oct 2015 13:13:02 +0000 (UTC) Received: by lbbyh1 with SMTP id yh1sf4341147lbb.0 for ; Thu, 15 Oct 2015 06:13:01 -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=t8F/ei8Yru8rpy45heZ/DlVrs6oU/TCNUll3++3z1Eo=; b=QUsUMgPLkxXGL/x9ySYuo0RM8qz25HhwN89v5Fve2+xbHUf6gFvrQXLo0LePnfj36l XfzOGYgOb6MYxZwpmrbU/uPuTboOihUL1mVWfU6lQm9L5W9ceYvUgGg8zFeTi4oOpP9z 5lf1Pih5N9IcKq9r48UokUuV9UlPvD8UVc2XQvALcJGdgFH/7EPtph1KlNcCeLW3aXVV 5FXyiZ/uHG4SiUPKCFvzvJIROfOV/E/RYNERT9OrYaC2Rh3WdxKZPtpIOYIqFTsOdn7d 6fh+C4AFDzOnRfeJu1OR05d4t+BGpyWCjWSQkkqtzuT3ckqhYYdkDpMAHI2XlfSxsf9M 40xw== X-Gm-Message-State: ALoCoQmQ0NfVN8H2JohngffboCaMTkUdEwnxNDnZJibZjqFT2O7D1RF4x3AxUIle05MGxcx7AxaU X-Received: by 10.194.83.169 with SMTP id r9mr2145809wjy.6.1444914781373; Thu, 15 Oct 2015 06:13:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.149.7 with SMTP id x7ls161601lfd.51.gmail; Thu, 15 Oct 2015 06:13:01 -0700 (PDT) X-Received: by 10.112.161.168 with SMTP id xt8mr3468885lbb.88.1444914781018; Thu, 15 Oct 2015 06:13:01 -0700 (PDT) Received: from mail-lf0-f45.google.com (mail-lf0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id zv6si9105112lbb.62.2015.10.15.06.13.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:13:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by lfaz124 with SMTP id z124so27307967lfa.1 for ; Thu, 15 Oct 2015 06:13:00 -0700 (PDT) X-Received: by 10.25.150.199 with SMTP id y190mr2990591lfd.35.1444914780825; Thu, 15 Oct 2015 06:13:00 -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 w3csp626264lbq; Thu, 15 Oct 2015 06:12:59 -0700 (PDT) X-Received: by 10.68.211.68 with SMTP id na4mr10173777pbc.94.1444914779789; Thu, 15 Oct 2015 06:12:59 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ph4si21581859pbb.177.2015.10.15.06.12.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:12:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-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 1ZmiK2-0000Ku-JJ; Thu, 15 Oct 2015 13:11:54 +0000 Received: from mail-lf0-f52.google.com ([209.85.215.52]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZmiIB-0005PQ-Jx for linux-arm-kernel@lists.infradead.org; Thu, 15 Oct 2015 13:10:03 +0000 Received: by lfeh64 with SMTP id h64so27166663lfe.3 for ; Thu, 15 Oct 2015 06:09:37 -0700 (PDT) X-Received: by 10.25.162.21 with SMTP id l21mr2941114lfe.70.1444914577369; Thu, 15 Oct 2015 06:09:37 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id rf8sm2036081lbb.20.2015.10.15.06.09.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Oct 2015 06:09:36 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , linux-mtd@lists.infradead.org Subject: [PATCH 09/10] mtd: afs: factor the IIS read into partition parser Date: Thu, 15 Oct 2015 15:08:52 +0200 Message-Id: <1444914533-27782-10-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_060959_902921_B1A6E3C9 X-CRM114-Status: GOOD ( 19.95 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.215.52 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.215.52 listed in wl.mailspike.net] -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-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-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.45 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 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/afs.c | 59 +++++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c index cdee8295d4c0..1ce6842c917c 100644 --- a/drivers/mtd/afs.c +++ b/drivers/mtd/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)