Skip to contentSkip to conversation

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

PATCH In review xiaomin1 3 participants 3 messages Jan 5, 2015 – Jan 9, 2015 Char and misc drivers

lore
Share & tools
lore

xiaomin1

author
#0 lore raw

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

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 +2 -1
index ffa97d2..289c59e 100644
@@ -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);
 	}
 fail:
 	mutex_unlock(&misc_mtx);
Signature · 1 line
1.7.9.5
Reviewed-by Alan Cox on v1 1/1
#1 lore raw
Quoted 18 lines · On Tue, 6 Jan 2015 08:34:07 +0800 xiaomin1 <[email protected]> wrote:

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);
 	}

This changes all the users of misc device open from singlethreaded to multi-threaded. Having read through the users I can find this seems safe and they all seem to have the right checks in place and to assume they are multi-threaded.

maintainer
#2 lore raw
In reply to xiaomin1
Quoted 7 lines · On Tue, Jan 06, 2015 at 08:34:07AM +0800, xiaomin1 wrote:

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.

Quoted 5 lines
---
 drivers/char/misc.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Please fix up your "From:" line to match your signed-off-by line, as I can't take it the way you sent this.

greg k-h