git: b72397da275b - main - kern_filewrite(): unconditionally calculate cnt, it is used by callers

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 08 Jul 2026 17:01:24 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=b72397da275b098365532133688d555b842bad4f

commit b72397da275b098365532133688d555b842bad4f
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-07-08 14:54:25 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-07-08 17:01:09 +0000

    kern_filewrite(): unconditionally calculate cnt, it is used by callers
    
    Reported by:    dhw, madpilot
    Tested by:      dhw
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Fixes:  dfad790c8cca ("sendfile: stop abusing kern_writev()")
---
 sys/kern/sys_generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index 079bd7b347d7..d5145d6cf322 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -595,9 +595,9 @@ kern_filewrite(struct thread *td, int fd, struct file *fp, struct uio *auio,
 #endif
 	cnt = auio->uio_resid;
 	error = fo_write(fp, auio, td->td_ucred, flags, td);
+	cnt -= auio->uio_resid;
 #ifdef KTRACE
 	if (ktruio != NULL) {
-		cnt -= auio->uio_resid;
 		if (error == 0)
 			ktruio->uio_resid = cnt;
 		ktrgenio(fd, UIO_WRITE, ktruio, error);