From patchwork Tue Jun 26 00:58:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 139902 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4616758lji; Mon, 25 Jun 2018 18:00:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJNsnYk0kNcFtkPYvVwnOZT420bTFV6Aj84al4K9GnU7jSaCM7NKfhB7Mr8QDC8SppzBW0M X-Received: by 2002:a65:5307:: with SMTP id m7-v6mr7495934pgq.431.1529974837222; Mon, 25 Jun 2018 18:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529974837; cv=none; d=google.com; s=arc-20160816; b=HHPjFkAMD7emSW178XtPfBbI32AUL7nXKK0pEVPmuv0Sn1zlkskm7kEzd8IcgiFzGU jj3r31Y7rYtjNG5p5J2wWy82Ce1YlvUixGsstNMGW1x9vAuzYCV6+Hqz7cm5+zodACH4 nFPDK35S9I66pXP9zxv5RTwMmV0tzUbcV3zoMNIglvqY+2jWvY7Q0pnNg1jwdqV7txNZ S0tzkwkgv4A2PypfOX4i7s2O7+0cIzosEON313/sOjXRP/RU4Qdy8gDEFvs0+vk1cvVf MHNdNOd9aF+KC5FyKS4SCsSP+cJ+c4u5YnpOxsU3NCBChwDCurdxr5DSqI8qCsxMYxDX zGeg== 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=GyZkGlYZ1xYhCPBJ841az1JrzD/G85xn84STm/is5jU=; b=VNxCdo0bWvD5zUuV115itiTtAz9WMw206sXDcPexGUe01n3TEH38V6TKohVLmx7Pvm wtukXAurfi3s+94nb9U1eE0qz+tQN5adGZvmtQw8z4rm74Ob6yWrm8g8GoFNd4o4DpOT YhHLA4A7T0tl1/lAqi6ySaHUsMK0BllnYWIsOQQelgTzejmkGtvwEO1zEG/UKG4I+aUW evwzWN0Qy2sS03bIDs2Ek48xp/bnElZwxYFTso7URaK7EZXn/TakUqffYA3aDVJZpR9U xStQFUbGp8P2faG3zmn0JkEEEaxtbfQHCfX+MjVxV6M+JR/reJvyZ+CxGySztz5G8Of/ ylew== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UAX6MZpp; 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 g17-v6si310563plo.355.2018.06.25.18.00.37; Mon, 25 Jun 2018 18:00:37 -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=UAX6MZpp; 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 S934552AbeFZBAe (ORCPT + 13 others); Mon, 25 Jun 2018 21:00:34 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:55224 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755790AbeFZA7J (ORCPT ); Mon, 25 Jun 2018 20:59:09 -0400 Received: by mail-it0-f68.google.com with SMTP id 76-v6so15175072itx.4 for ; Mon, 25 Jun 2018 17:59:09 -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=ykWRwse3ZZFWvvwZIi1NRP2Kheq0JMqj14q6nMHsCMc=; b=UAX6MZppTydTMGxWWX8cy7zgQBwTSL8npUO3M79SWxNhgDT22eCvkE9/rj7Vat4+7V iixRVz7ODWBGE6ZiHPWbpK5YoVFDt3/BsNHJS5eqr3cupKFlRPF0xO/KLZeQNgcoswKc +FziDtZcCdhoTHBiEnqleNtI9t7ll3jutcfSI= 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=ykWRwse3ZZFWvvwZIi1NRP2Kheq0JMqj14q6nMHsCMc=; b=IvqsuU+Wk/sGXuw04qJ3wAeR70cc4WgnRKGiOphCRFO5LtbiHzni37E8yUwD6OuTnJ s/QraN0ksBcUjAscs+2ivnBNmb136iziG5eNiNVbV9TMFbkQ1UDGIZL+mttxva4EAlrb OzCdxZhCBlHsZUhZ+t1d80FEqPKDpHD0720eaYyP3SPHeGNo2aCXe39qBPwI9YuKSYhP JEtRmtW5nsBZtq9NEYM95EK06SiiepIqAo76HNsGZ2cLJ5s51ZB7eaKDlxE7ERKGpqFA UEvIEGczih8Q6yRONNtimTL6qPYeqPdUH7KpvqvnkpYaSkFOKY09+TjsIhlJ/I6l6G/4 tX9Q== X-Gm-Message-State: APt69E3IZcRFBe4HsuYdt9sc5oCr0/rydQYKeYcESnJlrd8nu3H8eflA AzQz/OwEVS1kBCUOh+JaKp5Uyg== X-Received: by 2002:a24:6e95:: with SMTP id w143-v6mr2726834itc.108.1529974748034; Mon, 25 Jun 2018 17:59:08 -0700 (PDT) Received: from localhost.localdomain (c-71-195-29-92.hsd1.mn.comcast.net. [71.195.29.92]) by smtp.gmail.com with ESMTPSA id f193-v6sm372556itf.9.2018.06.25.17.59.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jun 2018 17:59:07 -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 resend 07/12] soc: qcom: smem: introduce qcom_smem_partition_header() Date: Mon, 25 Jun 2018 19:58:51 -0500 Message-Id: <20180626005856.14174-8-elder@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180626005856.14174-1-elder@linaro.org> References: <20180626005856.14174-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 locating a partition header and validating information found within it. 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 | 45 ++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 14 deletions(-) -- 2.17.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 49f228e9d2d3..516a17d340af 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,17 +857,13 @@ static int qcom_smem_enumerate_partitions(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, - "Partition %d has invalid magic\n", i); - return -EINVAL; - } - if (host0 != host0 || host1 != host1) { dev_err(smem->dev, "Partition %d hosts don't match\n", i);