9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 1d00a34a219af5734eba414ba53f4182595b45f6
parent 4aaa276aa59b9f7e8a474cae79e79815a657f6d4
Author: Ambroise Vincent <ambroise.vincent@arm.com>
Date:   Thu, 25 Apr 2019 12:02:50 +0100

[dev] Fix types in devcons

Change-Id: I6ba30c0f210abebd3dab6770965bba82955838db
Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>

Diffstat:
Mdrivers/devcons.c | 59+++++++++++++++++++++++++----------------------------------
1 file changed, 25 insertions(+), 34 deletions(-)

diff --git a/drivers/devcons.c b/drivers/devcons.c @@ -27,14 +27,10 @@ static const Dirtab dirtab[] = { {"ctl", Qctl, 0, O_READ | O_WRITE} }; -struct cons { - Chan *in; - char inname[NAMESIZE]; - Chan *out[CONSOUT]; - char outname[CONSOUT][NAMESIZE]; -}; - -static struct cons *cons; +static Chan *in; +static char inname[NAMESIZE]; +static Chan *out[CONSOUT]; +static char outname[CONSOUT][NAMESIZE]; static char buffer[LINELEN]; static int head; @@ -53,16 +49,16 @@ consstatus(void *buf, Chan *c, int n) int len = 0; char tmp[CONSSTATUS]; - if (cons->in) + if (in) len += ksnprint(tmp, sizeof(tmp), "addin %s\n", - cons->inname); + inname); for (i = 0; i < CONSOUT; i++) { - if (cons->out[i]) + if (out[i]) len += ksnprint(tmp + len, sizeof(tmp) - len, "addout %s\n", - cons->outname[i]); + outname[i]); } if (len == sizeof(tmp)) @@ -79,13 +75,13 @@ consaddin(void *buf, int n) return -1; } - if (cons->in) { + if (in) { errno = ENOMEM; return -1; } - cons->in = namec(buf, O_READ); - memcpy(cons->inname, buf, n); + in = namec(buf, O_READ); + memcpy(inname, buf, n); return 0; } @@ -100,9 +96,9 @@ consaddout(void *buf, int n) } for (i = 0; i < CONSOUT; i++) { - if (!cons->out[i]) { - cons->out[i] = namec(buf, O_WRITE); - memcpy(cons->outname[i], buf, n); + if (!out[i]) { + out[i] = namec(buf, O_WRITE); + memcpy(outname[i], buf, n); return 0; } } @@ -118,14 +114,14 @@ consdelin(void *buf, int n) return -1; } - if (!cons->in || memcmp(buf, cons->inname, n)) { + if (!in || memcmp(buf, inname, n)) { errno = ENOENT; return -1; } - chanclose(cons->in); - cons->in = NULL; - cons->inname[0] = '\0'; + chanclose(in); + in = NULL; + inname[0] = '\0'; return 0; } @@ -140,10 +136,10 @@ consdelout(void *buf, int n) } for (i = 0; i < CONSOUT; i++) { - if (cons->out[i] && !memcmp(buf, cons->outname[i], n)) { - chanclose(cons->out[i]); - cons->out[i] = NULL; - cons->outname[i][0] = '\0'; + if (out[i] && !memcmp(buf, outname[i], n)) { + chanclose(out[i]); + out[i] = NULL; + outname[i][0] = '\0'; return 0; } } @@ -168,7 +164,7 @@ conswriteraw(char *buf, int n) } r = 0; - for (pp = cons->out; pp < &cons->out[CONSOUT]; pp++) { + for (pp = out; pp < &out[CONSOUT]; pp++) { int w; Chan *p; @@ -197,7 +193,7 @@ conswrite(Chan *c, void *buf, int n) int (*func)(void *, int); }; - const struct conscmds conscmds[] = { + static const struct conscmds conscmds[] = { {"addin", consaddin}, {"addout", consaddout}, {"delin", consdelin}, @@ -310,7 +306,6 @@ static char consreadone(void) { char ch; - Chan *in = cons->in; return devtab[in->type]->read(in, &ch, 1) < 0 ? EOF : ch; } @@ -359,7 +354,7 @@ consread(Chan *c, void *buf, int n) case Qconsfs: return dirread(c, buf, n, dirtab, NELEM(dirtab), devgen); case Qraw: - if (!cons->in) { + if (!in) { errno = ENOENT; return -1; } @@ -379,13 +374,9 @@ consread(Chan *c, void *buf, int n) void conslink(Attr *attr) { - size_t siz; Attr *a; int index = 0; - siz = sizeof(struct cons); - cons = memset(alloc(siz), 0, siz); - for (a = attr; a->key; a++) { if (!strcmp(a->key, "in")) consaddin(a->value, strlen(a->value));