AHCI: Replace MMIO accesses with helper functions
[akaros.git] / kern / drivers / dev / eventfd.c
index 395eaa0..2287b25 100644 (file)
@@ -70,7 +70,7 @@ static struct chan *efd_attach(char *spec)
        struct eventfd *efd;
 
        c = devattach(devname(), spec);
-       efd = kzmalloc(sizeof(struct eventfd), KMALLOC_WAIT);
+       efd = kzmalloc(sizeof(struct eventfd), MEM_WAIT);
        SLIST_INIT(&efd->fd_taps);
        spinlock_init(&efd->tap_lock);
        rendez_init(&efd->rv_readers);
@@ -161,10 +161,8 @@ static unsigned long efd_read_efd(struct eventfd *efd, struct chan *c)
        while (1) {
                old_count = atomic_read(&efd->counter);
                if (!old_count) {
-                       if (c->flag & O_NONBLOCK) {
-                               set_errno(EAGAIN);
-                               error("Would block on #%s read", devname());
-                       }
+                       if (c->flag & O_NONBLOCK)
+                               error(EAGAIN, "Would block on #%s read", devname());
                        rendez_sleep(&efd->rv_readers, has_counts, efd);
                } else {
                        if (efd->flags & EFD_SEMAPHORE) {
@@ -219,10 +217,8 @@ static void efd_write_efd(struct eventfd *efd, unsigned long add_to,
                old_count = atomic_read(&efd->counter);
                new_count = old_count + add_to;
                if (new_count > EFD_MAX_VAL) {
-                       if (c->flag & O_NONBLOCK) {
-                               set_errno(EAGAIN);
-                               error("Would block on #%s write", devname());
-                       }
+                       if (c->flag & O_NONBLOCK)
+                               error(EAGAIN, "Would block on #%s write", devname());
                        rendez_sleep(&efd->rv_writers, has_room, efd);
                } else {
                        if (atomic_cas(&efd->counter, old_count, new_count))
@@ -244,20 +240,19 @@ static long efd_write(struct chan *c, void *ubuf, long n, int64_t offset)
                case Qctl:
                        /* If we want to allow runtime changing of settings, we can do it
                         * here. */
-                       error("No #%s ctl commands supported", devname());
+                       error(EFAIL, "No #%s ctl commands supported", devname());
                        break;
                case Qefd:
                        /* We want to give strtoul a null-terminated buf (can't handle
                         * arbitrary user strings).  Ignoring the chan offset too. */
-                       if (n > sizeof(num64)) {
-                               set_errno(EINVAL);
-                               error("attempted to write %d chars, max %d", n, sizeof(num64));
-                       }
+                       if (n > sizeof(num64))
+                               error(EAGAIN, "attempted to write %d chars, max %d", n,
+                                         sizeof(num64));
                        memcpy(num64, ubuf, n);
                        num64[n] = 0;   /* enforce trailing 0 */
                        write_val = strtoul(num64, 0, 0);
                        if (write_val == (unsigned long)(-1))
-                               error("Eventfd write must not be -1");
+                               error(EFAIL, "Eventfd write must not be -1");
                        efd_write_efd(efd, write_val, c);
                        break;
                default:
@@ -291,9 +286,8 @@ static int efd_tapfd(struct chan *c, struct fd_tap *tap, int cmd)
        switch (c->qid.path) {
                case Qefd:
                        if (tap->filter & ~EFD_LEGAL_TAPS) {
-                               set_errno(ENOSYS);
-                               set_errstr("Unsupported #%s tap, must be %p, got %p", devname(),
-                                          EFD_LEGAL_TAPS, tap->filter);
+                               set_error(ENOSYS, "Unsupported #%s tap, must be %p", devname(),
+                                                 EFD_LEGAL_TAPS);
                                return -1;
                        }
                        spin_lock(&efd->tap_lock);
@@ -307,17 +301,15 @@ static int efd_tapfd(struct chan *c, struct fd_tap *tap, int cmd)
                                        ret = 0;
                                        break;
                                default:
-                                       set_errno(ENOSYS);
-                                       set_errstr("Unsupported #%s tap command %p",
-                                                  devname(), cmd);
+                                       set_error(ENOSYS, "Unsupported #%s tap command %p",
+                                                         devname(), cmd);
                                        ret = -1;
                        }
                        spin_unlock(&efd->tap_lock);
                        return ret;
                default:
-                       set_errno(ENOSYS);
-                       set_errstr("Can't tap #%s file type %d", devname(),
-                                  c->qid.path);
+                       set_error(ENOSYS, "Can't tap #%s file type %d", devname(),
+                                 c->qid.path);
                        return -1;
        }
 }