aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Elder <elder@linaro.org>2018-06-25 20:58:51 -0400
committerAndy Gross <andy.gross@linaro.org>2018-09-13 17:57:01 -0400
commitada79289735fea37e755bbefc4403c989e66f4b1 (patch)
treedb1c4594b9a4f782d84a51eefa9ff2d2649fa761
parentabc006b7a6eaf598c3987e5ae87deb7cd8221145 (diff)
soc: qcom: smem: introduce qcom_smem_partition_header()
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 <elder@linaro.org> Signed-off-by: Andy Gross <andy.gross@linaro.org>
-rw-r--r--drivers/soc/qcom/smem.c45
1 files changed, 31 insertions, 14 deletions
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index 91f814900ca1..eb530a6770c1 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -723,6 +723,29 @@ static u32 qcom_smem_get_item_count(struct qcom_smem *smem)
723 return le16_to_cpu(info->num_items); 723 return le16_to_cpu(info->num_items);
724} 724}
725 725
726/*
727 * Validate the partition header for a partition whose partition
728 * table entry is supplied. Returns a pointer to its header if
729 * valid, or a null pointer otherwise.
730 */
731static struct smem_partition_header *
732qcom_smem_partition_header(struct qcom_smem *smem,
733 struct smem_ptable_entry *entry)
734{
735 struct smem_partition_header *header;
736
737 header = smem->regions[0].virt_base + le32_to_cpu(entry->offset);
738
739 if (memcmp(header->magic, SMEM_PART_MAGIC, sizeof(header->magic))) {
740 dev_err(smem->dev, "bad partition magic %02x %02x %02x %02x\n",
741 header->magic[0], header->magic[1],
742 header->magic[2], header->magic[3]);
743 return NULL;
744 }
745
746 return header;
747}
748
726static int qcom_smem_set_global_partition(struct qcom_smem *smem) 749static int qcom_smem_set_global_partition(struct qcom_smem *smem)
727{ 750{
728 struct smem_partition_header *header; 751 struct smem_partition_header *header;
@@ -761,15 +784,13 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem)
761 return -EINVAL; 784 return -EINVAL;
762 } 785 }
763 786
764 header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); 787 header = qcom_smem_partition_header(smem, entry);
788 if (!header)
789 return -EINVAL;
790
765 host0 = le16_to_cpu(header->host0); 791 host0 = le16_to_cpu(header->host0);
766 host1 = le16_to_cpu(header->host1); 792 host1 = le16_to_cpu(header->host1);
767 793
768 if (memcmp(header->magic, SMEM_PART_MAGIC, sizeof(header->magic))) {
769 dev_err(smem->dev, "Global partition has invalid magic\n");
770 return -EINVAL;
771 }
772
773 if (host0 != SMEM_GLOBAL_HOST || host1 != SMEM_GLOBAL_HOST) { 794 if (host0 != SMEM_GLOBAL_HOST || host1 != SMEM_GLOBAL_HOST) {
774 dev_err(smem->dev, "Global partition hosts are invalid\n"); 795 dev_err(smem->dev, "Global partition hosts are invalid\n");
775 return -EINVAL; 796 return -EINVAL;
@@ -837,17 +858,13 @@ static int qcom_smem_enumerate_partitions(struct qcom_smem *smem,
837 return -EINVAL; 858 return -EINVAL;
838 } 859 }
839 860
840 header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); 861 header = qcom_smem_partition_header(smem, entry);
862 if (!header)
863 return -EINVAL;
864
841 host0 = le16_to_cpu(header->host0); 865 host0 = le16_to_cpu(header->host0);
842 host1 = le16_to_cpu(header->host1); 866 host1 = le16_to_cpu(header->host1);
843 867
844 if (memcmp(header->magic, SMEM_PART_MAGIC,
845 sizeof(header->magic))) {
846 dev_err(smem->dev,
847 "Partition %d has invalid magic\n", i);
848 return -EINVAL;
849 }
850
851 if (host0 != host0 || host1 != host1) { 868 if (host0 != host0 || host1 != host1) {
852 dev_err(smem->dev, 869 dev_err(smem->dev,
853 "Partition %d hosts don't match\n", i); 870 "Partition %d hosts don't match\n", i);