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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 943FBC433F5 for ; Mon, 25 Oct 2021 09:28:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D3F560F4F for ; Mon, 25 Oct 2021 09:28:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232546AbhJYJaX (ORCPT ); Mon, 25 Oct 2021 05:30:23 -0400 Received: from first.geanix.com ([116.203.34.67]:37400 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232511AbhJYJaV (ORCPT ); Mon, 25 Oct 2021 05:30:21 -0400 Received: from zen.. (unknown [185.17.218.86]) by first.geanix.com (Postfix) with ESMTPSA id 6867CD58DA; Mon, 25 Oct 2021 09:27:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1635154077; bh=pSFGkotVeNb5qsNJzmaYe1nuIoE4MQOk1MI2epzMezw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Mv4+ogc3dVKuTtnnI+hrfyPa/g719p4wz9cUz5IwUxC5FGXroMrtkFp+kxF4olK88 D4RWuXCnYrEgJvuSB1+FLycsvLlKhT9WtYMIDZhkvMBkfw4rol9BOFo5yJouwpAmS+ jnZ86b1VfLSifGyjKcQGRxk9YsZK8DF2kxpXfwQLjXLnT98tnQDe3xdXF8X/1csN2I 5tZpXl3DPjrfTKPWAWaxcwEIDzhpgXR3/+JBY1ybpNw/f5iYWzZ7aqEz04GxrZlYrD 1rx/aajPF5YTG+qLbCMMTQxuYxuCyq75bz2ZQdp2Vpz5IvW6S9cVnJs4LL96MOLcbx yiVU+3Qhr7qmA== 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 v3 1/4] mtd: rawnand: nand_bbt: hide suspend/resume hooks while scanning bbt Date: Mon, 25 Oct 2021 11:27:49 +0200 Message-Id: <20211025092752.2824678-2-sean@geanix.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211025092752.2824678-1-sean@geanix.com> References: <20211025092752.2824678-1-sean@geanix.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2757EC433FE for ; Mon, 25 Oct 2021 09:29:04 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id DFEEF60EBD for ; Mon, 25 Oct 2021 09:29:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DFEEF60EBD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=geanix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=hyQGe+PiSp3t0YnEHHEmof9Ep587Qlhu+Lh/cML2BN4=; b=Q1p83nLCOGFLDf IFCmFOgiWUZXfK/3THwmxgUHE36N4zjwa9DL/3OeXzcP+IJtFhh+P9qUpwN1/B+JtOZXaItfrqVrM k9NtzPyTLeySv//Y/wuwcaZjFkHD7Xb04AoyrWYLrzRfOSN4ZxrziSMFDN/KK1IeubNvRTa5Ar9Qo IkAHMY6ZdaBbhVNKrb9+bFK/WsGQLQgB6RS8w+kVWO4TANfL4mvF0lgp5wlBLS1W5+keS6tt57U0p apUL4uJgnbdbxVd5MQGXAhANFurKgU80CRcBsTf8FjWVzPRMAodCjY2gMlZdIedKa6GQw7C5G9BCC MU7q//ZYPS5YVjL3AH6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mewH5-00FvXk-1g; Mon, 25 Oct 2021 09:28:11 +0000 Received: from first.geanix.com ([116.203.34.67]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mewH1-00FvUO-Pa for linux-mtd@lists.infradead.org; Mon, 25 Oct 2021 09:28:09 +0000 Received: from zen.. (unknown [185.17.218.86]) by first.geanix.com (Postfix) with ESMTPSA id 6867CD58DA; Mon, 25 Oct 2021 09:27:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1635154077; bh=pSFGkotVeNb5qsNJzmaYe1nuIoE4MQOk1MI2epzMezw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Mv4+ogc3dVKuTtnnI+hrfyPa/g719p4wz9cUz5IwUxC5FGXroMrtkFp+kxF4olK88 D4RWuXCnYrEgJvuSB1+FLycsvLlKhT9WtYMIDZhkvMBkfw4rol9BOFo5yJouwpAmS+ jnZ86b1VfLSifGyjKcQGRxk9YsZK8DF2kxpXfwQLjXLnT98tnQDe3xdXF8X/1csN2I 5tZpXl3DPjrfTKPWAWaxcwEIDzhpgXR3/+JBY1ybpNw/f5iYWzZ7aqEz04GxrZlYrD 1rx/aajPF5YTG+qLbCMMTQxuYxuCyq75bz2ZQdp2Vpz5IvW6S9cVnJs4LL96MOLcbx yiVU+3Qhr7qmA== 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 v3 1/4] mtd: rawnand: nand_bbt: hide suspend/resume hooks while scanning bbt Date: Mon, 25 Oct 2021 11:27:49 +0200 Message-Id: <20211025092752.2824678-2-sean@geanix.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211025092752.2824678-1-sean@geanix.com> References: <20211025092752.2824678-1-sean@geanix.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211025_022808_062094_367274DA X-CRM114-Status: GOOD ( 16.57 ) 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 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 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/