Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1281020pxb; Wed, 20 Oct 2021 01:47:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLPNGvg2Yd21jeNpMHKLHnfUhdE0AI2rcrlfXQRsDQR2M3XbSVEM/yPGMO3W7Wg+5d6pSx X-Received: by 2002:a17:90a:353:: with SMTP id 19mr5876302pjf.83.1634719645592; Wed, 20 Oct 2021 01:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634719645; cv=none; d=google.com; s=arc-20160816; b=ys8XhrfJRBc22Uk0Ci8fNESicUJ6dgSQqXxeSRroJNlwuHFW1YS0fyda+okHv8haZo S1s7qZ6wSZaBbodY/BMLtjjcTTPPZnqooQY1T6qjUNWosaWy884X/HNH0XqG3kYyxaNf rpIIq4fOWZRtTLV0pyQ4hfSxpEeRbUP0Uq4rrP/tm+81CcK/UaiKYw35umJXYIJScmue GJLfHQm3NRu5SLhoNIsJ7639WeEkuBtfgSgZf1R/aaTHy+szrUJg49ctQygvOQIW6FXK dYNexWwL0H0yzFMMFksmpYixLve9CI8GqzIcbqliJ5idVdmJ5hiJJDzLSzoTlSDN9h2l YFlA== 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=XWLGkpoEDfvVG04zQUT7vEsYTQOT3/82l2x4v22z1KI=; b=Q392nRnfBp1S1d1Hhwkc7/rCKYgP+N5XbQw8yULgEzq4WsjSCpzjoePNY0SxnqVOhe mZXbgiHU3x2cZcNsIAVC+CzGulf2eZMQHWoWMmlVK2MoMQvQqmIiP/rdv5Cf7/ovIjb1 C0fd1dE3166z91QKRKmOWyWd6qIUXJ9W0P7S43An4zacxrKzeL7+Ila+SKI4vJUJqN0I SVkBBoOMuPSjJYodsluG6A7+Qog+GOc10l1NzO//3BwVDF1x5ozC+PcA+w92OgTZvtJJ MaT247dA0qdtlDquU3OZ1N7Txenv6DvWj4CJol6AkGXIDvmHjI9lG22zqb1JVqxeNl52 703A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b="I/WYAae5"; 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 o37si2268136pgm.128.2021.10.20.01.47.12; Wed, 20 Oct 2021 01:47:25 -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="I/WYAae5"; 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 S230049AbhJTIsA (ORCPT + 99 others); Wed, 20 Oct 2021 04:48:00 -0400 Received: from first.geanix.com ([116.203.34.67]:37390 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbhJTIr6 (ORCPT ); Wed, 20 Oct 2021 04:47:58 -0400 Received: from zen.. (unknown [185.17.218.86]) by first.geanix.com (Postfix) with ESMTPSA id 3F48DC7EC5; Wed, 20 Oct 2021 08:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1634719542; bh=cGWPCXk1Wny7/Ezf/s8a4wUpVvPCYTV59Za745o2o5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=I/WYAae5oFLK/RoEZ3OhVu2pSyxlE4Sy0EjJjRdyew0DdfzUjfCBNbiJOC967UyT2 2zpgQSErPwzA2q+kAB8qAsOzonl/OxQEHOq2GlxP9SWVQXPUspc+cfz52DlU28IhMi XYRkva3IgMjQl67OqzymfYez1K8cq1KSYygb0JkgJ9Wv7MvS2FYzVZ45cYBVlelWzj rmb10SF0ImS6EpWn0lBYO40gBEeGYnS2zxRNqnp8PPdvy7si3GaXQNYTRjB5RNk2ZQ YscZh7kfrCI5K7pbrnZXPW7JlheF2YMb+RuK34jbrVRl5rDW/vAjQQHIwgc9me93nt VnfY3/UogY5ig== 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 v2 3/4] mtd: rawnand: remove suspended check Date: Wed, 20 Oct 2021 10:45:33 +0200 Message-Id: <20211020084534.2472305-4-sean@geanix.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211020084534.2472305-1-sean@geanix.com> References: <20211020084534.2472305-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 Access is protected in upper MTD layer when MTD devices are suspended. Fixes: 013e6292aaf5 ("mtd: rawnand: Simplify the locking") Reviewed-by: Miquel Raynal Signed-off-by: Sean Nyekjaer --- drivers/mtd/nand/raw/nand_base.c | 52 ++++++++------------------------ include/linux/mtd/rawnand.h | 5 +-- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 3d6c6e880520..aa2874ae3c4a 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -332,19 +332,11 @@ static int nand_isbad_bbm(struct nand_chip *chip, loff_t ofs) * @chip: NAND chip structure * * Lock the device and its controller for exclusive access - * - * Return: -EBUSY if the chip has been suspended, 0 otherwise */ -static int nand_get_device(struct nand_chip *chip) +static void nand_get_device(struct nand_chip *chip) { mutex_lock(&chip->lock); - if (chip->suspended) { - mutex_unlock(&chip->lock); - return -EBUSY; - } mutex_lock(&chip->controller->lock); - - return 0; } /** @@ -573,10 +565,7 @@ static int nand_block_markbad_lowlevel(struct nand_chip *chip, loff_t ofs) nand_erase_nand(chip, &einfo, 0); /* Write bad block marker to OOB */ - ret = nand_get_device(chip); - if (ret) - return ret; - + nand_get_device(chip); ret = nand_markbad_bbm(chip, ofs); nand_release_device(chip); } @@ -3756,9 +3745,7 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from, ops->mode != MTD_OPS_RAW) return -ENOTSUPP; - ret = nand_get_device(chip); - if (ret) - return ret; + nand_get_device(chip); if (!ops->datbuf) ret = nand_do_read_oob(chip, from, ops); @@ -4345,13 +4332,11 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops) { struct nand_chip *chip = mtd_to_nand(mtd); - int ret; + int ret = 0; ops->retlen = 0; - ret = nand_get_device(chip); - if (ret) - return ret; + nand_get_device(chip); switch (ops->mode) { case MTD_OPS_PLACE_OOB: @@ -4410,10 +4395,8 @@ int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr, if (nand_region_is_secured(chip, instr->addr, instr->len)) return -EIO; - /* Grab the lock and see if the device is available */ - ret = nand_get_device(chip); - if (ret) - return ret; + /* Grab the lock */ + nand_get_device(chip); /* Shift to get first page */ page = (int)(instr->addr >> chip->page_shift); @@ -4499,8 +4482,8 @@ static void nand_sync(struct mtd_info *mtd) pr_debug("%s: called\n", __func__); - /* Grab the lock and see if the device is available */ - WARN_ON(nand_get_device(chip)); + /* Grab the lock */ + nand_get_device(chip); /* Release it and go back */ nand_release_device(chip); } @@ -4517,9 +4500,7 @@ static int nand_block_isbad(struct mtd_info *mtd, loff_t offs) int ret; /* Select the NAND device */ - ret = nand_get_device(chip); - if (ret) - return ret; + nand_get_device(chip); nand_select_target(chip, chipnr); @@ -4565,8 +4546,6 @@ static int nand_suspend(struct mtd_info *mtd) mutex_lock(&chip->lock); if (chip->ops.suspend) ret = chip->ops.suspend(chip); - if (!ret) - chip->suspended = 1; mutex_unlock(&chip->lock); return ret; @@ -4580,15 +4559,10 @@ static void nand_resume(struct mtd_info *mtd) { struct nand_chip *chip = mtd_to_nand(mtd); + mutex_lock(&chip->lock); - if (chip->suspended) { - if (chip->ops.resume) - chip->ops.resume(chip); - chip->suspended = 0; - } else { - pr_err("%s called for a chip which is not in suspended state\n", - __func__); - } + if (chip->ops.resume) + chip->ops.resume(chip); mutex_unlock(&chip->lock); } diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index b2f9dd3cbd69..1198a6548912 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1237,9 +1237,7 @@ struct nand_secure_region { * @pagecache.page: Page number currently in the cache. -1 means no page is * currently cached * @buf_align: Minimum buffer alignment required by a platform - * @lock: Lock protecting the suspended field. Also used to serialize accesses - * to the NAND device - * @suspended: Set to 1 when the device is suspended, 0 when it's not + * @lock: Lock to serialize accesses to the NAND device * @cur_cs: Currently selected target. -1 means no target selected, otherwise we * should always have cur_cs >= 0 && cur_cs < nanddev_ntargets(). * NAND Controller drivers should not modify this value, but they're @@ -1293,7 +1291,6 @@ struct nand_chip { /* Internals */ struct mutex lock; - unsigned int suspended : 1; int cur_cs; int read_retries; struct nand_secure_region *secure_regions; -- 2.33.0