rpmsg: char: Add mutex protection for rpmsg_eptdev_open()
PATCH RESEND 1/1 rpmsg: char: Add mutex protection for rpmsg_eptdev_open()
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.
---
changes in resend:
- add fixes tag
drivers/rpmsg/rpmsg_char.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/rpmsg/rpmsg_char.c +6 -1
@@ -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 ; }
Signature · 1 line
2.17.1
Mathieu Poirier
maintainerQuoted 8 lines · Shengjiu Wang
There is no mutex protection for
rpmsg_eptdev_open(), especially foreptdev->eptread and write operation. It may cause issues when multiple instances callrpmsg_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 <[email protected]>
This looks good. I will fix the above typo and apply the patch when the 5.19 cycle starts.
Thanks,
Mathieu
Quoted 41 lines
---
changes in resend:
- add fixes tagdrivers/rpmsg/rpmsg_char.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/rpmsg/rpmsg_char.c +6
-1@@ -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 ; }Signature · 1 line
2.17.1
Mathieu Poirier
maintainerQuoted 6 lines · Shengjiu Wang
There is no mutex protection for
rpmsg_eptdev_open(), especially foreptdev->eptread and write operation. It may cause issues when multiple instances callrpmsg_eptdev_open()in parallel,the return state may be success or EBUGY.
Quoted 8 lines
Fixes 964e8bedd5a1 ("rpmsg: char: Return an error if device already open")Signed-off-by Shengjiu Wang <[email protected]>---
changes in resend:
- add fixes tagdrivers/rpmsg/rpmsg_char.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
I have applied your patch.
Thanks,
Mathieu
Quoted 35 lines
drivers/rpmsg/rpmsg_char.c +6
-1@@ -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 ; }Signature · 1 line
2.17.1