Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp20307ybh; Tue, 17 Mar 2020 17:18:01 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvUX958H7tg8gGlhW0cBQr25QiDQga8W/KXeYt8+Ofh2owFyFDFFrduMwmc85BslR7nXUVB X-Received: by 2002:a9d:7cc9:: with SMTP id r9mr1830175otn.154.1584490681567; Tue, 17 Mar 2020 17:18:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584490681; cv=none; d=google.com; s=arc-20160816; b=cECt44GEvfNCTAfp65u4pSSaUT26pby8N0ti9Eo2PjjD1BqpKU3d4aySH9iHVwCv8w 8EyAwYWSiAOZWouogqx8a34go8cfY0Wr/hrjwtWgEYRP1QJqoHCAX/Jmm6H0hS7EfX7x sNdFnjmrrJI1MAXl/+jt09K3phEVlIYlqfclp83YRWNySg3xNnAKLhhV4hLH9CpL9aBU +BU3nTxH1J4yFoP5hvciiXgKw7vahlPGCBu7/nAv92icYJdErBH6vKb+lEz74IenKvAm MElsTA8mg+YnqwB7UsYZFYNtmw4HsoOf23mKumGmY7ik2Xn9Rt/ivVTGwXmt0BS3X8Bt XXxg== 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; bh=LtJjhRPIy7AYBnH/+FNJCutzC44JnMplfSDwQrTUa8w=; b=jiYBWgP0pbhanoNyFHpv6L8zwTuGDRhkd2K5dm+Se0GV2e/m3SmT9S1LM2MfKaOXYg vF4UU4TGT5cieQT6UE6I3YAfKNDX5wtvv4NkQ0cq98B9eONUe0S5eDRm72ZtRV9G4Qj2 UX9zkKJtEEgRbcYDdG/5isgmGyxxALWU7ylzywMsO0b4I4uVw8fW0TT35Aq8UD5/zm5y 2kpz2BoJzvFz2fVEfEEcOA3Zsqd7grfL9ekGbBh1l5DfdMHp8eioKkVNra4Ws0xj+BMi 2f+4qZ2c8xgXOnunpQJV8an43TD74UGfWub1Z8t0ZaoYFrYITqSN5pdDzdPUKnwyQTj9 qiow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jbSOl1Aw; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5si2317345otk.178.2020.03.17.17.17.43; Tue, 17 Mar 2020 17:18:01 -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=@gmail.com header.s=20161025 header.b=jbSOl1Aw; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727283AbgCRARQ (ORCPT + 99 others); Tue, 17 Mar 2020 20:17:16 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:56315 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726991AbgCRARO (ORCPT ); Tue, 17 Mar 2020 20:17:14 -0400 Received: by mail-wm1-f68.google.com with SMTP id 6so1303305wmi.5; Tue, 17 Mar 2020 17:17:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LtJjhRPIy7AYBnH/+FNJCutzC44JnMplfSDwQrTUa8w=; b=jbSOl1Awue/1LPRRc+xSPb9r+8QvOIlbvb25O6i8BGZgfpAtA1ZOnCyPHRosISF29I Ezp/SyZTuH3p2oeNcSk8B51hijLOv/S3UhcF+MUiHyRbxdPUKZRHALBHAuOPiqEJ4tCF J4orZviFR1gSge+5sFACQXQmzWW8/PeBHnW6qDaRYMYeAXVX+j32QzRO4LaKXnaWXJCT jeNkLOHqZaHk7fICB7yV0wQTrRJX1W6pa1Scdx3JhTrzqUMeGEC+MXUaAZGeUu5ygi1r hk0En70j4+s45QLwK7KAnIcZ+2+/7WB5LE9ZjRNtvS/WR9VSU4DnkyX7qjvc3gi3LDI2 dMkg== 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=LtJjhRPIy7AYBnH/+FNJCutzC44JnMplfSDwQrTUa8w=; b=KLbno19G/uX4BmOYYXLeGvJCeCAdFfxMjwu7qVG/rI7pcG3SRfiC+z62Do79Umvk/C 5dJ5cHc2P3CtCyzcewGwRSl1gjvonbsnFxZQMSbNLZhpTUnGgwYac8x7fA5bQSFiCgrl NPgtdnfkns12KXWcbm33v3ZBGK0le4j/cA9qcOo3U9HjIR1iZKjqX/NUmE2GpbvrWQmW XTr66LWse8sFDIWntu/ElsyBI0KAXNdvzTF4FBTR2WaWGxYoOMwLbHzzrNMbTUIbD9mF kvKNF39eg+CpIdLEVZ3d3q8huMzKK+7fErQm+06viw2mLP+qQHneAIKsLsbsVIeuFM9k I0aw== X-Gm-Message-State: ANhLgQ01IuxCxCxw0zC4IPfwjKt1km7I2FFcFfxDa7rZE6mfFPn5MJeg 3DrlMni7vyPb4eBeYGr5iFEgc7/N0X2+Iw== X-Received: by 2002:a1c:de82:: with SMTP id v124mr1539863wmg.70.1584490632322; Tue, 17 Mar 2020 17:17:12 -0700 (PDT) Received: from localhost.localdomain ([79.115.60.40]) by smtp.gmail.com with ESMTPSA id i6sm6584600wru.40.2020.03.17.17.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2020 17:17:11 -0700 (PDT) From: Vladimir Oltean To: broonie@kernel.org Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, shawnguo@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, devicetree@vger.kernel.org, eha@deif.com, angelo@sysam.it, andrew.smirnov@gmail.com, gustavo@embeddedor.com, weic@nvidia.com, mhosny@nvidia.com, michael@walle.cc, peng.ma@nxp.com Subject: [PATCH v5 04/12] spi: spi-fsl-dspi: Avoid reading more data than written in EOQ mode Date: Wed, 18 Mar 2020 02:15:55 +0200 Message-Id: <20200318001603.9650-5-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318001603.9650-1-olteanv@gmail.com> References: <20200318001603.9650-1-olteanv@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean If dspi->words_in_flight is populated with the hardware FIFO size, then in dspi_fifo_read it will attempt to read more data at the end of a buffer that is not a multiple of 16 bytes in length. It will probably time out attempting to do so. So limit the num_fifo_entries variable to the actual number of FIFO entries that is going to be used. Fixes: d59c90a2400f ("spi: spi-fsl-dspi: Convert TCFQ users to XSPI FIFO mode") Signed-off-by: Vladimir Oltean --- Changes in v5: None. Changes in v4: Patch is new. drivers/spi/spi-fsl-dspi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 8f2b73cc6ed7..51224b772680 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -739,13 +739,16 @@ static void dspi_eoq_fifo_write(struct fsl_dspi *dspi) int num_fifo_entries = dspi->devtype_data->fifo_size; u16 xfer_cmd = dspi->tx_cmd; + if (num_fifo_entries * dspi->oper_word_size > dspi->len) + num_fifo_entries = dspi->len / dspi->oper_word_size; + dspi->words_in_flight = num_fifo_entries; /* Fill TX FIFO with as many transfers as possible */ - while (dspi->len && num_fifo_entries--) { + while (num_fifo_entries--) { dspi->tx_cmd = xfer_cmd; /* Request EOQF for last transfer in FIFO */ - if (dspi->len == dspi->oper_word_size || num_fifo_entries == 0) + if (num_fifo_entries == 0) dspi->tx_cmd |= SPI_PUSHR_CMD_EOQ; /* Write combined TX FIFO and CMD FIFO entry */ dspi_pushr_write(dspi); -- 2.17.1