From patchwork Wed May 2 01:10:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 134808 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp124777lji; Tue, 1 May 2018 18:12:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoK615oLtYovYqUmwH+4wRYS5OHFXY7hGMd4gGxWOv+m75mWBmZOmg1fDoh7VqoKC6gdKZR X-Received: by 10.98.5.129 with SMTP id 123mr4571230pff.38.1525223522327; Tue, 01 May 2018 18:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525223522; cv=none; d=google.com; s=arc-20160816; b=1LgbreD/hEEaAwS3RoaLjMhfDWWV5q2/Oyg5EsfzqrK6+JBHKjg+gduTu/QbXHbqF3 74QM0/jB6aiaBPIEbKXnSKJQEVR2IxljbnJ0k9kNVgRehxlVuoCGRqWM091FITM6Qjif 9VpRAcgjrRI3gzQKPjvF5Kk45BbhgTbylAcBaiiU4xNtoN31kHjgRlgZYzLJWPpdU6mM O0xh/ME66GvF2PKF6Bjody55fJxufphK+M2fmRcNxTAF2qtF2goaY/5wq7V1VuX52pb3 ahEiO3JQQ4ugwI/UJX2PwlFAid+1Tn5XF2rN+GJ5VwKb6ZmDbHnfg8aZddCfpR8DgCiE k8Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=uyakRVK7vDwBd8ZUkx+oD5IGmu2GNBCkxcCABF4tKFQ=; b=cL5xf/XpGC82Y/5qI8X6aMtZF9Nu9YbtjeL73G0DbXh367WpqUfOAFK0pWakrFd9Ol F12npULJrdlseszpniYpe1qbHcxZWWD2EHPPjVmvzQQIIW6fZlCXXHa2ZRK6eaJPOQKM Rdls9GWZcRtb3dnn9pNVWNQY/uzgA1Az3AqYKstxhmMLo9rZqSMtdqqey1I89FLw3Xva AmfBaG3riXLbOxK1jtlyznKwlVpohj6R1Ref88jcXvarYzhMbhWh+BGR+1lNUQOENV3q KYt37PP5LMUCqhnqciYRoQRrRtKzrZ9z/kJQ5KW0t3H7OJQlAZMtFWcs0cwVIS+i/+lw nZvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fTH6T3RP; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z9-v6si4495461plk.94.2018.05.01.18.12.02; Tue, 01 May 2018 18:12:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fTH6T3RP; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751505AbeEBBL6 (ORCPT + 12 others); Tue, 1 May 2018 21:11:58 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:35487 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751241AbeEBBKf (ORCPT ); Tue, 1 May 2018 21:10:35 -0400 Received: by mail-io0-f193.google.com with SMTP id g1-v6so6230995iob.2 for ; Tue, 01 May 2018 18:10:35 -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; bh=LbahlbqXD+qJbEDg3ue3is5H4Ih6/uAkLwNI1Dv8cl4=; b=fTH6T3RPLR+TjZL+EdoO42NXQBr0OpNpY4lAMoYSVsSk89Z/9FtP4KyMQxUrPPHHP+ Sb7/kFBTy68dJfZYN/BLhhErAj8pknJ5S8nLjYk0HGRO4CuEz9+FU7Gt6cK9zK2s9ETg XGtheaaocQIBnRDkWx/kDqZvnwethUtBBIzh4= 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; bh=LbahlbqXD+qJbEDg3ue3is5H4Ih6/uAkLwNI1Dv8cl4=; b=lP5z/hwZ3R/XVb6JiE2EP2jYNebYJOAD0KljlNChtKUeQHjUHZAD0RvTHTFLhPVBcX yQ4haqhCMjqjBZEqKYAYuf9vXa6rMYydwntBLBxVJct2u61nDt+REHtjlJc4htq8oPgn sQX+HtIWTyYAVTfN4bMb8rAAtebemJGghDNUcESu2y8gORrD48vLazy4QUSAGN06Ofe2 PwVbvxyYftfV99XVsRrhLkP1K2mMdLALtKz7IUPHwkPhddOK1hvy13c+1IxPFxc2UoWF Zx+m2s9KJAlmdx05A0mejD3owY1IRA2cq6mZAZn+d7/4tm0ECuogK8Sv3TnvY6BNqqWb EE4Q== X-Gm-Message-State: ALQs6tD/HL7QFqS6YWNTeBSNSwxctKK+As7mLrWmMW/Fe1swcArj5Yze 0tf3K8daPwjA3D94DoHJTdl6CA== X-Received: by 2002:a6b:8b58:: with SMTP id n85-v6mr18172296iod.109.1525223434584; Tue, 01 May 2018 18:10:34 -0700 (PDT) Received: from presto.localdomain (c-71-195-29-92.hsd1.mn.comcast.net. [71.195.29.92]) by smtp.gmail.com with ESMTPSA id g200-v6sm2082479itb.26.2018.05.01.18.10.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 18:10:34 -0700 (PDT) From: Alex Elder To: andy.gross@linaro.org Cc: clew@codeaurora.org, aneela@codeaurora.org, david.brown@linaro.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/12] soc: qcom: smem: introduce qcom_smem_partition_header() Date: Tue, 1 May 2018 20:10:14 -0500 Message-Id: <20180502011019.22812-8-elder@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180502011019.22812-1-elder@linaro.org> References: <20180502011019.22812-1-elder@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Create a new function qcom_smem_partition_header() to encapsulate validating the header information found in a partition. This will be built up over a few commits to make it more obvious how the common function is replacing duplicated code elsewhere. Initially it just verifies the header has the right magic number. Signed-off-by: Alex Elder --- drivers/soc/qcom/smem.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) -- 2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 9e20c6b1b4c2..d52a282f7338 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -727,6 +727,29 @@ static u32 qcom_smem_get_item_count(struct qcom_smem *smem) return le16_to_cpu(info->num_items); } +/* + * Validate the partition header for a partition whose partition + * table entry is supplied. Returns a pointer to its header if + * valid, or a null pointer otherwise. + */ +static struct smem_partition_header * +qcom_smem_partition_header(struct qcom_smem *smem, + struct smem_ptable_entry *entry) +{ + struct smem_partition_header *header; + + header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); + + if (memcmp(header->magic, SMEM_PART_MAGIC, sizeof(header->magic))) { + dev_err(smem->dev, "bad partition magic %02x %02x %02x %02x\n", + header->magic[0], header->magic[1], + header->magic[2], header->magic[3]); + return NULL; + } + + return header; +} + static int qcom_smem_set_global_partition(struct qcom_smem *smem) { struct smem_partition_header *header; @@ -760,15 +783,13 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem) return -EINVAL; } - header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); + header = qcom_smem_partition_header(smem, entry); + if (!header) + return -EINVAL; + host0 = le16_to_cpu(header->host0); host1 = le16_to_cpu(header->host1); - if (memcmp(header->magic, SMEM_PART_MAGIC, sizeof(header->magic))) { - dev_err(smem->dev, "Global partition has invalid magic\n"); - return -EINVAL; - } - if (host0 != SMEM_GLOBAL_HOST || host1 != SMEM_GLOBAL_HOST) { dev_err(smem->dev, "Global partition hosts are invalid\n"); return -EINVAL; @@ -836,13 +857,9 @@ static int qcom_smem_enumerate_partitions(struct qcom_smem *smem, return -EINVAL; } - header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); - if (memcmp(header->magic, SMEM_PART_MAGIC, - sizeof(header->magic))) { - dev_err(smem->dev, - "Partition %d has invalid magic\n", i); + header = qcom_smem_partition_header(smem, entry); + if (!header) return -EINVAL; - } if (host0 != le16_to_cpu(header->host0) || host1 != le16_to_cpu(header->host1)) {