Re: [PATCH] move file->f_op->open out of mutex (misc_mtx) in misc_open

From: One Thousand Gnomes
Date: Mon Jan 05 2015 - 08:59:04 EST


On Tue, 6 Jan 2015 08:34:07 +0800
xiaomin1 <xiaoming.wang@xxxxxxxxx> 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.
>
> Signed-off-by: Zhang Dongxing <dongxing.zhang@xxxxxxxxx>
> Signed-off-by: xiaoming wang <xiaoming.wang@xxxxxxxxx>
> ---
> drivers/char/misc.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/misc.c b/drivers/char/misc.c
> index ffa97d2..289c59e 100644
> --- a/drivers/char/misc.c
> +++ b/drivers/char/misc.c
> @@ -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.

Reviewed-by: Alan Cox <alan@xxxxxxxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/