fix bogus waserror() constructs. also, poperror() before releasing the protected resource. Reference: /n/atom/patch/applied/m10gerror Date: Fri Feb 14 01:08:17 CET 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/9/pc/etherm10g.c Fri Feb 14 01:07:56 2014 +++ /sys/src/9/pc/etherm10g.c Fri Feb 14 01:07:58 2014 @@ -1,6 +1,6 @@ /* * myricom 10 gbit ethernet - * © 2007—13 erik quanstrom, coraid, inc. + * © 2007—14 erik quanstrom, coraid, inc. */ #include "u.h" @@ -480,18 +480,18 @@ coherence(); memmove(c->ram + Cmdoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 15; i++){ if(cmd->i[1] != Noconf){ - poperror(); i = gbit32(cmd->c); qunlock(&c->cmdl); if(cmd->i[1] != 0) dprint("[%ux]", i); return i; } - tsleep(&up->sleep, return0, 0, 1); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); + } } qunlock(&c->cmdl); print("m10g: cmd timeout [%ux %ux] cmd=%d\n", cmd->i[0], cmd->i[1], type); @@ -518,18 +518,18 @@ coherence(); memmove(c->ram + Cmdoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 15; i++){ if(cmd->i[1] != Noconf){ - poperror(); i = gbit32(cmd->c); qunlock(&c->cmdl); if(cmd->i[1] != 0) dprint("[%ux]", i); return i; } - tsleep(&up->sleep, return0, 0, 1); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); + } } qunlock(&c->cmdl); print("m10g: maccmd timeout [%ux %ux] cmd=%d\n", cmd->i[0], cmd->i[1], type); @@ -560,17 +560,17 @@ coherence(); memmove(c->ram + Cmdoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 15; i++){ if(c->cmd->i[1] != Noconf){ i = gbit32(c->cmd->c); if(i == 0) error(Eio); - poperror(); return i; } - tsleep(&up->sleep, return0, 0, 5); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); + } } error(Etimeout); return ~0; @@ -593,14 +593,13 @@ prepcmd(buf, 6); memmove(c->ram + Rdmaoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 20; i++){ - if(c->cmd->i[0] == Noconf){ - poperror(); + if(c->cmd->i[0] == Noconf) return gbit32(c->cmd->c); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); } - tsleep(&up->sleep, return0, 0, 1); } error(Etimeout); print("m10g: rdmacmd timeout\n"); @@ -762,7 +761,6 @@ if(waserror()){ print("m10g: reset error\n"); nexterror(); - return -1; } chkfw(c); @@ -1351,8 +1349,8 @@ } c->state = Runed; m10ginterrupt(nil, e); /* botch: racy */ - qunlock(c); poperror(); + qunlock(c); } static int @@ -1386,7 +1384,7 @@ } static long -m10gifstat(Ether *e, void *v, long n, ulong off) +m10gifstat(Ether *e, void *v, long n, usize off) { char *p; int l, lim; @@ -1506,8 +1504,8 @@ default: error(Ebadarg); } - free(c); poperror(); + free(c); return n; } --- /sys/src/9/pcpae/etherm10g.c Fri Feb 14 01:08:01 2014 +++ /sys/src/9/pcpae/etherm10g.c Fri Feb 14 01:08:03 2014 @@ -1,6 +1,6 @@ /* * myricom 10 gbit ethernet - * © 2007—13 erik quanstrom, coraid, inc. + * © 2007—14 erik quanstrom, coraid, inc. */ #include "u.h" @@ -480,18 +480,18 @@ coherence(); memmove(c->ram + Cmdoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 15; i++){ if(cmd->i[1] != Noconf){ - poperror(); i = gbit32(cmd->c); qunlock(&c->cmdl); if(cmd->i[1] != 0) dprint("[%ux]", i); return i; } - tsleep(&up->sleep, return0, 0, 1); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); + } } qunlock(&c->cmdl); print("m10g: cmd timeout [%ux %ux] cmd=%d\n", cmd->i[0], cmd->i[1], type); @@ -518,18 +518,18 @@ coherence(); memmove(c->ram + Cmdoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 15; i++){ if(cmd->i[1] != Noconf){ - poperror(); i = gbit32(cmd->c); qunlock(&c->cmdl); if(cmd->i[1] != 0) dprint("[%ux]", i); return i; } - tsleep(&up->sleep, return0, 0, 1); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); + } } qunlock(&c->cmdl); print("m10g: maccmd timeout [%ux %ux] cmd=%d\n", cmd->i[0], cmd->i[1], type); @@ -560,17 +560,17 @@ coherence(); memmove(c->ram + Cmdoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 15; i++){ if(c->cmd->i[1] != Noconf){ i = gbit32(c->cmd->c); if(i == 0) error(Eio); - poperror(); return i; } - tsleep(&up->sleep, return0, 0, 5); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); + } } error(Etimeout); return ~0; @@ -593,14 +593,13 @@ prepcmd(buf, 6); memmove(c->ram + Rdmaoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 20; i++){ - if(c->cmd->i[0] == Noconf){ - poperror(); + if(c->cmd->i[0] == Noconf) return gbit32(c->cmd->c); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); } - tsleep(&up->sleep, return0, 0, 1); } error(Etimeout); print("m10g: rdmacmd timeout\n"); @@ -762,7 +761,6 @@ if(waserror()){ print("m10g: reset error\n"); nexterror(); - return -1; } chkfw(c); @@ -1351,8 +1349,8 @@ } c->state = Runed; m10ginterrupt(nil, e); /* botch: racy */ - qunlock(c); poperror(); + qunlock(c); } static int @@ -1386,7 +1384,7 @@ } static long -m10gifstat(Ether *e, void *v, long n, ulong off) +m10gifstat(Ether *e, void *v, long n, usize off) { char *p; int l, lim; @@ -1506,8 +1504,8 @@ default: error(Ebadarg); } - free(c); poperror(); + free(c); return n; } --- /sys/src/nix/k10/etherm10g.c Fri Feb 14 01:08:05 2014 +++ /sys/src/nix/k10/etherm10g.c Fri Feb 14 01:08:07 2014 @@ -1,6 +1,6 @@ /* * myricom 10 gbit ethernet - * © 2007—13 erik quanstrom, coraid, inc. + * © 2007—14 erik quanstrom, coraid, inc. */ #include "u.h" @@ -480,18 +480,18 @@ coherence(); memmove(c->ram + Cmdoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 15; i++){ if(cmd->i[1] != Noconf){ - poperror(); i = gbit32(cmd->c); qunlock(&c->cmdl); if(cmd->i[1] != 0) dprint("[%ux]", i); return i; } - tsleep(&up->sleep, return0, 0, 1); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); + } } qunlock(&c->cmdl); print("m10g: cmd timeout [%ux %ux] cmd=%d\n", cmd->i[0], cmd->i[1], type); @@ -518,18 +518,18 @@ coherence(); memmove(c->ram + Cmdoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 15; i++){ if(cmd->i[1] != Noconf){ - poperror(); i = gbit32(cmd->c); qunlock(&c->cmdl); if(cmd->i[1] != 0) dprint("[%ux]", i); return i; } - tsleep(&up->sleep, return0, 0, 1); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); + } } qunlock(&c->cmdl); print("m10g: maccmd timeout [%ux %ux] cmd=%d\n", cmd->i[0], cmd->i[1], type); @@ -560,17 +560,17 @@ coherence(); memmove(c->ram + Cmdoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 15; i++){ if(c->cmd->i[1] != Noconf){ i = gbit32(c->cmd->c); if(i == 0) error(Eio); - poperror(); return i; } - tsleep(&up->sleep, return0, 0, 5); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); + } } error(Etimeout); return ~0; @@ -593,14 +593,13 @@ prepcmd(buf, 6); memmove(c->ram + Rdmaoff, buf, sizeof buf); - if(waserror()) - nexterror(); for(i = 0; i < 20; i++){ - if(c->cmd->i[0] == Noconf){ - poperror(); + if(c->cmd->i[0] == Noconf) return gbit32(c->cmd->c); + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 1); + poperror(); } - tsleep(&up->sleep, return0, 0, 1); } error(Etimeout); print("m10g: rdmacmd timeout\n"); @@ -763,7 +762,6 @@ if(waserror()){ print("m10g: reset error\n"); nexterror(); - return -1; } chkfw(c); @@ -1355,8 +1353,8 @@ } c->state = Runed; m10ginterrupt(nil, e); /* botch: racy */ - qunlock(c); poperror(); + qunlock(c); } static int @@ -1510,8 +1508,8 @@ default: error(Ebadarg); } - free(c); poperror(); + free(c); return n; }