Skip to content

Commit abe13e9

Browse files
TE-N-ShengjiuWangmathieupoirier
authored andcommitted
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 EBUSY. Fixes: 964e8be ("rpmsg: char: Return an error if device already open") Signed-off-by: Shengjiu Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mathieu Poirier <[email protected]>
1 parent b13bacc commit abe13e9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/rpmsg/rpmsg_char.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
120120
struct rpmsg_device *rpdev = eptdev->rpdev;
121121
struct device *dev = &eptdev->dev;
122122

123-
if (eptdev->ept)
123+
mutex_lock(&eptdev->ept_lock);
124+
if (eptdev->ept) {
125+
mutex_unlock(&eptdev->ept_lock);
124126
return -EBUSY;
127+
}
125128

126129
get_device(dev);
127130

@@ -137,11 +140,13 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
137140
if (!ept) {
138141
dev_err(dev, "failed to open %s\n", eptdev->chinfo.name);
139142
put_device(dev);
143+
mutex_unlock(&eptdev->ept_lock);
140144
return -EINVAL;
141145
}
142146

143147
eptdev->ept = ept;
144148
filp->private_data = eptdev;
149+
mutex_unlock(&eptdev->ept_lock);
145150

146151
return 0;
147152
}

0 commit comments

Comments
 (0)