mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] loop driver kernel thread module reference fix
@ 2003-09-17 15:28 Angus Sawyer
  0 siblings, 0 replies; only message in thread
From: Angus Sawyer @ 2003-09-17 15:28 UTC (permalink / raw)
  To: linux-kernel


the loop driver does not hold module references for the kernel_thread, and 
does not appear to wait for thread termination at any point.  

This patch associates the ref counting with the kernel thread which covers
the existing set/clear fd interval.

Hope this is OK.

 drivers/block/loop.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)

diff -puN drivers/block/loop.c~loop drivers/block/loop.c
--- linux-2.6.0-test5/drivers/block/loop.c~loop	2003-09-17 16:16:19.447291752 
+0100
+++ linux-2.6.0-test5-angus/drivers/block/loop.c	2003-09-17 16:25:55.103778664 
+0100
@@ -651,7 +651,7 @@ static int loop_thread(void *data)
 	}
 
 	up(&lo->lo_sem);
-	return 0;
+	module_put_and_exit(0);
 }
 
 static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
@@ -664,9 +664,6 @@ static int loop_set_fd(struct loop_devic
 	int		lo_flags = 0;
 	int		error;
 
-	/* This is safe, since we have a reference from open(). */
-	__module_get(THIS_MODULE);
-
 	error = -EBUSY;
 	if (lo->lo_state != Lo_unbound)
 		goto out;
@@ -757,6 +754,8 @@ static int loop_set_fd(struct loop_devic
 		blk_queue_merge_bvec(lo->lo_queue, q->merge_bvec_fn);
 	}
 
+	/* This is safe, since we have a reference from open(). */
+	__module_get(THIS_MODULE);
 	kernel_thread(loop_thread, lo, CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
 	down(&lo->lo_sem);
 
@@ -767,7 +766,6 @@ static int loop_set_fd(struct loop_devic
 	fput(file);
  out:
 	/* This is safe: open() is still holding a reference. */
-	module_put(THIS_MODULE);
 	return error;
 }
 
@@ -849,8 +847,6 @@ static int loop_clr_fd(struct loop_devic
 	mapping_set_gfp_mask(filp->f_dentry->d_inode->i_mapping, gfp);
 	lo->lo_state = Lo_unbound;
 	fput(filp);
-	/* This is safe: open() is still holding a reference. */
-	module_put(THIS_MODULE);
 	return 0;
 }
 

_


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-09-17 15:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-17 15:28 [PATCH] loop driver kernel thread module reference fix Angus Sawyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®