diff mbox series

[11/14] mtd: rawnand: meson: Don't skip cleanup after mtd_device_unregister() failed

Message ID 20220603210758.148493-12-u.kleine-koenig@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series mtd: Fix platform remove callbacks to always return 0 | expand

Commit Message

Uwe Kleine-König June 3, 2022, 9:07 p.m. UTC
If mtd_device_unregister() fails (which it doesn't when used correctly),
the resources bound by the nand chip should be freed anyhow as returning
an error value doesn't prevent the device getting unbound.

Instead use WARN_ON on the return value similar to how other drivers do
it. Then meson_nfc_nand_chip_cleanup() returns 0 unconditionally and can
be changed to return void which allows further simplification in the
remove callback.

This is a preparation for making platform remove callbacks return void.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/mtd/nand/raw/meson_nand.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

Comments

Miquel Raynal June 9, 2022, 1:09 p.m. UTC | #1
On Fri, 2022-06-03 at 21:07:55 UTC, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= wrote:
> If mtd_device_unregister() fails (which it doesn't when used correctly),
> the resources bound by the nand chip should be freed anyhow as returning
> an error value doesn't prevent the device getting unbound.
> 
> Instead use WARN_ON on the return value similar to how other drivers do
> it. Then meson_nfc_nand_chip_cleanup() returns 0 unconditionally and can
> be changed to return void which allows further simplification in the
> remove callback.
> 
> This is a preparation for making platform remove callbacks return void.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel
diff mbox series

Patch

diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
index ac3be92872d0..748e115b0bb7 100644
--- a/drivers/mtd/nand/raw/meson_nand.c
+++ b/drivers/mtd/nand/raw/meson_nand.c
@@ -1293,26 +1293,21 @@  meson_nfc_nand_chip_init(struct device *dev,
 	return 0;
 }
 
-static int meson_nfc_nand_chip_cleanup(struct meson_nfc *nfc)
+static void meson_nfc_nand_chip_cleanup(struct meson_nfc *nfc)
 {
 	struct meson_nfc_nand_chip *meson_chip;
 	struct mtd_info *mtd;
-	int ret;
 
 	while (!list_empty(&nfc->chips)) {
 		meson_chip = list_first_entry(&nfc->chips,
 					      struct meson_nfc_nand_chip, node);
 		mtd = nand_to_mtd(&meson_chip->nand);
-		ret = mtd_device_unregister(mtd);
-		if (ret)
-			return ret;
+		WARN_ON(mtd_device_unregister(mtd));
 
 		meson_nfc_free_buffer(&meson_chip->nand);
 		nand_cleanup(&meson_chip->nand);
 		list_del(&meson_chip->node);
 	}
-
-	return 0;
 }
 
 static int meson_nfc_nand_chips_init(struct device *dev,
@@ -1445,11 +1440,8 @@  static int meson_nfc_probe(struct platform_device *pdev)
 static int meson_nfc_remove(struct platform_device *pdev)
 {
 	struct meson_nfc *nfc = platform_get_drvdata(pdev);
-	int ret;
 
-	ret = meson_nfc_nand_chip_cleanup(nfc);
-	if (ret)
-		return ret;
+	meson_nfc_nand_chip_cleanup(nfc);
 
 	meson_nfc_disable_clk(nfc);