devfs/devsd: fix waserror() and unused variable compiler problem
the compiler optimizes setting unused variables out, which is problematic if they are used in waserror() handler which the compiler isnt aware of. rearrange the code to avoid this problem.
This commit is contained in:
parent
c4153b7755
commit
410d6bea6a
2 changed files with 22 additions and 18 deletions
|
@ -748,29 +748,33 @@ rdconf(void)
|
|||
} else
|
||||
mustrd = 1;
|
||||
|
||||
/* read it */
|
||||
cc = nil;
|
||||
c = nil;
|
||||
if (waserror()){
|
||||
if (cc != nil)
|
||||
cclose(cc);
|
||||
if (c)
|
||||
free(c);
|
||||
if (!mustrd)
|
||||
if(waserror()){
|
||||
if(!mustrd)
|
||||
return;
|
||||
nexterror();
|
||||
}
|
||||
|
||||
/* read it */
|
||||
cc = namec(s, Aopen, OREAD, 0);
|
||||
if(waserror()){
|
||||
cclose(cc);
|
||||
nexterror();
|
||||
}
|
||||
devtab[cc->type]->read(cc, confstr, sizeof confstr, 0);
|
||||
poperror();
|
||||
cclose(cc);
|
||||
cc = nil;
|
||||
|
||||
/* validate, copy and erase config; mconfig will repopulate confstr */
|
||||
if (strncmp(confstr, cfgstr, sizeof cfgstr - 1) != 0)
|
||||
error("bad #k config, first line must be: 'fsdev:\\n'");
|
||||
kstrdup(&c, confstr + sizeof cfgstr - 1);
|
||||
memset(confstr, 0, sizeof confstr);
|
||||
|
||||
c = nil;
|
||||
kstrdup(&c, confstr + sizeof cfgstr - 1);
|
||||
if(waserror()){
|
||||
free(c);
|
||||
nexterror();
|
||||
}
|
||||
memset(confstr, 0, sizeof confstr);
|
||||
/* process config copy one line at a time */
|
||||
for (p = c; p != nil && *p != '\0'; p = e){
|
||||
e = strchr(p, '\n');
|
||||
|
@ -780,8 +784,10 @@ rdconf(void)
|
|||
e++;
|
||||
mconfig(p, e - p);
|
||||
}
|
||||
USED(cc); /* until now, can be used in waserror clause */
|
||||
poperror();
|
||||
free(c);
|
||||
|
||||
poperror(); /* mustrd */
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -1558,10 +1558,10 @@ sdwstat(Chan* c, uchar* dp, int n)
|
|||
|
||||
d = nil;
|
||||
if(waserror()){
|
||||
free(d);
|
||||
qunlock(&unit->ctl);
|
||||
if(sdev != nil)
|
||||
decref(&sdev->r);
|
||||
free(d);
|
||||
nexterror();
|
||||
}
|
||||
|
||||
|
@ -1600,13 +1600,11 @@ sdwstat(Chan* c, uchar* dp, int n)
|
|||
error(Eperm);
|
||||
if(d[0].mode != ~0UL)
|
||||
perm->perm = (perm->perm & ~0777) | (d[0].mode & 0777);
|
||||
|
||||
free(d);
|
||||
d = nil; USED(d);
|
||||
poperror();
|
||||
qunlock(&unit->ctl);
|
||||
if(sdev != nil)
|
||||
decref(&sdev->r);
|
||||
poperror();
|
||||
free(d);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue