Skip to contentSkip to conversation

move file->f_op->open out of mutex (misc_mtx) in misc_open

PATCH Hillf Danton 1 participant 1 message Jan 5, 2015

lore
Share & tools
lore
#0 lore raw
Quoted 19 lines

misc_mtx was used to mutex misc_list.
But file->f_op->open may be blocked by downloading firmware in some devices' open.
So move file->f_op->open out of mutex (misc_mtx) in misc_open to avoid this block.
It also make code more efficiency.

---
 drivers/char/misc.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/char/misc.c +0 -0
index ffa97d2..289c59e 100644

drivers/char/misc.c static int misc_open(struct inode * inode, struct file * file) · line 149

Quoted 7 lines
drivers/char/misc.c +2 -1
@@ -144,7 +144,8 @@ static int misc_open(struct inode * inode, struct file * file)
 	replace_fops(file, new_fops);
 	if (file->f_op->open) {
 		file->private_data = c;
-		err = file->f_op->open(inode,file);
+		mutex_unlock(&misc_mtx);
+		return file->f_op->open(inode,file);
 	}

What if unregister breaks in while opening?

Quoted 4 lines
drivers/char/misc.c +0 -1
 fail:
 	mutex_unlock(&misc_mtx);
--

1.7.9.5