AHCI: Replace MMIO accesses with helper functions
[akaros.git] / kern / drivers / dev / eventfd.c
index e914cdd..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(EFAIL, "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(EFAIL, "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))
@@ -290,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);
@@ -306,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;
        }
 }