git: 9front

Download patch

ref: 1e0f61fbb332c08a643855c49bf0c00992b9afbb
parent: cd434df700c9136aba260c6b2467a46056db4281
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Mar 15 13:46:49 EDT 2026

kernel: make qiwrite() handle bypass, make local copy of q->bypass before nil check

The qiwrite() function was not handling bypass,
it should.

The bypass function can become nil, so make a
local copy of q->bypass pointer and do nil
check on that instead.

--- a/sys/src/9/port/qio.c
+++ b/sys/src/9/port/qio.c
@@ -1019,12 +1019,13 @@
 long
 qbwrite(Queue *q, Block *b)
 {
+	void (*bypass)(void*, Block*);
 	Flow flow;
 	int len;
 
-	if(q->bypass != nil){
+	if((bypass = q->bypass) != nil){
 		len = blocklen(b);
-		(*q->bypass)(q->arg, b);
+		(*bypass)(q->arg, b);
 		return len;
 	}
 
@@ -1144,6 +1145,7 @@
 int
 qiwrite(Queue *q, void *vp, int len)
 {
+	void (*bypass)(void*, Block*);
 	int n, sofar;
 	Block *b;
 	uchar *p = vp;
@@ -1161,6 +1163,12 @@
 			break;
 		memmove(b->wp, p+sofar, n);
 		b->wp += n;
+
+		if((bypass = q->bypass) != nil){
+			sofar += n;
+			(*bypass)(q->arg, b);
+			continue;
+		}
 
 		ilock(q);
 		if(q->state & (Qflow|Qclosed)){
--