]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
soc: qcom: smem: byte swap values properly
authorAlex Elder <elder@linaro.org>
Tue, 10 Apr 2018 22:25:39 +0000 (17:25 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 3 Aug 2018 05:47:44 +0000 (07:47 +0200)
[ Upstream commit 04a512fea333369cc0b550f3b90df0d638e34d00 ]

Two places report an error when a partition header is found to
not contain the right canary value.  The error messages do not
properly byte swap the host ids.  Fix this, and adjust the format
specificier to match the 16-bit unsigned data type.

Move the error handling for a bad canary value to the end of
qcom_smem_alloc_private().  This avoids some long lines, and
reduces the distraction of handling this unexpected problem.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Andy Gross <andy.gross@linaro.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/soc/qcom/smem.c

index c4bcc1e397ccc0b5f6636387ee13d95116880673..493865977e3dabc68017c4ce38a2b32762f2efb0 100644 (file)
@@ -362,13 +362,8 @@ static int qcom_smem_alloc_private(struct qcom_smem *smem,
        cached = phdr_to_last_cached_entry(phdr);
 
        while (hdr < end) {
-               if (hdr->canary != SMEM_PRIVATE_CANARY) {
-                       dev_err(smem->dev,
-                               "Found invalid canary in hosts %d:%d partition\n",
-                               phdr->host0, phdr->host1);
-                       return -EINVAL;
-               }
-
+               if (hdr->canary != SMEM_PRIVATE_CANARY)
+                       goto bad_canary;
                if (le16_to_cpu(hdr->item) == item)
                        return -EEXIST;
 
@@ -397,6 +392,11 @@ static int qcom_smem_alloc_private(struct qcom_smem *smem,
        le32_add_cpu(&phdr->offset_free_uncached, alloc_size);
 
        return 0;
+bad_canary:
+       dev_err(smem->dev, "Found invalid canary in hosts %hu:%hu partition\n",
+               le16_to_cpu(phdr->host0), le16_to_cpu(phdr->host1));
+
+       return -EINVAL;
 }
 
 static int qcom_smem_alloc_global(struct qcom_smem *smem,
@@ -560,8 +560,8 @@ static void *qcom_smem_get_private(struct qcom_smem *smem,
        return ERR_PTR(-ENOENT);
 
 invalid_canary:
-       dev_err(smem->dev, "Found invalid canary in hosts %d:%d partition\n",
-                       phdr->host0, phdr->host1);
+       dev_err(smem->dev, "Found invalid canary in hosts %hu:%hu partition\n",
+                       le16_to_cpu(phdr->host0), le16_to_cpu(phdr->host1));
 
        return ERR_PTR(-EINVAL);
 }