From patchwork Tue Apr 10 22:25:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 133128 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp91010ljb; Tue, 10 Apr 2018 16:44:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/IcFcb5dHGLFgvF1DIONBDQn9UMbon5orjuYi17KwoL/zFfAMMzUBx632IdxSTbAnyFEIk X-Received: by 10.99.121.134 with SMTP id u128mr1695042pgc.360.1523403842345; Tue, 10 Apr 2018 16:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523403842; cv=none; d=google.com; s=arc-20160816; b=HGfuUPwkYuK69es5wBsAeJY1T3PT3UK89lhfyEcJlrG6H5PVFu+1oGE1+xN95rIzZg 6iQo9X+WkczxclhgG/b0gMyGKSShq3OOFOmaKm2a7OBzHXAQ5/jwGjkAYZd0S//JQILU OrXj2xYR0C1WfzUVGzMUoLCP0aV2kAhM+LeeDgyd0XYz/nBW1hyHd9XT9+zNO4uVVIB7 DjOBNM7cl1o7VsV43W5PHhIT6IkvPY/iVZt8K8qmwL6zbWMptEf16DhYFriWatbkNEDX C8PxfVV4poxi7nKEHx2SqDry7fYHG/YasO3En6sa5p+Uc2V63Munm9ceoWv+BgD6GR6f zrZw== 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=/dRevxXRCKJJFWcSXie2zM4fuEtTKys67SAPUMlYQJk=; b=x8bCtZTxd94oqi7GcrXB3r0B3lBliGQz5/6sDgcMITNQxGEPGler1Zls+SizpgkVwP 6W3P/QJ89DXoGhRiuT3t70neto7M4ZK9x6kU29bZa+kAl+XduREhxfQeCEhSJE6zTpDH qD1JiB8LXn/2XGBpq9aLzG5rVltNuR9Bm51ypKXwiFRurR1XE3X2X9263ODTX+L1F/SN pnTif+AMVUi5N+CgapDlXw1aUhH0U9vG37BObmYbvaEcbK+EMpOiUU7D3d+U/l7sOSIN MjY6dNjhbHVUEEwYn0PJ6EpDsiyEoupw5GTkujhtrJYgyvdeBGo5nqKGmR/zb9ohOpVg +jsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kJA4eUCi; 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 x61-v6si3592088plb.213.2018.04.10.16.44.02; Tue, 10 Apr 2018 16:44:02 -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=kJA4eUCi; 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 S1754204AbeDJXn5 (ORCPT + 29 others); Tue, 10 Apr 2018 19:43:57 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:39958 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752985AbeDJW0H (ORCPT ); Tue, 10 Apr 2018 18:26:07 -0400 Received: by mail-it0-f68.google.com with SMTP id u62-v6so236359ita.5 for ; Tue, 10 Apr 2018 15:26:07 -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=/dRevxXRCKJJFWcSXie2zM4fuEtTKys67SAPUMlYQJk=; b=kJA4eUCimunvgzwioqimabt2TH3yxai2BgtZjJaJNAIwct0LRNNXvOAiFB572YiUgv jAqQG+clkmN1d6OkLpgb0rGn7uYxpK2FM34VblnMTwetnM15s8emI/S2E9q+2oq+FcKv JXpuOhY85019WqmzgqOwOcuiGPJRBT1W80kdI= 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=/dRevxXRCKJJFWcSXie2zM4fuEtTKys67SAPUMlYQJk=; b=Cx012k2AbYZ7nVUT/oMBFTI4T0BeNpkR7uZDHsNc1cXxRYY0/LqK4QuC0zY90sY1bu 83TgXOQZNKxm4INUHQQpj2rj2kEU8QlKQvDJ9dpKBr9xJ3VkJVvAx2hobTRWOYXoHPFD olTVoAAoE2SG/taGfH7VJ2kV2YL0Kti1EmiZ0DAURpYpKgURRxDuz8HvHwmBGxVC+cHV Za5qNQkpCX0y+tp9yRoT8HVGxHgGLlnj675KVdqvrDqOG0f5w62Ct002saczZUzhErOQ 2mrTD333bZ687/VceAKs39WPqE5ISrIk5JuERfd6qub6BJEbGJGBqdt48vzKiJ2yC3UT X54Q== X-Gm-Message-State: ALQs6tB+IBsqtgvAktQXI84JwjvTqgWdiHpUO0EYQmT3wbsX1jySpxVn A73GoXutd08xA5yHFO1LEzAZlQ== X-Received: by 2002:a24:4a03:: with SMTP id k3-v6mr1467098itb.124.1523399167009; Tue, 10 Apr 2018 15:26:07 -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.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 15:26:06 -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 1/6] soc: qcom: smem: fix first cache entry calculation Date: Tue, 10 Apr 2018 17:25:37 -0500 Message-Id: <20180410222542.29474-2-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 Cached items are found at the high end of an smem partition. A cached item's shared memory precedes the private entry structure that describes it. The address of the structure describing the first cached item should be returned by phdr_to_first_cached_entry(). However the function calculates the start address using the wrong structure size. Fix this by computing the first item's entry structure address by subtracting the size of a private entry structure rather than a partition header structure. Signed-off-by: Alex Elder --- drivers/soc/qcom/smem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.14.1 diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 0b94d62fad2b..7f38c5e11440 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -292,8 +292,9 @@ static void *phdr_to_first_cached_entry(struct smem_partition_header *phdr, size_t cacheline) { void *p = phdr; + struct smem_private_entry *e; - return p + le32_to_cpu(phdr->size) - ALIGN(sizeof(*phdr), cacheline); + return p + le32_to_cpu(phdr->size) - ALIGN(sizeof(*e), cacheline); } static void *phdr_to_last_cached_entry(struct smem_partition_header *phdr) 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); } From patchwork Tue Apr 10 22:25:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 133125 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp90295ljb; Tue, 10 Apr 2018 16:42:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx49msTpcpNaQvdrdf8gbrPEU3ilA6Jd7O9KOC2+IcQU2egwrBGIXLzQABjzzC/ELyXPTcz7R X-Received: by 2002:a17:902:8602:: with SMTP id f2-v6mr2430926plo.73.1523403771594; Tue, 10 Apr 2018 16:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523403771; cv=none; d=google.com; s=arc-20160816; b=UG+Wfo6UOlX/MVoKZ4mxrPDZlz6p1KibWP2jCVWv2PYw2iDvASY67FI68WKLEunQ3l dFkWWgvma2ze4c6WItzHqEDXFgjTGEoyyKmhhddAscaT/t7MUwQxNehc27Dkk48G0ECu PlQz6Km3nlHTHF1lR66jTdPjg2D2PG4iTR0hN7MXuA3YK4o22vaZtOKuYvHTDtgtvNwk eCXuaHv37DN/IJXc1qANF7yrCuSq+ndmieF+myPQqpqGWy+q0cEQ57rJ1uHKZJyyYZ50 e6sBnQM7qYvoj4+XjEsysWLOIM3UKIAmzVn8veoA4cIheDrirkXE/SH5eh1seZcaAVw+ vPgQ== 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=j/HWrJFLE73QOw+LK503/28bOtLSgJ+l2ovIc8z530k=; b=n+jRlIunV7ltCTwWWLAgf623skdkRTGmMtY14hZPrwRh+ij+qrLQ0j5vF5F9QfC2Kk sBcaUrBcEDGHvkQqL7f574GUuIRpWu3///zfxlgAOSO4c8By7phrl7ToBSCY5tporoKt mDcgC6IJaVp7K3Dp1+AdZTUDeYr8RMHx8BxaaFLjCBZyApx6xQmkEujt9cEMORRqtFiD WtPr/UkcHC+Em591MiHgBYolDutfJh3T53CftRWq5kGz1ZukdIYqSKtJbbvLOdYVaAHa n7lhD/ftq1TeQysVuxZkGDhdeMedWbCwK+TngybVuLitCsi0WcKSCxZYCjImS3ugElj7 q8ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f11uwQqm; 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 j2si1895754pgn.815.2018.04.10.16.42.51; Tue, 10 Apr 2018 16:42:51 -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=f11uwQqm; 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 S1754475AbeDJXmr (ORCPT + 29 others); Tue, 10 Apr 2018 19:42:47 -0400 Received: from mail-it0-f67.google.com ([209.85.214.67]:39961 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753027AbeDJW0K (ORCPT ); Tue, 10 Apr 2018 18:26:10 -0400 Received: by mail-it0-f67.google.com with SMTP id u62-v6so236464ita.5 for ; Tue, 10 Apr 2018 15:26:10 -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=j/HWrJFLE73QOw+LK503/28bOtLSgJ+l2ovIc8z530k=; b=f11uwQqmGct0wDzcuNrP1lzqC6yIaTdPDgrRLAT1ijiASrTubsBh/tiAQl1AsJO9iH CEBDgiJv1kmXCAy0xe4AhGI1KMuD3E47TO57bQtaVt0chXlyPmonGOHVPXFf36QN8cE1 9Hg2u4qCmXBDa6eaxHBX1vwzis0cQ3ytHM600= 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=j/HWrJFLE73QOw+LK503/28bOtLSgJ+l2ovIc8z530k=; b=YFwCPySjmuNLH/Goz4Agd/B0eM2vLx8a4RGSuIksiqZVJHTKpPUwi8FazwLHXDOv+s WaKZqSCC8R9mZ+ozevF1Z4A8CmGSCeQtO/K1+9eRVgvO7aeY0aE72uOiZcHqKSaOiWTF 77p4ild+Lue78jllovgTIPtudsVAB+blh6IqsTESXdNY+m0irPWG4zU/nAQxAGq7h/q2 HNX4fLDz3mN8ON9N5iyEl+QCD9Tk7m60cXKQk3PNTwl1Kso2k3Olhbp32S5Lkke2qzZq OdajGo56GWH5i4FIDsRq5kY+j0DKXaYJ97F+ZgAA8RWFynItCaQUy55Jv8/o6Nm+TALx QNxA== X-Gm-Message-State: ALQs6tC5Loe4vmOrn/Yl2Oix5+61CNslAJtjBQswQsbNpWcW+YWag6xK iE3AeSgJOKtc3e7K2q1TUg6RwQ== X-Received: by 2002:a24:f581:: with SMTP id k123-v6mr1406649ith.56.1523399169758; Tue, 10 Apr 2018 15:26:09 -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.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 15:26:09 -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 4/6] soc: qcom: smem: fix off-by-one error in qcom_smem_alloc_private() Date: Tue, 10 Apr 2018 17:25:40 -0500 Message-Id: <20180410222542.29474-5-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 It's OK if the space for a newly-allocated uncached entry actually touches the free cached space boundary. It's only a problem if it would cross it. Signed-off-by: Alex Elder --- drivers/soc/qcom/smem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.14.1 diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 82f0908b90e1..0ed263055988 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -375,7 +375,7 @@ static int qcom_smem_alloc_private(struct qcom_smem *smem, /* Check that we don't grow into the cached region */ alloc_size = sizeof(*hdr) + ALIGN(size, 8); - if ((void *)hdr + alloc_size >= cached) { + if ((void *)hdr + alloc_size > cached) { dev_err(smem->dev, "Out of memory\n"); return -ENOSPC; } From patchwork Tue Apr 10 22:25:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 133120 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp39194ljb; Tue, 10 Apr 2018 15:26:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx4//KEpoX5SHXEbz/5CQCIstczWPgLnQT8kPyF4roL79ln18yvMOGuXkhPUwu+LXnAoGJt45 X-Received: by 10.101.85.200 with SMTP id k8mr1564689pgs.290.1523399180227; Tue, 10 Apr 2018 15:26:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523399180; cv=none; d=google.com; s=arc-20160816; b=obGFTC87RGzzQrxrcHGCh+v+dRgz2ErnBWz6Lw1dSg99Rm/h9dD9ZYLllOqvg9vGxP Oi8xEx1ecXSxgbC3TvvgNvNrJoZbcs4PbBRv5z3PbHZxq191dxJAaL1L9AW71AakZlul SLb+f+1CgaViaKvcw6tCH5RTSCiaX5C3C0pGO7g8bD5YO3qfqHG9Skqs+WB4xYLDC2J9 TW3psledrYcPdBohAxh17ifzEiBhWfHRX7EzpWn2GcG+RzGbCiJjXDYBL4cvs7s/RY/F oWgj7/uRUG7nBipp/4ETVYg01VmoCz0mJgC56CWlVVtNcjYywerXX2hvNe9NGNk81u3h LjBg== 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=5wlkiebE+lt8D2K+rDYtdKU2imQTARWjqvZM2UydGD8=; b=I29SwW2qzXM0dS4emnuIbtqvo9YjK7mAmL9m17P07PQO3n54eA4hkJAhRfr3hOoe56 2cAyJhBCK/IvQqXO5KQ5AVZ1MxmdWX9U32cn6xEIcjvbo5L2Wp9KT9QEWmShpg5Y98V+ rhajrTad7stY3rc0sxxe3eJhnQrwzNgaJA9cjXVxuQcBKV4AImESP5HEw1Lcj4sdM6MS oYsA8YoIA3b4qcWe1p7ro+P93WhRodzON60+nYVKgQCRiuTNiuOX2mkcW0OM7T7ZOi8P G5WZbtAgkzU+SczbbaK0cpZCFJhTs3kxSCJ3Pw6VXujm/KKBC7ZDUx6xQ6TtST3bSpgV 0D9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OqTCwApj; 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 s13si2394424pgr.802.2018.04.10.15.26.19; Tue, 10 Apr 2018 15:26:20 -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=OqTCwApj; 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 S1753091AbeDJW0R (ORCPT + 29 others); Tue, 10 Apr 2018 18:26:17 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:37308 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753051AbeDJW0M (ORCPT ); Tue, 10 Apr 2018 18:26:12 -0400 Received: by mail-it0-f66.google.com with SMTP id 71-v6so255437ith.2 for ; Tue, 10 Apr 2018 15:26:12 -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=5wlkiebE+lt8D2K+rDYtdKU2imQTARWjqvZM2UydGD8=; b=OqTCwApjGkfP65S9dpNe+mI/xbYC7MIA7uNTmueb76zGBUKYZ6XJTHaUNqIpHkpGR/ Wnm/RnvftTzlE5B6sPU7LSUXK9m006TA5LO/0iUdPHe/yAvhyTcmxbCjB4JKhJ+IWG9V qOLgd9dffr92EL1Jh47jgCxMcf1kvsbrtvT5o= 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=5wlkiebE+lt8D2K+rDYtdKU2imQTARWjqvZM2UydGD8=; b=sm3shjccE1lqXbzq73TIR+lsHZUKyrZwSftK8Opt0S8bWtp7PFuC5yRYhpbc/LBjeo TDa8z09F5AJr+42SSQ/vTybDohlyf2zYxay7MIuU1iA0+5CJr2ag9bfJqwThBkkgfG8t XRh6cagfvXYtTU4qYODlHWrIY4LMtIXDt2BQ8S4OGGb0WHuYCM1CjwiYcjgKQ6GjMW3C ULoNMKYNZLA+ZLhv2FGtGWFP86fuXlgyTn3U8fkSMyZbPJZfsWjR2C1YL8+SDt/A8hb6 vaU/dxfhCEaxGfxfyCfi/Sn4UQ7d1pBQ3FCygyKpT6K4B4dfN/W0CY1cTx2iZh9t5B4Z OcBA== X-Gm-Message-State: ALQs6tCZehEYQQLkDkJDL5unPcFJDJqYYEzgVTMesmPO34PU3wjI/hs6 /O0EqYTw/pWO8PbTvysebvlixA== X-Received: by 2002:a24:5f45:: with SMTP id r66-v6mr1432180itb.126.1523399171632; Tue, 10 Apr 2018 15:26:11 -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.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 15:26:11 -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 6/6] soc: qcom: smem: check sooner in qcom_smem_set_global_partition() Date: Tue, 10 Apr 2018 17:25:42 -0500 Message-Id: <20180410222542.29474-7-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 There's no sense in scanning the partition table again if we know the global partition has already been discovered. Check for a non-null global_partition pointer in qcom_smem_set_global_partition() immediately. Signed-off-by: Alex Elder --- drivers/soc/qcom/smem.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.14.1 diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 6e42599b70d4..7d9a43da5084 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -364,6 +364,11 @@ static int qcom_smem_alloc_private(struct qcom_smem *smem, end = phdr_to_last_uncached_entry(phdr); cached = phdr_to_last_cached_entry(phdr); + if (smem->global_partition) { + dev_err(smem->dev, "Already found the global partition\n"); + return -EINVAL; + } + while (hdr < end) { if (hdr->canary != SMEM_PRIVATE_CANARY) goto bad_canary; @@ -729,11 +734,6 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem) return -EINVAL; } - if (smem->global_partition) { - dev_err(smem->dev, "Already found the global partition\n"); - return -EINVAL; - } - header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); host0 = le16_to_cpu(header->host0); host1 = le16_to_cpu(header->host1);