From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4ADEFC54E4C for ; Fri, 23 Feb 2024 11:56:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Gw1Cd2UIdSXoNF0HQkQe0WhxizZMdBGIMViMeP2MOK8=; b=L05jx1pEo/s4OZ Zi9XAEepQwgzITlFBAll66YM2aXfacjCDDYhZM50IkuVKX8j2qcwW8mWDVJVu1HdnGLMdXK5x3W0J QScVNpO1L7sjGcP2T4f/g7vyyrUKHg7ijHFxP0/ju+X0O53+U0gnLvxENWgXHflCEd8tMjcmxbr22 b2BK52MRmDsIWkvjKhppNjrG7gXcP9GAfBXaJyWUOAxnxSomvGepJCG4RNSY+tsc7XGjNR5TsANN8 sxA94s8ufSy7GbZ1h4TTT8+e1XSJ0vpRYBsTDPUDJjUdSINknOSevef96aadJl5ac/kKsUP7mCNvy 4gCR2cQyfpil/g1Mt6uQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdU9s-00000009EdV-35J8; Fri, 23 Feb 2024 11:56:04 +0000 Received: from relay6-d.mail.gandi.net ([217.70.183.198]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdU9i-00000009Eb4-2Go5 for linux-mtd@lists.infradead.org; Fri, 23 Feb 2024 11:55:58 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id B3968C000A; Fri, 23 Feb 2024 11:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708689350; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8yrP8J9ft/GYoNxsSdLSCccwDVuNUqlEsP+2f7HuanA=; b=UdpfAvTsQ8T+NJXqujvznRZyQgsNEoFKSKyQy+pI3cnAdr8N/l2Z9JYCBYm39cKnE1Qrby H3MnBlHoTQH7MOrLOHpUPgu9b25ZEQ1wlG0wIuDzU4wlJGmXX802I/WOeohNjAqiSD/EEm +4v+bnh7Pr0SLMToHDP1exPtd268x0AHM8il8NSfHqtjhAswh+MLSmgYStIEcuQQ/SPg5O QMbHSr1/CQQRem+yRLzzLHfhaIar/LNZYm3jgAjd2XjPD5Kf2+NU+FbVmdgg25eemxp1Xm rr7Mkk/w9qbHEntErpjhgRL4oD6PFtLxGMyczWC0u4cuQ16eaY2RkyS2gkbqhg== From: Miquel Raynal To: Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus , Pratyush Yadav , Michael Walle , Cc: Thomas Petazzoni , Julien Su , Jaime Liao , Jaime Liao , Alvin Zhou , Christophe Kerello , eagle.alexander923@gmail.com, mans@mansr.com, martin@geanix.com, =?UTF-8?q?Sean=20Nyekj=C3=A6r?= , Miquel Raynal , stable@vger.kernel.org Subject: [PATCH 1/3] mtd: rawnand: Fix and simplify again the continuous read derivations Date: Fri, 23 Feb 2024 12:55:43 +0100 Message-Id: <20240223115545.354541-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223115545.354541-1-miquel.raynal@bootlin.com> References: <20240223115545.354541-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240223_035555_015445_2C653604 X-CRM114-Status: GOOD ( 12.85 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org We need to avoid the first page if we don't read it entirely. We need to avoid the last page if we don't read it entirely. While rather simple, this logic has been failed in the previous fix. This time I wrote about 30 unit tests locally to check each possible condition, hopefully I covered them all. Reported-by: Christophe Kerello Closes: https://lore.kernel.org/linux-mtd/20240221175327.42f7076d@xps-13/T/#m399bacb10db8f58f6b1f0149a1df867ec086bb0a Suggested-by: Christophe Kerello Fixes: 828f6df1bcba ("mtd: rawnand: Clarify conditions to enable continuous reads") Cc: stable@vger.kernel.org Signed-off-by: Miquel Raynal --- drivers/mtd/nand/raw/nand_base.c | 38 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 3b3ce2926f5d..bcfd99a1699f 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -3466,30 +3466,36 @@ static void rawnand_enable_cont_reads(struct nand_chip *chip, unsigned int page, u32 readlen, int col) { struct mtd_info *mtd = nand_to_mtd(chip); - unsigned int end_page, end_col; + unsigned int first_page, last_page; chip->cont_read.ongoing = false; if (!chip->controller->supported_op.cont_read) return; - end_page = DIV_ROUND_UP(col + readlen, mtd->writesize); - end_col = (col + readlen) % mtd->writesize; + /* + * Don't bother making any calculations if the length is too small. + * Side effect: avoids possible integer underflows below. + */ + if (readlen < (2 * mtd->writesize)) + return; + /* Derive the page where continuous read should start (the first full page read) */ + first_page = page; if (col) - page++; - - if (end_col && end_page) - end_page--; - - if (page + 1 > end_page) - return; - - chip->cont_read.first_page = page; - chip->cont_read.last_page = end_page; - chip->cont_read.ongoing = true; - - rawnand_cap_cont_reads(chip); + first_page++; + + /* Derive the page where continuous read should stop (the last full page read) */ + last_page = page + ((col + readlen) / mtd->writesize) - 1; + + /* Configure and enable continuous read when suitable */ + if (first_page < last_page) { + chip->cont_read.first_page = first_page; + chip->cont_read.last_page = last_page; + chip->cont_read.ongoing = true; + /* May reset the ongoing flag */ + rawnand_cap_cont_reads(chip); + } } static void rawnand_cont_read_skip_first_page(struct nand_chip *chip, unsigned int page) -- 2.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 851EA76905 for ; Fri, 23 Feb 2024 11:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708689359; cv=none; b=cR7p1ysxkeqG+RBI6Ao+nH9yH35/T6BLPzb2iL+FotScV34ma2XWjuBgVFvIHggDh8fvxHa1GKKFsd1353hlBFhJKhXt/WgQaeJYOQcHD5v9vCLk3k7Xt0jLkBWcj5lSVsRTPQbxn6yruVHVq2gXBr8M3IDQiLKxUld7xpMw1YA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708689359; c=relaxed/simple; bh=ot7rfY//SXr54qNBjHWuWgs6Wlu/7UUOCtacgDS2B7Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c+Fsf9zUl0foqAyB0EcLzMV/HR5g4D9UpWzFuJ4GbHpMk3n+FIWO81yjP0OabVJGYtO9LM9cfpg0s3N1AwiX8ffJJDmp/tjsv2AU5u+adhuJ7BHQh5XDMS0+G974lQiEEZSH2tqID4uHmMGu/ZGfz5uf1Rc97qamU1divmiN9uo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=UdpfAvTs; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="UdpfAvTs" Received: by mail.gandi.net (Postfix) with ESMTPSA id B3968C000A; Fri, 23 Feb 2024 11:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708689350; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8yrP8J9ft/GYoNxsSdLSCccwDVuNUqlEsP+2f7HuanA=; b=UdpfAvTsQ8T+NJXqujvznRZyQgsNEoFKSKyQy+pI3cnAdr8N/l2Z9JYCBYm39cKnE1Qrby H3MnBlHoTQH7MOrLOHpUPgu9b25ZEQ1wlG0wIuDzU4wlJGmXX802I/WOeohNjAqiSD/EEm +4v+bnh7Pr0SLMToHDP1exPtd268x0AHM8il8NSfHqtjhAswh+MLSmgYStIEcuQQ/SPg5O QMbHSr1/CQQRem+yRLzzLHfhaIar/LNZYm3jgAjd2XjPD5Kf2+NU+FbVmdgg25eemxp1Xm rr7Mkk/w9qbHEntErpjhgRL4oD6PFtLxGMyczWC0u4cuQ16eaY2RkyS2gkbqhg== From: Miquel Raynal To: Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus , Pratyush Yadav , Michael Walle , Cc: Thomas Petazzoni , Julien Su , Jaime Liao , Jaime Liao , Alvin Zhou , Christophe Kerello , eagle.alexander923@gmail.com, mans@mansr.com, martin@geanix.com, =?UTF-8?q?Sean=20Nyekj=C3=A6r?= , Miquel Raynal , stable@vger.kernel.org Subject: [PATCH 1/3] mtd: rawnand: Fix and simplify again the continuous read derivations Date: Fri, 23 Feb 2024 12:55:43 +0100 Message-Id: <20240223115545.354541-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223115545.354541-1-miquel.raynal@bootlin.com> References: <20240223115545.354541-1-miquel.raynal@bootlin.com> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: miquel.raynal@bootlin.com We need to avoid the first page if we don't read it entirely. We need to avoid the last page if we don't read it entirely. While rather simple, this logic has been failed in the previous fix. This time I wrote about 30 unit tests locally to check each possible condition, hopefully I covered them all. Reported-by: Christophe Kerello Closes: https://lore.kernel.org/linux-mtd/20240221175327.42f7076d@xps-13/T/#m399bacb10db8f58f6b1f0149a1df867ec086bb0a Suggested-by: Christophe Kerello Fixes: 828f6df1bcba ("mtd: rawnand: Clarify conditions to enable continuous reads") Cc: stable@vger.kernel.org Signed-off-by: Miquel Raynal --- drivers/mtd/nand/raw/nand_base.c | 38 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 3b3ce2926f5d..bcfd99a1699f 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -3466,30 +3466,36 @@ static void rawnand_enable_cont_reads(struct nand_chip *chip, unsigned int page, u32 readlen, int col) { struct mtd_info *mtd = nand_to_mtd(chip); - unsigned int end_page, end_col; + unsigned int first_page, last_page; chip->cont_read.ongoing = false; if (!chip->controller->supported_op.cont_read) return; - end_page = DIV_ROUND_UP(col + readlen, mtd->writesize); - end_col = (col + readlen) % mtd->writesize; + /* + * Don't bother making any calculations if the length is too small. + * Side effect: avoids possible integer underflows below. + */ + if (readlen < (2 * mtd->writesize)) + return; + /* Derive the page where continuous read should start (the first full page read) */ + first_page = page; if (col) - page++; - - if (end_col && end_page) - end_page--; - - if (page + 1 > end_page) - return; - - chip->cont_read.first_page = page; - chip->cont_read.last_page = end_page; - chip->cont_read.ongoing = true; - - rawnand_cap_cont_reads(chip); + first_page++; + + /* Derive the page where continuous read should stop (the last full page read) */ + last_page = page + ((col + readlen) / mtd->writesize) - 1; + + /* Configure and enable continuous read when suitable */ + if (first_page < last_page) { + chip->cont_read.first_page = first_page; + chip->cont_read.last_page = last_page; + chip->cont_read.ongoing = true; + /* May reset the ongoing flag */ + rawnand_cap_cont_reads(chip); + } } static void rawnand_cont_read_skip_first_page(struct nand_chip *chip, unsigned int page) -- 2.34.1