Skip to content

Commit f061773

Browse files
TE-N-ShengjiuWanggregkh
authored andcommitted
rpmsg: char: Add mutex protection for rpmsg_eptdev_open()
[ Upstream commit abe13e9 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent c81935d commit f061773

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/rpmsg/rpmsg_char.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,25 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
127127
struct rpmsg_device *rpdev = eptdev->rpdev;
128128
struct device *dev = &eptdev->dev;
129129

130-
if (eptdev->ept)
130+
mutex_lock(&eptdev->ept_lock);
131+
if (eptdev->ept) {
132+
mutex_unlock(&eptdev->ept_lock);
131133
return -EBUSY;
134+
}
132135

133136
get_device(dev);
134137

135138
ept = rpmsg_create_ept(rpdev, rpmsg_ept_cb, eptdev, eptdev->chinfo);
136139
if (!ept) {
137140
dev_err(dev, "failed to open %s\n", eptdev->chinfo.name);
138141
put_device(dev);
142+
mutex_unlock(&eptdev->ept_lock);
139143
return -EINVAL;
140144
}
141145

142146
eptdev->ept = ept;
143147
filp->private_data = eptdev;
148+
mutex_unlock(&eptdev->ept_lock);
144149

145150
return 0;
146151
}

0 commit comments

Comments
 (0)