Run spatch on devcons.c
[akaros.git] / kern / drivers / dev / alarm.c
index 52bd8cd..889384c 100644 (file)
@@ -246,9 +246,9 @@ static struct chan *alarmopen(struct chan *c, int omode)
                case Qtopdir:
                case Qalarmdir:
                        if (omode & O_REMCLO)
-                               error(Eperm);
+                               error(EPERM, NULL);
                        if (omode & O_WRITE)
-                               error(Eisdir);
+                               error(EISDIR, NULL);
                        break;
                case Qclone:
                        a = kzmalloc(sizeof(struct proc_alarm), KMALLOC_WAIT);
@@ -287,7 +287,7 @@ static struct chan *alarmopen(struct chan *c, int omode)
                        }
                        spin_unlock(&p->alarmset.lock);
                        if (!a_i)
-                               error("Unable to open alarm, concurrent closing");
+                               error(EFAIL, "Unable to open alarm, concurrent closing");
                        break;
        }
        c->mode = openmode(omode);
@@ -299,17 +299,17 @@ static struct chan *alarmopen(struct chan *c, int omode)
 
 static void alarmcreate(struct chan *c, char *name, int omode, uint32_t perm)
 {
-       error(Eperm);
+       error(EPERM, NULL);
 }
 
 static void alarmremove(struct chan *c)
 {
-       error(Eperm);
+       error(EPERM, NULL);
 }
 
 static int alarmwstat(struct chan *c, uint8_t * dp, int n)
 {
-       error("No alarmwstat");
+       error(EFAIL, "No alarmwstat");
        return 0;
 }
 
@@ -355,7 +355,7 @@ static long alarmread(struct chan *c, void *ubuf, long n, int64_t offset)
 static long alarmwrite(struct chan *c, void *ubuf, long n, int64_t unused)
 {
        ERRSTACK(1);
-       char buf[32];
+       char num64[NUMSIZE64];
        struct cmdbuf *cb;
        struct proc_alarm *p_alarm;
        uint64_t hexval;
@@ -363,7 +363,7 @@ static long alarmwrite(struct chan *c, void *ubuf, long n, int64_t unused)
        switch (TYPE(c->qid)) {
                case Qtopdir:
                case Qalarmdir:
-                       error(Eperm);
+                       error(EPERM, NULL);
                case Qctl:
                        p_alarm = QID2A(c->qid);
                        cb = parsecmd(ubuf, n);
@@ -372,21 +372,21 @@ static long alarmwrite(struct chan *c, void *ubuf, long n, int64_t unused)
                                nexterror();
                        }
                        if (cb->nf < 1)
-                               error("short control request");
+                               error(EFAIL, "short control request");
                        if (!strcmp(cb->f[0], "evq")) {
                                if (cb->nf < 2)
-                                       error("evq needs a pointer");
+                                       error(EFAIL, "evq needs a pointer");
                                /* i think it's safe to do a stroul on a parsecmd.  it's kernel
                                 * memory, and space or 0 terminated */
                                hexval = strtoul(cb->f[1], 0, 16);
                                /* This is just to help userspace - event code can handle it */
                                if (!is_user_rwaddr((void *)hexval, sizeof(struct event_queue)))
-                                       error("Non-user ev_q pointer");
+                                       error(EFAIL, "Non-user ev_q pointer");
                                p_alarm->ev_q = (struct event_queue *)hexval;
                        } else if (!strcmp(cb->f[0], "cancel")) {
                                unset_alarm(p_alarm->proc->alarmset.tchain, &p_alarm->a_waiter);
                        } else {
-                               error("%s: not implemented", cb->f[0]);
+                               error(EFAIL, "%s: not implemented", cb->f[0]);
                        }
                        kfree(cb);
                        poperror();
@@ -394,11 +394,14 @@ static long alarmwrite(struct chan *c, void *ubuf, long n, int64_t unused)
                case Qtimer:
                        /* want to give strtoul a null-terminated buf (can't handle random
                         * user strings) */
-                       if (n >= sizeof(buf))
-                               error(Egreg);
-                       memcpy(buf, ubuf, n);
-                       buf[n] = 0;
-                       hexval = strtoul(buf, 0, 16);
+                       if (n > sizeof(num64)) {
+                               set_errno(EINVAL);
+                               error(EFAIL, "attempted to write %d chars, max %d", n,
+                                         sizeof(num64));
+                       }
+                       memcpy(num64, ubuf, n);
+                       num64[n] = 0;   /* enforce trailing 0 */
+                       hexval = strtoul(num64, 0, 16);
                        p_alarm = QID2A(c->qid);
                        /* if you don't know if it was running or not, resetting will turn
                         * it on regardless. */
@@ -412,24 +415,23 @@ static long alarmwrite(struct chan *c, void *ubuf, long n, int64_t unused)
 }
 
 struct dev alarmdevtab __devtab = {
-       "alarm",
+       .name = "alarm",
 
-       devreset,
-       alarminit,
-       devshutdown,
-       alarmattach,
-       alarmwalk,
-       alarmstat,
-       alarmopen,
-       alarmcreate,
-       alarmclose,
-       alarmread,
-       devbread,
-       alarmwrite,
-       devbwrite,
-       alarmremove,
-       alarmwstat,
-       devpower,
-       //devconfig,
-       devchaninfo,
+       .reset = devreset,
+       .init = alarminit,
+       .shutdown = devshutdown,
+       .attach = alarmattach,
+       .walk = alarmwalk,
+       .stat = alarmstat,
+       .open = alarmopen,
+       .create = alarmcreate,
+       .close = alarmclose,
+       .read = alarmread,
+       .bread = devbread,
+       .write = alarmwrite,
+       .bwrite = devbwrite,
+       .remove = alarmremove,
+       .wstat = alarmwstat,
+       .power = devpower,
+       .chaninfo = devchaninfo,
 };