Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1050623pxb; Tue, 26 Oct 2021 01:49:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQ6OYdNCtqmlMgI5xxewgHyiBCZfeCUhgv32TYRfRvQg1CVB/kX+RuoN2qaVVbfM4MiD2j X-Received: by 2002:a17:907:98e1:: with SMTP id ke1mr25283386ejc.347.1635238177057; Tue, 26 Oct 2021 01:49:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635238177; cv=none; d=google.com; s=arc-20160816; b=gbOy6By5/MYRCtN1fs76DKEdXNomc2Q7JUW2IfqazwTbqIYUxwVwL2d9/0QDCZ0mrd T7R2KYNsyyiXd3gv0ZfmYsK98fSurK1o/lFRM/cawTnpVOzqHiWIBj/OL0SHQJ0qcE0k 8x36OuYVE/VYeq1luLjcpZ2BnXadBaZJnYbD9DwpjagJEW1oDawQEunnRG5WzINbRwxP GJ3zgLaqso2EJ0smWXl5wEf57kXysD6reUevVW3gWmJByQR/HSflijRs64cCFUb5LwaY 5vCYN2/HaraWDCuB0G38tYogViKRjQoeDXprrqwAPP2S6xgjHwcQV/iK2Ao4ILL24+tl gtQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tlIgGm0EZnSADCdihr+sFkzoLGtiZO8llmKWNfmkhyA=; b=QnyaJbVudteeDc+ZWs2E40Cs0e8SzBVhUnaaT16A327nomcjMTSwkguEtLH4SoJ3T8 zMnSAn7NAiQUjUWIdBtiVKfglPDWtyuJr0VScibryTV6s+ZbWgQhJY+jMqZamIakCOfN 84FD9brJjJHlhuOZaku/VWO4Duq5AKqQ0uUHi8BOQhdx2nfKPWD7sH8/XqLgUHNaPiR5 Zc339MN0bLG/NThKvJ0xNIEXHJkU8gbYs1D7JQxdFdEU0byBvE/lKHWRPYm+DoHMrgZQ 5HBFqjsznu3lfIInbIjgfrc+LN0ZKEZPdfp6WErlR23MRmdUlocrFPvrl76ZALljNZSs Sd3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=mb4c8iQm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p18si26915677ejr.517.2021.10.26.01.49.13; Tue, 26 Oct 2021 01:49:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=mb4c8iQm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235139AbhJZF61 (ORCPT + 99 others); Tue, 26 Oct 2021 01:58:27 -0400 Received: from first.geanix.com ([116.203.34.67]:37412 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233736AbhJZF6Z (ORCPT ); Tue, 26 Oct 2021 01:58:25 -0400 Received: from zen.. (unknown [185.17.218.86]) by first.geanix.com (Postfix) with ESMTPSA id 4FDDED6F7D; Tue, 26 Oct 2021 05:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1635227760; bh=pSFGkotVeNb5qsNJzmaYe1nuIoE4MQOk1MI2epzMezw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mb4c8iQmnzJxx1dB8NEUWqgGmzC7/ebnkAlILjN+AKwCaCPhEUwOJaqLEcie/Myfr wx6MzX1keEO1GrxO7anneoiClnG2OOLaaUblcnSC4pB9r80TlF45IObvhThZWbeBYy s+OGmKSeBoBj/WOx6zHGfezRR48ZE/xKu6xSvUp1sDFWalZVQ/XsnWSS4HJAqXcVY/ gKyA8fZCESCdAzHFYU/PXm5dHffp504H7FQymVHOv3mPlGhILWPnuWpqTbU5EdXP7C CE+ZQ93RqaegsqBaV7BvXCrI2GL7BIQGMeoxjkh3u7dCx+1lfazjKNO+Mj72uzk3rm z53FfnOAcDnhg== From: Sean Nyekjaer To: Boris Brezillon Cc: Sean Nyekjaer , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Boris Brezillon , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/4] mtd: rawnand: nand_bbt: hide suspend/resume hooks while scanning bbt Date: Tue, 26 Oct 2021 07:55:48 +0200 Message-Id: <20211026055551.3053598-2-sean@geanix.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211026055551.3053598-1-sean@geanix.com> References: <20211026055551.3053598-1-sean@geanix.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=4.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_BLOCKED autolearn=disabled version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 13e2a5895688 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Boris Brezillon The BBT scan logic use the MTD helpers before the MTD layer had a chance to initialize the device, and that leads to issues when accessing the uninitialized suspend lock. Let's temporarily set the suspend/resume hooks to NULL to skip the lock acquire/release step. Fixes: 013e6292aaf5 ("mtd: rawnand: Simplify the locking") Tested-by: Sean Nyekjaer Signed-off-by: Boris Brezillon Signed-off-by: Sean Nyekjaer --- drivers/mtd/nand/raw/nand_bbt.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/nand_bbt.c b/drivers/mtd/nand/raw/nand_bbt.c index b7ad030225f8..93d385703469 100644 --- a/drivers/mtd/nand/raw/nand_bbt.c +++ b/drivers/mtd/nand/raw/nand_bbt.c @@ -1397,8 +1397,28 @@ static int nand_create_badblock_pattern(struct nand_chip *this) */ int nand_create_bbt(struct nand_chip *this) { + struct mtd_info *mtd = nand_to_mtd(this); + int (*suspend) (struct mtd_info *) = mtd->_suspend; + void (*resume) (struct mtd_info *) = mtd->_resume; int ret; + /* + * The BBT scan logic use the MTD helpers before the MTD layer had a + * chance to initialize the device, and that leads to issues when + * accessing the uninitialized suspend lock. Let's temporarily set the + * suspend/resume hooks to NULL to skip the lock acquire/release step. + * + * FIXME: This is an ugly hack, so please don't copy this pattern to + * other MTD implementations. The proper fix would be to implement a + * generic BBT scan logic at the NAND level that's not using any of the + * MTD helpers to access pages. We also might consider doing a two + * step initialization at the MTD level (mtd_device_init() + + * mtd_device_register()) so some of the fields are initialized + * early. + */ + mtd->_suspend = NULL; + mtd->_resume = NULL; + /* Is a flash based bad block table requested? */ if (this->bbt_options & NAND_BBT_USE_FLASH) { /* Use the default pattern descriptors */ @@ -1422,7 +1442,13 @@ int nand_create_bbt(struct nand_chip *this) return ret; } - return nand_scan_bbt(this, this->badblock_pattern); + ret = nand_scan_bbt(this, this->badblock_pattern); + + /* Restore the suspend/resume hooks. */ + mtd->_suspend = suspend; + mtd->_resume = resume; + + return ret; } EXPORT_SYMBOL(nand_create_bbt); -- 2.33.0