linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: linux-mtd@lists.infradead.org
Cc: boris.brezillon@free-electrons.com, computersforpeace@gmail.com,
	dwmw2@infradead.org, Richard Weinberger <richard@nod.at>
Subject: [PATCH 2/5] mtd: nand: Propagate mtd_device_unregister() return value in tear down
Date: Tue,  5 Jul 2016 00:06:20 +0200	[thread overview]
Message-ID: <1467669983-12105-3-git-send-email-richard@nod.at> (raw)
In-Reply-To: <1467669983-12105-1-git-send-email-richard@nod.at>

Provide a __nand_release() function for drivers which can deal
with a failing nand release operation.
Most drivers should be safe since they rely on module refcounting.
To catch outliers implement a nand_release() with a WARN_ON().

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/nand/nand_base.c | 15 ++++++++++-----
 include/linux/mtd/nand.h     | 12 +++++++++++-
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 0b0dc29..5b9b65b 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -4601,19 +4601,22 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
 EXPORT_SYMBOL(nand_scan);
 
 /**
- * nand_release - [NAND Interface] Free resources held by the NAND device
+ * __nand_release - [NAND Interface] Free resources held by the NAND device
  * @mtd: MTD device structure
  */
-void nand_release(struct mtd_info *mtd)
+int __nand_release(struct mtd_info *mtd)
 {
+	int ret;
 	struct nand_chip *chip = mtd_to_nand(mtd);
 
+	ret = mtd_device_unregister(mtd);
+	if (ret)
+		return ret;
+
 	if (chip->ecc.mode == NAND_ECC_SOFT &&
 	    chip->ecc.algo == NAND_ECC_BCH)
 		nand_bch_free((struct nand_bch_control *)chip->ecc.priv);
 
-	mtd_device_unregister(mtd);
-
 	/* Free bad block table memory */
 	kfree(chip->bbt);
 	if (!(chip->options & NAND_OWN_BUFFERS))
@@ -4623,8 +4626,10 @@ void nand_release(struct mtd_info *mtd)
 	if (chip->badblock_pattern && chip->badblock_pattern->options
 			& NAND_BBT_DYNAMICSTRUCT)
 		kfree(chip->badblock_pattern);
+
+	return 0;
 }
-EXPORT_SYMBOL_GPL(nand_release);
+EXPORT_SYMBOL_GPL(__nand_release);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Steven J. Hill <sjhill@realitydiluted.com>");
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index fbe8e16..b3554ec 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -39,7 +39,7 @@ extern int nand_scan_ident(struct mtd_info *mtd, int max_chips,
 extern int nand_scan_tail(struct mtd_info *mtd);
 
 /* Free resources held by the NAND device */
-extern void nand_release(struct mtd_info *mtd);
+extern int __nand_release(struct mtd_info *mtd);
 
 /* Internal helper for board drivers which need to override command function */
 extern void nand_wait_ready(struct mtd_info *mtd);
@@ -1022,6 +1022,16 @@ static inline int jedec_feature(struct nand_chip *chip)
 		: 0;
 }
 
+static inline void nand_release(struct mtd_info *mtd)
+{
+	/*
+	 * If you face this warning your driver is doing something bad.
+	 * Don't issue nand_release() when your MTD is in use.
+	 * Use __nand_release() and handle the error correctly.
+	 */
+	WARN_ON(__nand_release(mtd) != 0);
+}
+
 /*
  * struct nand_sdr_timings - SDR NAND chip timings
  *
-- 
2.7.3

  parent reply	other threads:[~2016-07-04 22:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-04 22:06 MTD life cycle fixes Richard Weinberger
2016-07-04 22:06 ` [PATCH 1/5] mtdpart: Propagate _get/put_device() Richard Weinberger
2016-07-04 22:06 ` Richard Weinberger [this message]
2016-07-06 13:34   ` [PATCH 2/5] mtd: nand: Propagate mtd_device_unregister() return value in tear down Boris Brezillon
2016-07-07 18:29     ` Richard Weinberger
2016-07-07 18:58       ` Boris Brezillon
2016-07-04 22:06 ` [PATCH 3/5] mtd: Don't unconditionally unregister reboot notifier Richard Weinberger
2016-09-28 20:30   ` Brian Norris
2016-07-04 22:06 ` [PATCH 4/5] mtd: Don't unconditionally execute remove notifiers Richard Weinberger
2016-07-07 14:59   ` Boris Brezillon
2016-09-28 20:31   ` Brian Norris
2016-07-04 22:06 ` [PATCH 5/5] mtd: Don't print a scary message when trying to remove a busy MTD Richard Weinberger
2016-07-07 14:58   ` Boris Brezillon
2016-07-07 18:48     ` Richard Weinberger
2016-07-07 18:53       ` Boris Brezillon
2016-07-07 18:56         ` Richard Weinberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467669983-12105-3-git-send-email-richard@nod.at \
    --to=richard@nod.at \
    --cc=boris.brezillon@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).