Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4092581pxb; Tue, 2 Nov 2021 04:04:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoSPBs+9CCIcf7ulTie7Vbd+tkfi91x4mS77OLbz3Z6dm9vgGgdWwSG5EjDAoC7q9Cvh1q X-Received: by 2002:a17:906:b7d3:: with SMTP id fy19mr31549836ejb.121.1635851095360; Tue, 02 Nov 2021 04:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635851095; cv=none; d=google.com; s=arc-20160816; b=MBIpeIJ4Xf1z9apZDL+uQzIKaT+XCayY6ksMDxfoFcQmxnc0aA6BA4JjY0r7BNUZRa xZfquCDEV0tYVx/9IslSrBvfT8yi075jQ2yRxkfgN9MguyT2w7s+ZiToMif6BI4Dpd03 id9GoUN2a70fN+vprabQwI36yfCCWeSP8eEQjZ+Qz2Y+aBzKsaArGKhrXzGHKo7NOTMK onBPDUJL2/WhOa25sPeShPJx32OPTOORE7erUIy72rQrsPyxD6rZMv7v4yk4fDU/Omvh /yl0ouuJ6ng5qSj92b7RsGgzRwl4dGA5PZ1G+KFtkWp5G9plD3E49dMbIOBrrYPmwbsD UmwA== 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=LP5J2wEALZEk6MRbz9ZlAOMAbUgyatCxMAZZ8eSNC1c=; b=NJCzk9y6loxSzGQkXR/vyEsl9CPcLZ5amSSl+vZf8qxccmTiSfFwQzOrs7CoUIHono JAdq2+CzTadjpQFC/VYo0eHzRlvz9+4RaNfPlIQkFEJIIQ4BA2CAm8YBzbJMfSgB23Ph +ekgj8d2wfv+fwerZYaeoULHvf2azoZrRJu2Qs25JGgwPyLhOLGBM+ktEqF+ZSnUnLBD NGvfGcrcoUJUJdaxgEQehgQCMA68isEDKVgmdZoSW0wgzf1fBBGcEinyFwASHpYPmhkI 10LtBI7NHdwABrYFRkIfp8lt82T8R3frWLOtHv7FFVlWr6LdfP2OR7lSreds0PsOMPq9 ZFbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=eIqmfsTZ; 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 jr11si25955269ejb.269.2021.11.02.04.04.31; Tue, 02 Nov 2021 04:04:55 -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=eIqmfsTZ; 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 S230326AbhKBLFD (ORCPT + 99 others); Tue, 2 Nov 2021 07:05:03 -0400 Received: from first.geanix.com ([116.203.34.67]:37540 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230109AbhKBLEu (ORCPT ); Tue, 2 Nov 2021 07:04:50 -0400 Received: from zen.. (unknown [185.17.218.86]) by first.geanix.com (Postfix) with ESMTPSA id 3B62ED7478; Tue, 2 Nov 2021 11:02:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1635850930; bh=u1QiAAw6X6LgXTU44geERokABB9hy1J5K+hpPufCwYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eIqmfsTZrIQXJuLn/Z6o8Kwmd/jfmlhJSaVQMNc4HaoDj7YS8mboFjxOEhj3Ux7XK RZvFpYe21bAHRGldmTFcnzF3cUGcm5EjEK3jWncNY+pgrSxUhMG/lUXrE6ByYviYP8 QLcpqcYJQooZDXvp4aF12CjbuaaPXuk1bm1C7EN8t64D9mFK5rOhmHXzvu9LT4/YOK uXSWZx6T4qJfTN/lMuiQHZY6OXcSea7aUl+tApxyJYVDxbVzlKMFzehda64ia2OkpW amHSJjhK5//21daR36Y9gLWPE5QckisD1IDREQfY8i4jSA19et5kYYQS8uiJ6pqXKT qW6QsuG4WoyoQ== 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 v5 1/4] mtd: rawnand: nand_bbt: hide suspend/resume hooks while scanning bbt Date: Tue, 2 Nov 2021 12:02:01 +0100 Message-Id: <20211102110204.3334609-2-sean@geanix.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211102110204.3334609-1-sean@geanix.com> References: <20211102110204.3334609-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. 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