Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1773982imm; Thu, 27 Sep 2018 02:13:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV62lR8VDISerUGLWY/1sHVnNlRtbcKrxf5SnHRrvwSG3uBoB8r0sKa9SQVHr/Wu5xTfBAbON X-Received: by 2002:a17:902:981:: with SMTP id 1-v6mr9931701pln.60.1538039629700; Thu, 27 Sep 2018 02:13:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538039629; cv=none; d=google.com; s=arc-20160816; b=ySJsgRS2jnhHPNTkMeHLBbN87oAWGsaLI8wVgqo/BzOw9iG+HY+3BLSCOq2gqjQ0PB rxKklAJ7OCuBZMAbMeWF7dzRUoeyRhMxwOXLkJKlLqJdzRZm+vaKG5SkUiL/pGHjl5NJ Er+Sga8qeqG5WNg3rnRUqfoD1u4XFrrWSoMJDyPd7RWzFEVltpqJKkn2NeYXWaHyHutW VzQ6UhXSWcLZ+tiuJQVCWtNUb9qROfTgB0QV8LoD9jVSKCDRwgh0eb4et/dV5LDXOzek hxTUuf4dCtpWikBCEb+dcdGn8vzR/sExTGtfeG2SF9DlN/EOkMpVNP0K+XrOEVKPWaUP Z/jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=PGwpZ/SYQbtyjc83qNoDZ97czspC5dnTySpQnIgnWsA=; b=YTxBLSXU3folIb1BaYU7T7Co3Jx3ofxOGWBZ9esKbsOhhI/K2tXxQPtI/hvt8s4M5m 6dmiCO5+woI/8yY8mvCQNlw/G3V04i4qO1X5rRggb4AgLPTF7llrOPlOLNrkHZ+wZKFV 99lUB9AHBo5DC6VRt+CvP15HUYDqR8WklbewNGcB/8fzzT35M1GRnZH2wlTPFz4DIzdL rWigiwxC/bXPr9eTcwe1IwzTe+lcAhlidsN+t76vfjycVHcIHwRIzFPlbdK9mW5tA1Dt xYJ2OIUQ2yz2LjJAzGQnCV4fo16mn9aum3x9trJwba2uOkCWdH0M4g9QEfmeugLCIJsD UvPQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b137-v6si1517562pga.90.2018.09.27.02.13.34; Thu, 27 Sep 2018 02:13:49 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728351AbeI0P3u (ORCPT + 99 others); Thu, 27 Sep 2018 11:29:50 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55378 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727285AbeI0P3t (ORCPT ); Thu, 27 Sep 2018 11:29:49 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4A1601117; Thu, 27 Sep 2018 09:12:32 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jarkko Nikula , Boris Brezillon Subject: [PATCH 4.18 40/88] mtd: devices: m25p80: Make sure the buffer passed in op is DMA-able Date: Thu, 27 Sep 2018 11:03:21 +0200 Message-Id: <20180927090305.611960984@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927090300.631426620@linuxfoundation.org> References: <20180927090300.631426620@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Boris Brezillon commit 4a3e85f2674cbfb81052059107d0165269778e2f upstream. As documented in spi-mem.h, spi_mem_op->data.buf.{in,out} must be DMA-able, and commit 4120f8d158ef ("mtd: spi-nor: Use the spi_mem_xx() API") failed to follow this rule as buffers passed to ->{read,write}_reg() are usually placed on the stack. Fix that by allocating a scratch buffer and copying the data around. Fixes: 4120f8d158ef ("mtd: spi-nor: Use the spi_mem_xx() API") Reported-by: Jarkko Nikula Cc: Signed-off-by: Boris Brezillon Tested-by: Jarkko Nikula Reviewed-by: Jarkko Nikula Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/devices/m25p80.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -41,13 +41,23 @@ static int m25p80_read_reg(struct spi_no struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(code, 1), SPI_MEM_OP_NO_ADDR, SPI_MEM_OP_NO_DUMMY, - SPI_MEM_OP_DATA_IN(len, val, 1)); + SPI_MEM_OP_DATA_IN(len, NULL, 1)); + void *scratchbuf; int ret; + scratchbuf = kmalloc(len, GFP_KERNEL); + if (!scratchbuf) + return -ENOMEM; + + op.data.buf.in = scratchbuf; ret = spi_mem_exec_op(flash->spimem, &op); if (ret < 0) dev_err(&flash->spimem->spi->dev, "error %d reading %x\n", ret, code); + else + memcpy(val, scratchbuf, len); + + kfree(scratchbuf); return ret; } @@ -58,9 +68,19 @@ static int m25p80_write_reg(struct spi_n struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 1), SPI_MEM_OP_NO_ADDR, SPI_MEM_OP_NO_DUMMY, - SPI_MEM_OP_DATA_OUT(len, buf, 1)); + SPI_MEM_OP_DATA_OUT(len, NULL, 1)); + void *scratchbuf; + int ret; + + scratchbuf = kmemdup(buf, len, GFP_KERNEL); + if (!scratchbuf) + return -ENOMEM; - return spi_mem_exec_op(flash->spimem, &op); + op.data.buf.out = scratchbuf; + ret = spi_mem_exec_op(flash->spimem, &op); + kfree(scratchbuf); + + return ret; } static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,