shithub: riscv

Download patch

ref: 04d6a2acecfe4fe44947da8b676f63bcd0f3c0fe
parent: 8e3abc0cce6d52ebf9195ea277a6dbd92ba497a1
author: cinap_lenrek <[email protected]>
date: Sun Nov 12 16:49:07 EST 2023

devuart: fix wrong opens count in case of uartenable() error

--- a/sys/src/9/port/devuart.c
+++ b/sys/src/9/port/devuart.c
@@ -143,10 +143,11 @@
 
 	p = uartport(which);
 	qlock(p);
-	if(p->opens++ == 0 && uartenable(p) == nil){
+	if(p->opens == 0 && uartenable(p) == nil){
 		qunlock(p);
 		error(Enodev);
 	}
+	p->opens++;
 	if(setb1200)
 		uartctl(p, "b1200");
 	p->putc = putc;
@@ -321,11 +322,12 @@
 	case Ndataqid:
 		p = uart[NETID(c->qid.path)];
 		qlock(p);
-		if(p->opens++ == 0 && uartenable(p) == nil){
+		if(p->opens == 0 && uartenable(p) == nil){
 			qunlock(p);
 			c->flag &= ~COPEN;
 			error(Enodev);
 		}
+		p->opens++;
 		qunlock(p);
 		break;
 	}