From patchwork Tue Apr 10 22:25:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 133126 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp90514ljb; Tue, 10 Apr 2018 16:43:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/pPVOiPC3yjydJOTx8hUjhWKKjZVk+5QnqHHBbCM73BrpJxITZHFTKNmnwB+twApxp1KPE X-Received: by 2002:a17:902:900a:: with SMTP id a10-v6mr2575493plp.142.1523403792154; Tue, 10 Apr 2018 16:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523403792; cv=none; d=google.com; s=arc-20160816; b=D1t+Mcd0C/IKME87KpzQb2k409auiz4BUdvzycN+ycpDZGQl0DWVCxu3lnPGd/qY54 tjgWBhBHAuKNcWCm3cMFrxzdhMdRMUQtHbehtCLGzTjUm1Vb+OzlIsY4XowsG8Eb2BBF h93scD/YOrdfSyRkPaFDBOwV3VuEGLD1fEsTSqsCtKcPmrvkjahrpxhwxigq2GnfqfJW QxyAmEGE6PgSycE/EZLyRNvjNxiYr5Np61vEiVDquylnq85pX/vC4G78WC4b0IBXIcYT 54AcujAwxlDi5eIsQEVqKAEvoTbVk26BfI1zMLVCt3Qp82F8YNc0nLyGOCqYCIka116F l6lw== 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=l3H4/EZviulqejooLx4wkjMJzF09A09A4x/ztGcOCwk=; b=dKWZk+hksekxRCEaGVsgfoxBFJfL3OVNM4MT9YGxsdvgsH8vDhkvMdd30JeZQeiHe/ ax9J+TFwlQYzjp0BoAgcOYd2nARh+HiyBno8eW7Fd2zpV4NxDcql9rJcLQ1QDSfWaqWh dzJv6oNrnFo7WH3HyiilIvhdlMxo+G1cE91+eZ7LYGOFYXBJiBaIHuIF6Qm5TffMkl5B 38Dq5ONVmGB01YEeIp4bQU3mMPZA8bWpKP+NBooNEuxOjpdV9PL8G1cXIvRcdMRyM7Am GAjf/U9ckwCJk6Rb3oSSC42tCclCNaOOBjH+uXhTax8FG28tyRMzyRvDT41/qml2mnLE D1/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EclcHV8m; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 z33-v6si3744818plb.694.2018.04.10.16.43.11; Tue, 10 Apr 2018 16:43:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EclcHV8m; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754642AbeDJXnI (ORCPT + 29 others); Tue, 10 Apr 2018 19:43:08 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:54123 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752988AbeDJW0J (ORCPT ); Tue, 10 Apr 2018 18:26:09 -0400 Received: by mail-it0-f66.google.com with SMTP id m134-v6so271219itb.3 for ; Tue, 10 Apr 2018 15:26: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=l3H4/EZviulqejooLx4wkjMJzF09A09A4x/ztGcOCwk=; b=EclcHV8m006CStuIV5DfTqqY/k9qOmyHKUWqEWEtVyAo6ZZY8fDQLFuU8eCRWpoKQ7 11K8UIz6DNTOBhJn+PLsxV4Pi21yWMLlZYjnJhskKsNQg03l/nv78IlB+2heJQEXyrju /kS/CQEhJRtzmK5VOyYzcrp0KozrlT0VyUqZo= 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=l3H4/EZviulqejooLx4wkjMJzF09A09A4x/ztGcOCwk=; b=XFUMnqgklLI/meNKHSfG2Y7r6BfZsLQ7P/bggACUv+7xlsyFvVv6VD5sXj9fBzTLuJ bDHLIuwxlnLxWjbU4loW14tuZtk48h/LnJ+VULph7s5l9MbWeIx3AZtiqY7G+BcpOA6Z tL/jBAQMIsjGJXteO8tYP+xMzLkwaPzE1pYdJEWPEGr+YxoeDr2fkAQbm2IcPG2slJMw eWpnVJ648pdou7NmsI0l0GjmRy+hi5ez9Hb5R5T1mdHgiWgfqikv1mXlIF2OxObO5hkZ NlKj+314zR6GOBU/f1DzOyS55Nu9RZVhPT4ZcnxJV8weY6/yMewhVCruQXZxQnfd2Wv7 G/NA== X-Gm-Message-State: ALQs6tCRSUOOT1wG0Sn2v4iYscX96tkeO2CaH0bwp0PeAoD+fCjGaDOj tTi7ofMjYPiViqvMq6gtWz0nnfKNEo8= X-Received: by 2002:a24:c2c7:: with SMTP id i190-v6mr1437363itg.146.1523399168805; Tue, 10 Apr 2018 15:26: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 l16-v6sm1373640iti.18.2018.04.10.15.26.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 15:26:08 -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 3/6] soc: qcom: smem: byte swap values properly Date: Tue, 10 Apr 2018 17:25:39 -0500 Message-Id: <20180410222542.29474-4-elder@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180410222542.29474-1-elder@linaro.org> References: <20180410222542.29474-1-elder@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/soc/qcom/smem.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) -- 2.14.1 diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 3102aa94aec2..82f0908b90e1 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -365,13 +365,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; @@ -400,6 +395,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, @@ -563,8 +563,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); }