Message ID | Y8i85zM0u4XdM46z@makrotopia.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp130196wrn; Wed, 18 Jan 2023 20:09:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXtoufIJXJUESTrdWtfVR/rZKDMKm8i/5D7mFttTl1rfxJ0d+O3jBLyUWxpoVVksZvJXHIPN X-Received: by 2002:a17:902:7fc9:b0:194:84f2:c1ec with SMTP id t9-20020a1709027fc900b0019484f2c1ecmr9928912plb.21.1674101355355; Wed, 18 Jan 2023 20:09:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674101355; cv=none; d=google.com; s=arc-20160816; b=QFtVGTpeiZ2CcFDM6MundLpfQ/tR0Rik3dmdvvKuvhBqPHm+Mhx8Sz0d3REsTNbgBA dK1R9kgmfoZGIAJ6ymG+Q2blYeSPXu4lpFvfUZHGXNLpUL5334jAQQm8tj++H/MrgP2Z sn8f4HOqI5VSyxGBQPr8d0lgwKNZauFYPVfuI+EnYAbTgPl0fmFfA20HJspAmcWRsFEQ giB3af0RIrBul8SlPLScq2Jk0hu69byifJwGkRkhTxlD9y+BRdoeNrJvkmE1wN7r3UnZ 2Cntn/1bkhPtm6huegoVNQJPiZ8yvA7K7TcX1uheYuysnDiM0d4vljp3CVuKFpCo+qD5 c4fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date; bh=Vpk4BlqV1r5hS3t2t88+cW9b0/99SZA/UQajw1jAEGg=; b=S4Mvq0K+7AykUDBCmUqL1g6RQlZoBmyEj27tYrjuwP4HclPvap4JZdFMPz8OYeRea+ BwoBqkIqQwMgNIiDWe1PwbvLC759yBrpfICX+FniGpt9SDJLFv9ZxYJOMhbyKRoyIG42 nN3kgEJjg7pbUligj7gkSIXZhUp/FCmSnFlG7Zt3s7hcq1lm/q41u3lICwaVVKhdgR19 gcsZpMSt0osmUWGgmNERKKii3123yQ1ygLchnNhH0Rl9XAGOvJKCobSC0FHHA/+uA0f8 uTRJKxSV1bTMoDTTCUZO6HL4qJLKJqiSyrAZQqJFj2Tm7xfslQVVMKkYpvfM0RIPKfCZ 9zVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j6-20020a170903024600b00192d4c98f87si40393284plh.308.2023.01.18.20.08.46; Wed, 18 Jan 2023 20:09:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230162AbjASEG4 (ORCPT <rfc822;pfffrao@gmail.com> + 99 others); Wed, 18 Jan 2023 23:06:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbjASDtj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 18 Jan 2023 22:49:39 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A13B037575 for <linux-kernel@vger.kernel.org>; Wed, 18 Jan 2023 19:47:44 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from <daniel@makrotopia.org>) id 1pILs6-0004aJ-14; Thu, 19 Jan 2023 04:45:50 +0100 Date: Thu, 19 Jan 2023 03:45:43 +0000 From: Daniel Golle <daniel@makrotopia.org> To: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Miquel Raynal <miquel.raynal@bootlin.com>, Richard Weinberger <richard@nod.at>, Vignesh Raghavendra <vigneshr@ti.com> Cc: Mason Yang <masonccyang@mxic.com.tw>, Jianhui Zhao <zhaojh329@gmail.com> Subject: [PATCH] mtd: spinand: macronix: use scratch buffer for DMA operation Message-ID: <Y8i85zM0u4XdM46z@makrotopia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755422502791236313?= X-GMAIL-MSGID: =?utf-8?q?1755422502791236313?= |
Series |
mtd: spinand: macronix: use scratch buffer for DMA operation
|
|
Commit Message
Daniel Golle
Jan. 19, 2023, 3:45 a.m. UTC
The mx35lf1ge4ab_get_eccsr() function uses an SPI DMA operation to
read the eccsr, hence the buffer should not be on stack. Since commit
380583227c0c7f ("spi: spi-mem: Add extra sanity checks on the op param")
the kernel emmits a warning and blocks such operations.
Use the scratch buffer to get eccsr instead of trying to directly read
into a stack-allocated variable.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/mtd/nand/spi/macronix.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
Hi Daniel, On 19/01/23 09:15, Daniel Golle wrote: > The mx35lf1ge4ab_get_eccsr() function uses an SPI DMA operation to > read the eccsr, hence the buffer should not be on stack. Since commit > 380583227c0c7f ("spi: spi-mem: Add extra sanity checks on the op param") > the kernel emmits a warning and blocks such operations. Good catch! > > Use the scratch buffer to get eccsr instead of trying to directly read > into a stack-allocated variable. > > Signed-off-by: Daniel Golle <daniel@makrotopia.org> > --- Reviewed-by: Dhruva Gole <d-gole@ti.com> > drivers/mtd/nand/spi/macronix.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c > index dce835132a1e2..722a9738ba370 100644 > --- a/drivers/mtd/nand/spi/macronix.c > +++ b/drivers/mtd/nand/spi/macronix.c > @@ -83,9 +83,10 @@ static int mx35lf1ge4ab_ecc_get_status(struct spinand_device *spinand, > * in order to avoid forcing the wear-leveling layer to move > * data around if it's not necessary. > */ > - if (mx35lf1ge4ab_get_eccsr(spinand, &eccsr)) > + if (mx35lf1ge4ab_get_eccsr(spinand, spinand->scratchbuf)) > return nanddev_get_ecc_conf(nand)->strength; > > + eccsr = *spinand->scratchbuf; > if (WARN_ON(eccsr > nanddev_get_ecc_conf(nand)->strength || > !eccsr)) > return nanddev_get_ecc_conf(nand)->strength;
Hi Daniel, daniel@makrotopia.org wrote on Thu, 19 Jan 2023 03:45:43 +0000: > The mx35lf1ge4ab_get_eccsr() function uses an SPI DMA operation to > read the eccsr, hence the buffer should not be on stack. Since commit > 380583227c0c7f ("spi: spi-mem: Add extra sanity checks on the op param") > the kernel emmits a warning and blocks such operations. > > Use the scratch buffer to get eccsr instead of trying to directly read > into a stack-allocated variable. > > Signed-off-by: Daniel Golle <daniel@makrotopia.org> > --- Looks like my scripts did not properly sent the "applied" e-mail, so here it is, I applied this patch to nand/next. > drivers/mtd/nand/spi/macronix.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c > index dce835132a1e2..722a9738ba370 100644 > --- a/drivers/mtd/nand/spi/macronix.c > +++ b/drivers/mtd/nand/spi/macronix.c > @@ -83,9 +83,10 @@ static int mx35lf1ge4ab_ecc_get_status(struct spinand_device *spinand, > * in order to avoid forcing the wear-leveling layer to move > * data around if it's not necessary. > */ > - if (mx35lf1ge4ab_get_eccsr(spinand, &eccsr)) > + if (mx35lf1ge4ab_get_eccsr(spinand, spinand->scratchbuf)) > return nanddev_get_ecc_conf(nand)->strength; > > + eccsr = *spinand->scratchbuf; > if (WARN_ON(eccsr > nanddev_get_ecc_conf(nand)->strength || > !eccsr)) > return nanddev_get_ecc_conf(nand)->strength; Thanks, Miquèl
diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c index dce835132a1e2..722a9738ba370 100644 --- a/drivers/mtd/nand/spi/macronix.c +++ b/drivers/mtd/nand/spi/macronix.c @@ -83,9 +83,10 @@ static int mx35lf1ge4ab_ecc_get_status(struct spinand_device *spinand, * in order to avoid forcing the wear-leveling layer to move * data around if it's not necessary. */ - if (mx35lf1ge4ab_get_eccsr(spinand, &eccsr)) + if (mx35lf1ge4ab_get_eccsr(spinand, spinand->scratchbuf)) return nanddev_get_ecc_conf(nand)->strength; + eccsr = *spinand->scratchbuf; if (WARN_ON(eccsr > nanddev_get_ecc_conf(nand)->strength || !eccsr)) return nanddev_get_ecc_conf(nand)->strength;