Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp58044imu; Thu, 8 Nov 2018 05:02:38 -0800 (PST) X-Google-Smtp-Source: AJdET5fFBLkWfVxvdJ+XcBequntgdxEfv07rUVFJMUS6iexOt2N985wPD3YtOZ01RTYdr9cecSY2 X-Received: by 2002:a17:902:1122:: with SMTP id d31-v6mr4484433pla.259.1541682158733; Thu, 08 Nov 2018 05:02:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541682158; cv=none; d=google.com; s=arc-20160816; b=DqMCX5vDpe4635ufBX9Gu7ATh4z3TGMeEUcA1CRdGGssnTER3B8gedETGqAwGSfgqo 9xtij/hJ8byB4nQ+wW7ajp/xi528OApSUW8uj+PKpyKDlVooVJ1jhHuPPJUuJS6kvSIa WlskteqrQZcTqv9jnfY1yrz3FZOp9M92yRl1i8ZMCcrYe9LL9SjOkRmSmprcAqWd2e89 LflWH5lm8/LtYeixJmVMgzPKyHmGocI8lT2tDh7HRkXhq6FVyRpolj0rwvoeKd/BN/1b +2WjYqwBaBiicMq/GvQ0eXZ0RqCTSF7t3GDfWWK2Kt9tF3UcdER90tF+BF7zMCQmeQ4k un9A== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=fIR6h7esO+VckZNy0eo1UzXeoIpTjNendSwpWo8SenM=; b=XgTkfdzfsUKofkqjr/j0RW6xJaG9nP8UntselU/N6MWFW+07eAjMV+pipCO3kPK6u8 Cz+JayVU9vEM8SjC2MYzFZG88m1UC5HQYdCpeSD7jvVFErYCoxCyFR/dQY4lXeBIR5E5 YosPkKXtnm8ZID4sq5pZzZVIr2L/IjcDzREGG4LenWxN3+Sh54Edp1RfdWGE/AjLEf/9 CvPOSf/F98Q4HLDTn/H7GkiVplvVgItNQ5wEYV2E6EezGQq+gXEfg0y3mM/o9Eq6AwqX Iig1zUelLs4OGPrkVy+tCyQY0RhUQknDABvCnwTemLHiZ0gWfti8dLvmuCOXJeM80b1x YKLQ== 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 q201-v6si5476697pfq.14.2018.11.08.05.02.20; Thu, 08 Nov 2018 05:02:38 -0800 (PST) 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 S1727079AbeKHWhL (ORCPT + 99 others); Thu, 8 Nov 2018 17:37:11 -0500 Received: from mail.bootlin.com ([62.4.15.54]:37073 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726993AbeKHWhL (ORCPT ); Thu, 8 Nov 2018 17:37:11 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id 92E61224CD; Thu, 8 Nov 2018 14:01:45 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.2 Received: from bbrezillon (aaubervilliers-681-1-30-49.w90-88.abo.wanadoo.fr [90.88.15.49]) by mail.bootlin.com (Postfix) with ESMTPSA id 3B010207B0; Thu, 8 Nov 2018 14:01:35 +0100 (CET) Date: Thu, 8 Nov 2018 14:01:35 +0100 From: Boris Brezillon To: Cc: , , , , , , , Subject: Re: [PATCH 5/7] mtd: spi_nor: pass DMA-able buffer to spi_nor_read_raw() Message-ID: <20181108140135.09a23152@bbrezillon> In-Reply-To: <20181108110653.21063-6-tudor.ambarus@microchip.com> References: <20181108110653.21063-1-tudor.ambarus@microchip.com> <20181108110653.21063-6-tudor.ambarus@microchip.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 8 Nov 2018 11:07:16 +0000 wrote: > spi_nor_read_raw() calls nor->read() which might be implemented > by the m25p80 driver. m25p80 uses the spi-mem layer which requires > DMA-able in/out buffers. Pass kmalloc'ed dma buffer to spi_nor_read_raw(). > > Signed-off-by: Tudor Ambarus > --- > drivers/mtd/spi-nor/spi-nor.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c > index 79ca1102faed..2eaa21c85483 100644 > --- a/drivers/mtd/spi-nor/spi-nor.c > +++ b/drivers/mtd/spi-nor/spi-nor.c > @@ -2161,7 +2161,7 @@ spi_nor_set_pp_settings(struct spi_nor_pp_command *pp, > * @nor: pointer to a 'struct spi_nor' > * @addr: offset in the serial flash memory > * @len: number of bytes to read > - * @buf: buffer where the data is copied into > + * @buf: buffer where the data is copied into (dma-safe memory) > * > * Return: 0 on success, -errno otherwise. > */ > @@ -2868,11 +2868,16 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt, > u8 smpt_len) > { > const u32 *ret; > + u8 *dma_safe; I'd prefer to have it named buf, data_buf or scratch_buf... > u32 addr; > int err; > u8 i, ncmds, nmaps; > u8 addr_width, read_opcode, read_dummy; > - u8 read_data_mask, data_byte, map_id; > + u8 read_data_mask, map_id; > + ... and have a comment here explaining why your allocating the buffer instead of using a local var placed on the stack. > + dma_safe = kmalloc(sizeof(*dma_safe), GFP_KERNEL | GFP_DMA); Please don't use GFP_DMA, kmalloc() should already return a DMA-safe buffer (see [1]). > + if (!dma_safe) > + return ERR_PTR(-ENOMEM); > > addr_width = nor->addr_width; > read_dummy = nor->read_dummy; > @@ -2890,7 +2895,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt, > nor->read_opcode = SMPT_CMD_OPCODE(smpt[i]); > addr = smpt[i + 1]; > > - err = spi_nor_read_raw(nor, addr, 1, &data_byte); > + err = spi_nor_read_raw(nor, addr, 1, dma_safe); > if (err) { > ret = ERR_PTR(err); > goto out; > @@ -2900,7 +2905,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt, > * Build an index value that is used to select the Sector Map > * Configuration that is currently in use. > */ > - map_id = map_id << 1 | !!(data_byte & read_data_mask); > + map_id = map_id << 1 | !!(*dma_safe & read_data_mask); > ncmds++; > } > > @@ -2941,6 +2946,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt, > > /* fall through */ > out: > + kfree(dma_safe); > nor->addr_width = addr_width; > nor->read_dummy = read_dummy; > nor->read_opcode = read_opcode; [1]https://elixir.bootlin.com/linux/latest/source/include/linux/gfp.h#L263