move file->f_op->open out of mutex (misc_mtx) in misc_open
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
@@ -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
Quoted 18 lines · On Tue, 6 Jan 2015 08:34:07 +0800 xiaomin1 <[email protected]> wrote:
misc_mtxwas used to mutexmisc_list.
Butfile->f_op->openmay be blocked by downloading firmware in some devices' open.
So movefile->f_op->openout of mutex (misc_mtx) inmisc_opento avoid this block.
It also make code more efficiency.Signed-off-by Zhang Dongxing <[email protected]>Signed-off-by xiaoming wang <[email protected]>--- drivers/char/misc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/char/misc.c +0
-0
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.
Greg KH
maintainerQuoted 7 lines · On Tue, Jan 06, 2015 at 08:34:07AM +0800, xiaomin1 wrote:
misc_mtxwas used to mutexmisc_list.
Butfile->f_op->openmay be blocked by downloading firmware in some devices' open.
So movefile->f_op->openout of mutex (misc_mtx) inmisc_opento avoid this block.
It also make code more efficiency.
Quoted 5 lines
Signed-off-by Zhang Dongxing <[email protected]>Signed-off-by xiaoming wang <[email protected]>--- 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