summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-10-05 08:36:57 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-10-27 06:27:01 +0100
commit9f196b281cf30fb1ca2c300bedff6a1b07a095b4 (patch)
tree9850ad5618aafd3b1df17319e1b0d7a8b23563fc
parentmcast01: Fix write to read-only string (diff)
downloadrtems-libbsd-9f196b281cf30fb1ca2c300bedff6a1b07a095b4.tar.bz2
NVD(4): Fix NULL pointer access in nvd_sync()
Update #4164.
-rw-r--r--rtemsbsd/sys/dev/nvd/nvd.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/rtemsbsd/sys/dev/nvd/nvd.c b/rtemsbsd/sys/dev/nvd/nvd.c
index 897b0af6..85069e3c 100644
--- a/rtemsbsd/sys/dev/nvd/nvd.c
+++ b/rtemsbsd/sys/dev/nvd/nvd.c
@@ -43,6 +43,7 @@
#include <stdatomic.h>
#include <rtems/blkdev.h>
+#include <rtems/thread.h>
#define NVD_STR "nvd"
@@ -208,28 +209,27 @@ nvd_request(struct nvd_disk *ndisk, rtems_blkdev_request *req,
static void
nvd_sync_completion(void *arg, const struct nvme_completion *status)
{
- rtems_status_code sc;
-
- if (nvme_completion_is_error(status)) {
- sc = RTEMS_IO_ERROR;
- } else {
- sc = RTEMS_SUCCESSFUL;
- }
+ rtems_binary_semaphore *sync;
- rtems_blkdev_request_done(arg, sc);
+ sync = arg;
+ rtems_binary_semaphore_post(sync);
}
static int
-nvd_sync(struct nvd_disk *ndisk, rtems_blkdev_request *req)
+nvd_sync(struct nvd_disk *ndisk)
{
+ rtems_binary_semaphore sync;
int error;
- error = nvme_ns_cmd_flush(ndisk->ns, nvd_sync_completion, req);
- if (error != 0) {
- rtems_blkdev_request_done(req, RTEMS_NO_MEMORY);
+ rtems_binary_semaphore_init(&sync, "nvd sync");
+
+ error = nvme_ns_cmd_flush(ndisk->ns, nvd_sync_completion, &sync);
+ if (error == 0) {
+ rtems_binary_semaphore_wait(&sync);
}
- return (0);
+ rtems_binary_semaphore_destroy(&sync);
+ return (error);
}
static int
@@ -244,7 +244,7 @@ nvd_ioctl(rtems_disk_device *dd, uint32_t req, void *arg)
}
if (req == RTEMS_BLKDEV_REQ_SYNC) {
- return (nvd_sync(ndisk, arg));
+ return (nvd_sync(ndisk));
}
if (req == RTEMS_BLKIO_CAPABILITIES) {