From patchwork Fri Nov 25 00:54:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9446371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8DFC360779 for ; Fri, 25 Nov 2016 00:55:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D08E27F8F for ; Fri, 25 Nov 2016 00:55:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71C5927FB3; Fri, 25 Nov 2016 00:55:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2C7C427FB0 for ; Fri, 25 Nov 2016 00:55:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cA4ne-00083f-UB; Fri, 25 Nov 2016 00:55:34 +0000 Received: from mail-wj0-x243.google.com ([2a00:1450:400c:c01::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cA4nC-0006lM-6H; Fri, 25 Nov 2016 00:55:07 +0000 Received: by mail-wj0-x243.google.com with SMTP id jb2so4306054wjb.3; Thu, 24 Nov 2016 16:54:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UjRoia4UptgQbCt/S2lPhyPmnulTWCtC2UuwjTmvmkY=; b=rijpmEYi1el2J7urEHnPJW+dXS7hW4zgiDFFQftTYbHnusi4qWGbpNq3L3kP5zXvQo Kx4DSVR2fiBomJg2yoRhJmlHe5tduNayVs2ha8fYl5BgwZRe50pG4kWEeaX2U1N5zBLe VPcBSAzhiM7hqjB8Yr4PBlHN7J+aJRDzmXXvEf1yusXiTfp5QxzXDZbiQHFzVqOBvppm XJrNvrA952NeBE7rhflcFxdv7gS6avL5tyWoU5SYYRKvW2k7R8nuR6l43g3Se+XAysw/ /TzsAc5+U76IrsxXbzOFUfJokpXx6QVyGdUjOB6lGHkVj8MkyFf6jZG/kyN4rdrug82j humw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UjRoia4UptgQbCt/S2lPhyPmnulTWCtC2UuwjTmvmkY=; b=agTUt53o+pBYXRo3E7mpd4W7LDjRYW47GpOZUSeb+u7rk+9urtubSQT+BBtb8amjv4 U6NZl+J+pRmdAOeVGfJjfEKiJBdprw6INuVFW4zebs0CgMtUrBhW0b6ZhbUC0NbpE4Hl psT/IMFbrYfRaukAl7dBrqW26Bh1fpOv28rChd32v1AvxZoExJYU+EBZuFSsQbH4bA+j a6+U+xB0QGzMz1Ugxuknd0yFZDW44xJ44az11x7KnhP6aUudhJ00CqR0plS4N5UvFc0C NGQ2xKtrQ9GsyUgQ5YWyWoCRaM5FWc/G4V3WH5zxW5E59lFl5PzOViU/db6n+8Lee6fo b8Ww== X-Gm-Message-State: AKaTC00PrXPHEJCtxjq2/KK+aX5PAGLl6JJ/R3gkOPSeFfk4M/H+Y3KnaEdizOGeqOZcaw== X-Received: by 10.194.222.132 with SMTP id qm4mr5271928wjc.150.1480035284117; Thu, 24 Nov 2016 16:54:44 -0800 (PST) Received: from blackbox.darklights.net (p5DE38BA9.dip0.t-ipconnect.de. [93.227.139.169]) by smtp.googlemail.com with ESMTPSA id g73sm10804181wme.16.2016.11.24.16.54.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Nov 2016 16:54:43 -0800 (PST) From: Martin Blumenstingl To: sudeep.holla@arm.com, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org Subject: [PATCH v2 1/2] firmware: arm_scpi: zero RX buffer before requesting data from the mbox Date: Fri, 25 Nov 2016 01:54:31 +0100 Message-Id: <20161125005432.1205-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161125005432.1205-1-martin.blumenstingl@googlemail.com> References: <20161124001845.20830-1-martin.blumenstingl@googlemail.com> <20161125005432.1205-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161124_165506_514002_26CD02FB X-CRM114-Status: GOOD ( 16.15 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , narmstrong@baylibre.com MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The original code was relying on the fact that the SCPI firmware responds with the same number of bytes (or more, all extra data would be ignored in that case) as requested. However, we have some pre-v1.0 SCPI firmwares which are responding with less data for some commands (sensor_value.hi_val did not exist in the old implementation). This means that some data from the previous command's RX buffer was leaked into the current command (as the RX buffer is re-used for all commands on the same channel). Clearing the RX buffer before (re-) using it ensures we get a consistent result, even if the SCPI firmware returns less bytes than requested. Signed-off-by: Martin Blumenstingl --- drivers/firmware/arm_scpi.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index 70e1323..8c183d8 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -259,6 +259,7 @@ struct scpi_chan { struct mbox_chan *chan; void __iomem *tx_payload; void __iomem *rx_payload; + resource_size_t max_payload_len; struct list_head rx_pending; struct list_head xfers_list; struct scpi_xfer *xfers; @@ -470,6 +471,20 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg) if (t->rx_buf) { if (!(++ch->token)) ++ch->token; + + /* clear the RX buffer as it is shared across all commands on + * the same channel (to make sure we're not leaking data from + * the previous response into the current command if the SCPI + * firmware writes less data than requested). + * This is especially important for pre-v1.0 SCPI firmwares + * where some fields in the responses do not exist (while they + * exist but are optional in newer versions). One example for + * this problem is sensor_value.hi_val, which would contain + * ("leak") the second 4 bytes of the RX buffer from the + * previous command. + */ + memset_io(ch->rx_payload, 0, ch->max_payload_len); + ADD_SCPI_TOKEN(t->cmd, ch->token); spin_lock_irqsave(&ch->rx_lock, flags); list_add_tail(&t->node, &ch->rx_pending); @@ -921,7 +936,9 @@ static int scpi_probe(struct platform_device *pdev) ret = -EADDRNOTAVAIL; goto err; } - pchan->tx_payload = pchan->rx_payload + (size >> 1); + + pchan->max_payload_len = size / 2; + pchan->tx_payload = pchan->rx_payload + pchan->max_payload_len; cl->dev = dev; cl->rx_callback = scpi_handle_remote_msg;