mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 16:24:13 +08:00
rpmsg: char: Add mutex protection for rpmsg_eptdev_open()
[ Upstream commitabe13e9a56
] 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 EBUSY. Fixes:964e8bedd5
("rpmsg: char: Return an error if device already open") Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com> Link: https://lore.kernel.org/r/1653104105-16779-1-git-send-email-shengjiu.wang@nxp.com Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
c81935d0e0
commit
f061773b7b
@ -127,8 +127,11 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
|
|||||||
struct rpmsg_device *rpdev = eptdev->rpdev;
|
struct rpmsg_device *rpdev = eptdev->rpdev;
|
||||||
struct device *dev = &eptdev->dev;
|
struct device *dev = &eptdev->dev;
|
||||||
|
|
||||||
if (eptdev->ept)
|
mutex_lock(&eptdev->ept_lock);
|
||||||
|
if (eptdev->ept) {
|
||||||
|
mutex_unlock(&eptdev->ept_lock);
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
}
|
||||||
|
|
||||||
get_device(dev);
|
get_device(dev);
|
||||||
|
|
||||||
@ -136,11 +139,13 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
|
|||||||
if (!ept) {
|
if (!ept) {
|
||||||
dev_err(dev, "failed to open %s\n", eptdev->chinfo.name);
|
dev_err(dev, "failed to open %s\n", eptdev->chinfo.name);
|
||||||
put_device(dev);
|
put_device(dev);
|
||||||
|
mutex_unlock(&eptdev->ept_lock);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
eptdev->ept = ept;
|
eptdev->ept = ept;
|
||||||
filp->private_data = eptdev;
|
filp->private_data = eptdev;
|
||||||
|
mutex_unlock(&eptdev->ept_lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user