Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C336439A04D; Mon, 23 Mar 2026 16:27:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774283226; cv=none; b=oKhD/Typ2zdrT47cmviimTZk1QgATif2QGE7uW6LWc/1bMcEM3trELw8P18iA4/ofXc2JozL6qvlx6aRUNl/lznlE9RV4O+uBPb9BpDb3Ar4wP+hCCxNArW6naU8m0qJiOrO7Et1G86e8vcyPCy1F4eOTWKRBmfmfaaTuq5uoZk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774283226; c=relaxed/simple; bh=3jJwKeTurFSgkMdRBsZSzhAzG/SYon0M5kVXRQCLw4M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PdoRIKG4uZedPiL3j2efF40j6Pdl2YCofRjyNarOvSHjC4o7gFCtDwCMFpqEBjiAvKIAy9QLVut3Jid+/Q++ltd16S17gzb17D54S3Nc+1e+ALsNNneoF+K5/s95+PzTiXmtMqg3WLIbWuOoKFW6vGaBib6VYi0NBvuUscJAuvs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=irJXeRiQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="irJXeRiQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 519B3C4CEF7; Mon, 23 Mar 2026 16:27:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774283226; bh=3jJwKeTurFSgkMdRBsZSzhAzG/SYon0M5kVXRQCLw4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=irJXeRiQUNkltRv2N4cOgpKdFEYgryO0xjzFvjno24p3YQSv41ODJjheic/+1MsYv 8AHC4bihAsET2MiXZ6973EH4dzyepM8U5qgB9T+4vBwCaiDo6XtYh0pg6ah5JIY20k AVSAAAn5WBpjGhxglmPss+pfMEZJHZwfz752dGgM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kamal Dasu , William Zhang , Miquel Raynal , Sasha Levin Subject: [PATCH 6.1 448/481] mtd: rawnand: serialize lock/unlock against other NAND operations Date: Mon, 23 Mar 2026 14:47:10 +0100 Message-ID: <20260323134536.131866622@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134525.256603107@linuxfoundation.org> References: <20260323134525.256603107@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kamal Dasu [ Upstream commit bab2bc6e850a697a23b9e5f0e21bb8c187615e95 ] nand_lock() and nand_unlock() call into chip->ops.lock_area/unlock_area without holding the NAND device lock. On controllers that implement SET_FEATURES via multiple low-level PIO commands, these can race with concurrent UBI/UBIFS background erase/write operations that hold the device lock, resulting in cmd_pending conflicts on the NAND controller. Add nand_get_device()/nand_release_device() around the lock/unlock operations to serialize them against all other NAND controller access. Fixes: 92270086b7e5 ("mtd: rawnand: Add support for manufacturer specific lock/unlock operation") Signed-off-by: Kamal Dasu Reviewed-by: William Zhang Signed-off-by: Miquel Raynal Signed-off-by: Sasha Levin --- drivers/mtd/nand/raw/nand_base.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index ea7e37a6e4c07..a545df56a30e7 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4692,11 +4692,16 @@ static void nand_shutdown(struct mtd_info *mtd) static int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { struct nand_chip *chip = mtd_to_nand(mtd); + int ret; if (!chip->ops.lock_area) return -ENOTSUPP; - return chip->ops.lock_area(chip, ofs, len); + nand_get_device(chip); + ret = chip->ops.lock_area(chip, ofs, len); + nand_release_device(chip); + + return ret; } /** @@ -4708,11 +4713,16 @@ static int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) static int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { struct nand_chip *chip = mtd_to_nand(mtd); + int ret; if (!chip->ops.unlock_area) return -ENOTSUPP; - return chip->ops.unlock_area(chip, ofs, len); + nand_get_device(chip); + ret = chip->ops.unlock_area(chip, ofs, len); + nand_release_device(chip); + + return ret; } /* Set default functions */ -- 2.51.0