shithub: riscv

Download patch

ref: ff03b72ed5f365a2ca052218e055fac678cf0e23
parent: 0b3fd7c05208b6de625bb0b4d1719b9fd22156ae
author: cinap_lenrek <[email protected]>
date: Thu Jul 23 18:05:46 EDT 2015

devaoe: more nil vs. 0

--- a/sys/src/9/port/devaoe.c
+++ b/sys/src/9/port/devaoe.c
@@ -542,7 +542,7 @@
 	l = pickdevlink(d);
 	i = pickea(l);
 	if(i == -1){
-		if(!(cmd == ACata && f->srb && Nofail(d, s)))
+		if(!(cmd == ACata && f->srb != nil && Nofail(d, s)))
 			downdev(d, "resend fails; no netlink/ea");
 		return -1;
 	}
@@ -1238,7 +1238,7 @@
 		if(write && !copy)
 			memmove(srb->data, db, n);
 		strategy(d, srb);
-		if(srb->error)
+		if(srb->error != nil)
 			error(srb->error);
 		if(!write && !copy)
 			memmove(db, srb->data, n);
@@ -1970,7 +1970,7 @@
 		srb = f->srb;
 		f->dp = nil;
 		f->srb = nil;
-		if(srb){
+		if(srb != nil){
 			srb->nout--;
 			srbwakeup(srb);
 			d->nout--;
@@ -2133,7 +2133,7 @@
 	if(ahin->cmdstat & 0xa9){
 		eventlog("%æ: ata error cmd %.2ux stat %.2ux\n",
 			d, ahout->cmdstat, ahin->cmdstat);
-		if(srb)
+		if(srb != nil)
 			srb->error = Eio;
 	} else {
 		n = ahout->scnt * Aoesectsz;
@@ -2174,7 +2174,7 @@
 	}
 
 	f->srb = nil;
-	if(srb){
+	if(srb != nil){
 		srb->nout--;
 		srbwakeup(srb);
 	}
--- a/sys/src/9/port/sdaoe.c
+++ b/sys/src/9/port/sdaoe.c
@@ -85,20 +85,16 @@
 {
 	Chan *c;
 
-	c = nil;
+	uprint("%s/ctl", d->path);
+	c = namec(up->genbuf, Aopen, OWRITE, 0);
 	if(waserror()){
-		if(c)
-			cclose(c);
 		print("sdaoectl: %s\n", up->errstr);
+		cclose(c);
 		nexterror();
 	}
-
-	uprint("%s/ctl", d->path);
-	c = namec(up->genbuf, Aopen, OWRITE, 0);
 	devtab[c->type]->write(c, s, strlen(s), 0);
-
-	poperror();
 	cclose(c);
+	poperror();
 }
 
 /* must call with d qlocked */
@@ -107,20 +103,16 @@
 {
 	Chan *c;
 
-	c = nil;
+	uprint("%s/ident", d->path);
+	c = namec(up->genbuf, Aopen, OREAD, 0);
 	if(waserror()){
-		if(c)
-			cclose(c);
 		iprint("aoeidentify: %s\n", up->errstr);
+		cclose(c);
 		nexterror();
 	}
-
-	uprint("%s/ident", d->path);
-	c = namec(up->genbuf, Aopen, OREAD, 0);
 	devtab[c->type]->read(c, d->ident, sizeof d->ident, 0);
-
-	poperror();
 	cclose(c);
+	poperror();
 
 	d->feat = 0;
 	identify(d, (ushort*)d->ident);
@@ -140,7 +132,7 @@
 	Ctlr *c;
 
 	lock(&ctlrlock);
-	for(c = head; c; c = c->next)
+	for(c = head; c != nil; c = c->next)
 		if(strcmp(c->path, path) == 0)
 			break;
 	unlock(&ctlrlock);
@@ -175,15 +167,15 @@
 
 	lock(&ctlrlock);
 
-	for(prev = 0, x = head; x; prev = x, x = c->next)
+	for(prev = 0, x = head; x != nil; prev = x, x = c->next)
 		if(strcmp(c->path, x->path) == 0)
 			break;
-	if(x == 0){
+	if(x == nil){
 		unlock(&ctlrlock);
 		error(Enonexist);
 	}
 
-	if(prev)
+	if(prev != nil)
 		prev->next = x->next;
 	else
 		head = x->next;
@@ -191,7 +183,7 @@
 		tail = prev;
 	unlock(&ctlrlock);
 
-	if(x->c)
+	if(x->c != nil)
 		cclose(x->c);
 	free(x);
 }
@@ -204,12 +196,11 @@
 	Chan *c;
 	Ctlr *ctlr;
 
-	if((p = strrchr(path, '/')) == 0)
+	if((p = strrchr(path, '/')) == nil)
 		error(Ebadarg);
 	*p = 0;
 	uprint("%s/ctl", path);
 	*p = '/';
-
 	c = namec(up->genbuf, Aopen, OWRITE, 0);
 	if(waserror()) {
 		cclose(c);
@@ -217,8 +208,8 @@
 	}
 	n = uprint("discover %s", p+1);
 	devtab[c->type]->write(c, up->genbuf, n, 0);
-	poperror();
 	cclose(c);
+	poperror();
 
 	for(i = 0;; i += Probeintvl){
 		if(i > Probemax || waserror())
@@ -256,7 +247,7 @@
 	char *p;
 	SDev *h, *t, *s;
 
-	if((p = getconf("aoedev")) == 0)
+	if((p = getconf("aoedev")) == nil)
 		return 0;
 	kstrdup(&probebuf, p);
 	nprobe = tokenize(probebuf, probef, nelem(probef));