mtd/drivers/mtd mtd_blkdevs.c,1.2,1.3
David Woodhouse
dwmw2 at infradead.org
Sun May 18 10:40:57 EDT 2003
Update of /home/cvs/mtd/drivers/mtd
In directory phoenix.infradead.org:/tmp/cvs-serv30318
Modified Files:
mtd_blkdevs.c
Log Message:
notifiers
Index: mtd_blkdevs.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/mtd_blkdevs.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- mtd_blkdevs.c 18 May 2003 14:29:17 -0000 1.2
+++ mtd_blkdevs.c 18 May 2003 14:40:54 -0000 1.3
@@ -332,7 +332,6 @@
.ioctl = blktrans_ioctl,
};
-
int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
{
struct mtd_blktrans_ops *tr = new->tr;
@@ -414,11 +413,50 @@
return 0;
}
-
+
+void blktrans_notify_add(struct mtd_info *mtd)
+{
+ struct list_head *this, *this2, *next;
+
+ list_for_each(this, &blktrans_majors) {
+ struct mtd_blktrans_ops *tr = list_entry(this, struct mtd_blktrans_ops, list);
+
+ list_for_each_safe(this2, next, &tr->devs) {
+ struct mtd_blktrans_dev *dev = list_entry(this, struct mtd_blktrans_dev, list);
+
+ if (dev->mtd == mtd)
+ tr->remove_dev(dev);
+ }
+ }
+}
+
+void blktrans_notify_remove(struct mtd_info *mtd)
+{
+ struct list_head *this;
+
+ list_for_each(this, &blktrans_majors) {
+ struct mtd_blktrans_ops *tr = list_entry(this, struct mtd_blktrans_ops, list);
+
+ tr->add_mtd(tr, mtd);
+ }
+
+}
+
+static struct mtd_notifier blktrans_notifier = {
+ .add = blktrans_notify_add,
+ .remove = blktrans_notify_remove,
+};
+
int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
{
int ret, i;
+ /* Register the notifier if/when the first device type is
+ registered, to prevent the link/init ordering from fucking
+ us over. */
+ if (!blktrans_notifier.list.next)
+ register_mtd_user(&blktrans_notifier);
+
tr->blkcore_priv = kmalloc(sizeof(*tr->blkcore_priv), GFP_KERNEL);
if (!tr->blkcore_priv)
return -ENOMEM;
@@ -494,6 +532,16 @@
BUG();
return 0;
}
+
+static void __exit mtd_blktrans_exit(void)
+{
+ /* No race here -- if someone's currently in register_mtd_blktrans
+ we're screwed anyway. */
+ if (blktrans_notifier.list.next)
+ unregister_mtd_user(&blktrans_notifier);
+}
+
+module_exit(mtd_blktrans_exit);
MODULE_AUTHOR("David Woodhouse <dwmw2 at infradead.org>");
MODULE_LICENSE("GPL");
More information about the linux-mtd-cvs
mailing list