Skip to content

Commit 5e6a0e0

Browse files
TE-N-ShengjiuWangmathieupoirier
authored andcommitted
remoteproc: core: Move state checking to remoteproc_core
There is no mutex protection of these state checking for 'stop' and 'detach' which can't guarantee there is no another instance is trying to do same operation. Consider two instances case: Instance1: echo stop > /sys/class/remoteproc/remoteproc0/state Instance2: echo stop > /sys/class/remoteproc/remoteproc0/state The issue is that the instance2 case may success, Or it may fail with -EINVAL, which is uncertain. So move this state checking in rproc_cdev_write() and state_store() for 'stop', 'detach' operation to 'rproc_shutdown' , 'rproc_detach' function under the mutex protection. Signed-off-by: Shengjiu Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mathieu Poirier <[email protected]>
1 parent 8f454f9 commit 5e6a0e0

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

drivers/remoteproc/remoteproc_cdev.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_
3434
if (!strncmp(cmd, "start", len)) {
3535
ret = rproc_boot(rproc);
3636
} else if (!strncmp(cmd, "stop", len)) {
37-
if (rproc->state != RPROC_RUNNING &&
38-
rproc->state != RPROC_ATTACHED)
39-
return -EINVAL;
40-
4137
ret = rproc_shutdown(rproc);
4238
} else if (!strncmp(cmd, "detach", len)) {
43-
if (rproc->state != RPROC_ATTACHED)
44-
return -EINVAL;
45-
4639
ret = rproc_detach(rproc);
4740
} else {
4841
dev_err(&rproc->dev, "Unrecognized option\n");

drivers/remoteproc/remoteproc_core.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,12 @@ int rproc_shutdown(struct rproc *rproc)
20712071
return ret;
20722072
}
20732073

2074+
if (rproc->state != RPROC_RUNNING &&
2075+
rproc->state != RPROC_ATTACHED) {
2076+
ret = -EINVAL;
2077+
goto out;
2078+
}
2079+
20742080
/* if the remote proc is still needed, bail out */
20752081
if (!atomic_dec_and_test(&rproc->power))
20762082
goto out;
@@ -2130,6 +2136,11 @@ int rproc_detach(struct rproc *rproc)
21302136
return ret;
21312137
}
21322138

2139+
if (rproc->state != RPROC_ATTACHED) {
2140+
ret = -EINVAL;
2141+
goto out;
2142+
}
2143+
21332144
/* if the remote proc is still needed, bail out */
21342145
if (!atomic_dec_and_test(&rproc->power)) {
21352146
ret = 0;

drivers/remoteproc/remoteproc_sysfs.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,8 @@ static ssize_t state_store(struct device *dev,
198198
if (ret)
199199
dev_err(&rproc->dev, "Boot failed: %d\n", ret);
200200
} else if (sysfs_streq(buf, "stop")) {
201-
if (rproc->state != RPROC_RUNNING &&
202-
rproc->state != RPROC_ATTACHED)
203-
return -EINVAL;
204-
205201
ret = rproc_shutdown(rproc);
206202
} else if (sysfs_streq(buf, "detach")) {
207-
if (rproc->state != RPROC_ATTACHED)
208-
return -EINVAL;
209-
210203
ret = rproc_detach(rproc);
211204
} else {
212205
dev_err(&rproc->dev, "Unrecognised option: %s\n", buf);

0 commit comments

Comments
 (0)