All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH] rpmsg: char: Add mutex protection for rpmsg_eptdev_open()
@ 2022-05-21  3:35 Shengjiu Wang
  2022-05-31 17:28 ` Mathieu Poirier
  2022-06-14 22:28 ` Mathieu Poirier
  0 siblings, 2 replies; 3+ messages in thread
From: Shengjiu Wang @ 2022-05-21  3:35 UTC (permalink / raw)
  To: bjorn.andersson, mathieu.poirier, arnaud.pouliquen
  Cc: linux-remoteproc, linux-kernel, shengjiu.wang

There is no mutex protection for rpmsg_eptdev_open(),
especially for eptdev->ept read and write operation.
It may cause issues when multiple instances call
rpmsg_eptdev_open() in parallel,the return state
may be success or EBUGY.

Fixes: 964e8bedd5a1 ("rpmsg: char: Return an error if device already open")
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
---
changes in resend:
- add fixes tag

 drivers/rpmsg/rpmsg_char.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
index b6183d4f62a2..4f2189111494 100644
--- a/drivers/rpmsg/rpmsg_char.c
+++ b/drivers/rpmsg/rpmsg_char.c
@@ -120,8 +120,11 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
 	struct rpmsg_device *rpdev = eptdev->rpdev;
 	struct device *dev = &eptdev->dev;
 
-	if (eptdev->ept)
+	mutex_lock(&eptdev->ept_lock);
+	if (eptdev->ept) {
+		mutex_unlock(&eptdev->ept_lock);
 		return -EBUSY;
+	}
 
 	get_device(dev);
 
@@ -137,11 +140,13 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
 	if (!ept) {
 		dev_err(dev, "failed to open %s\n", eptdev->chinfo.name);
 		put_device(dev);
+		mutex_unlock(&eptdev->ept_lock);
 		return -EINVAL;
 	}
 
 	eptdev->ept = ept;
 	filp->private_data = eptdev;
+	mutex_unlock(&eptdev->ept_lock);
 
 	return 0;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RESEND PATCH] rpmsg: char: Add mutex protection for rpmsg_eptdev_open()
  2022-05-21  3:35 [RESEND PATCH] rpmsg: char: Add mutex protection for rpmsg_eptdev_open() Shengjiu Wang
@ 2022-05-31 17:28 ` Mathieu Poirier
  2022-06-14 22:28 ` Mathieu Poirier
  1 sibling, 0 replies; 3+ messages in thread
From: Mathieu Poirier @ 2022-05-31 17:28 UTC (permalink / raw)
  To: Shengjiu Wang
  Cc: bjorn.andersson, arnaud.pouliquen, linux-remoteproc,
	linux-kernel, shengjiu.wang

On Sat, May 21, 2022 at 11:35:05AM +0800, Shengjiu Wang wrote:
> There is no mutex protection for rpmsg_eptdev_open(),
> especially for eptdev->ept read and write operation.
> It may cause issues when multiple instances call
> rpmsg_eptdev_open() in parallel,the return state
> may be success or EBUGY.
> 
> Fixes: 964e8bedd5a1 ("rpmsg: char: Return an error if device already open")
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>

This looks good.  I will fix the above typo and apply the patch when the 5.19 cycle
starts.

Thanks,
Mathieu

> ---
> changes in resend:
> - add fixes tag
> 
>  drivers/rpmsg/rpmsg_char.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
> index b6183d4f62a2..4f2189111494 100644
> --- a/drivers/rpmsg/rpmsg_char.c
> +++ b/drivers/rpmsg/rpmsg_char.c
> @@ -120,8 +120,11 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
>  	struct rpmsg_device *rpdev = eptdev->rpdev;
>  	struct device *dev = &eptdev->dev;
>  
> -	if (eptdev->ept)
> +	mutex_lock(&eptdev->ept_lock);
> +	if (eptdev->ept) {
> +		mutex_unlock(&eptdev->ept_lock);
>  		return -EBUSY;
> +	}
>  
>  	get_device(dev);
>  
> @@ -137,11 +140,13 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
>  	if (!ept) {
>  		dev_err(dev, "failed to open %s\n", eptdev->chinfo.name);
>  		put_device(dev);
> +		mutex_unlock(&eptdev->ept_lock);
>  		return -EINVAL;
>  	}
>  
>  	eptdev->ept = ept;
>  	filp->private_data = eptdev;
> +	mutex_unlock(&eptdev->ept_lock);
>  
>  	return 0;
>  }
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RESEND PATCH] rpmsg: char: Add mutex protection for rpmsg_eptdev_open()
  2022-05-21  3:35 [RESEND PATCH] rpmsg: char: Add mutex protection for rpmsg_eptdev_open() Shengjiu Wang
  2022-05-31 17:28 ` Mathieu Poirier
@ 2022-06-14 22:28 ` Mathieu Poirier
  1 sibling, 0 replies; 3+ messages in thread
From: Mathieu Poirier @ 2022-06-14 22:28 UTC (permalink / raw)
  To: Shengjiu Wang
  Cc: bjorn.andersson, arnaud.pouliquen, linux-remoteproc,
	linux-kernel, shengjiu.wang

On Sat, May 21, 2022 at 11:35:05AM +0800, Shengjiu Wang wrote:
> There is no mutex protection for rpmsg_eptdev_open(),
> especially for eptdev->ept read and write operation.
> It may cause issues when multiple instances call
> rpmsg_eptdev_open() in parallel,the return state
> may be success or EBUGY.
> 
> Fixes: 964e8bedd5a1 ("rpmsg: char: Return an error if device already open")
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> ---
> changes in resend:
> - add fixes tag
> 
>  drivers/rpmsg/rpmsg_char.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

I have applied your patch.

Thanks,
Mathieu

> 
> diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
> index b6183d4f62a2..4f2189111494 100644
> --- a/drivers/rpmsg/rpmsg_char.c
> +++ b/drivers/rpmsg/rpmsg_char.c
> @@ -120,8 +120,11 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
>  	struct rpmsg_device *rpdev = eptdev->rpdev;
>  	struct device *dev = &eptdev->dev;
>  
> -	if (eptdev->ept)
> +	mutex_lock(&eptdev->ept_lock);
> +	if (eptdev->ept) {
> +		mutex_unlock(&eptdev->ept_lock);
>  		return -EBUSY;
> +	}
>  
>  	get_device(dev);
>  
> @@ -137,11 +140,13 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
>  	if (!ept) {
>  		dev_err(dev, "failed to open %s\n", eptdev->chinfo.name);
>  		put_device(dev);
> +		mutex_unlock(&eptdev->ept_lock);
>  		return -EINVAL;
>  	}
>  
>  	eptdev->ept = ept;
>  	filp->private_data = eptdev;
> +	mutex_unlock(&eptdev->ept_lock);
>  
>  	return 0;
>  }
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-14 22:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-21  3:35 [RESEND PATCH] rpmsg: char: Add mutex protection for rpmsg_eptdev_open() Shengjiu Wang
2022-05-31 17:28 ` Mathieu Poirier
2022-06-14 22:28 ` Mathieu Poirier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.