[PATCH 07/08] dm: proper module reference counting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Module reference counting appropriately occurs when the block device is
 opened, but dm devices exist outside of the device actually being opened.

 Currently, in certain situations, unloading the dm-mod module will result
 in an oops. This patch claims a reference to the module when a device
 is created, and drops it when the device is freed.

 This is one possible implementation. Another could be to do an internal
 "dmsetup remove_all" when the module is unloaded. Comments welcome.

Signed-off-by: Jeff Mahoney <[email protected]>
--
 drivers/md/dm.c |    6 ++++++
 1 files changed, 6 insertions(+)

diff -ruNpX ../dontdiff linux-2.6.16-staging1/drivers/md/dm.c linux-2.6.16-staging2/drivers/md/dm.c
--- linux-2.6.16-staging1/drivers/md/dm.c	2006-04-13 16:18:23.000000000 -0400
+++ linux-2.6.16-staging2/drivers/md/dm.c	2006-04-13 16:18:23.000000000 -0400
@@ -796,6 +796,9 @@ static struct mapped_device *alloc_dev(u
 		return NULL;
 	}
 
+	if (!try_module_get(THIS_MODULE))
+		goto bad0;
+
 	/* get a minor number for the dev */
 	r = persistent ? specific_minor(md, minor) : next_free_minor(md, &minor);
 	if (r < 0)
@@ -862,6 +865,8 @@ static struct mapped_device *alloc_dev(u
 	blk_put_queue(md->queue);
 	free_minor(minor);
  bad1:
+	module_put(THIS_MODULE);
+ bad0:
 	kfree(md);
 	return NULL;
 }
@@ -885,6 +890,7 @@ static void free_dev(struct mapped_devic
 
 	put_disk(md->disk);
 	blk_put_queue(md->queue);
+	module_put(THIS_MODULE);
 	kfree(md);
 }
 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux