All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtdcore: Infrastructure for the device release API
@ 2017-05-18  9:23 Martin Habets
  2017-05-27  0:13 ` Brian Norris
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Habets @ 2017-05-18  9:23 UTC (permalink / raw)
  To: linux-mtd

This API adds a cleanup callback for the user of an MTD device.
Normally they will have allocated the mtd_info structure, and using
this callback they can free that memory when the last reference is
dropped.

CONFIG_DEBUG_KOBJECT_RELEASE can be used to detect users that free
the memory too early.

Signed-off-by: Martin Habets <mhabets@solarflare.com>
---
 drivers/mtd/mtdcore.c   |    7 ++++---
 include/linux/mtd/mtd.h |    1 +
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 1517da3ddd7d..c36752206edc 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -96,9 +96,7 @@ static LIST_HEAD(mtd_notifiers);

 #define MTD_DEVT(index) MKDEV(MTD_CHAR_MAJOR, (index)*2)

-/* REVISIT once MTD uses the driver model better, whoever allocates
- * the mtd_info will probably want to use the release() hook...
- */
+/* Whoever allocates the mtd_info should populate the release() hook. */
 static void mtd_release(struct device *dev)
 {
        struct mtd_info *mtd = dev_get_drvdata(dev);
@@ -106,6 +104,9 @@ static void mtd_release(struct device *dev)

        /* remove /dev/mtdXro node */
        device_destroy(&mtd_class, index + 1);
+
+       if (mtd->_release)
+               (mtd->_release)(mtd);
 }

 static ssize_t mtd_type_show(struct device *dev,
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 79b176eca04a..e61c30ac8fb6 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -327,6 +327,7 @@ struct mtd_info {
        int (*_suspend) (struct mtd_info *mtd);
        void (*_resume) (struct mtd_info *mtd);
        void (*_reboot) (struct mtd_info *mtd);
+       void (*_release) (struct mtd_info *mtd);
        /*
         * If the driver is something smart, like UBI, it may need to maintain
         * its own reference counting. The below functions are only for driver.

The information contained in this message is confidential and is intended for the addressee(s) only. If you have received this message in error, please notify the sender immediately and delete the message. Unless you are an addressee (or authorized to receive for an addressee), you may not use, copy or disclose to anyone this message or any information contained in this message. The unauthorized use, disclosure, copying or alteration of this message is strictly prohibited.

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-07-18 15:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-18  9:23 [PATCH] mtdcore: Infrastructure for the device release API Martin Habets
2017-05-27  0:13 ` Brian Norris
2017-05-31 16:15   ` Martin Habets
2017-06-22 13:54     ` Martin Habets
2017-07-08  1:47       ` Brian Norris
2017-07-18 15:51         ` Martin Habets

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.