git: 1e01650a7870 - main - kcmp_pget(): add an assert that we did not hold the current process

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 30 Apr 2024 07:07:24 UTC
The branch main has been updated by kib:

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

commit 1e01650a787028fd558e8cb709c232e335fc2cd9
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-04-29 18:51:53 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-04-30 07:06:52 +0000

    kcmp_pget(): add an assert that we did not hold the current process
    
    Tested by:      pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
---
 sys/kern/sys_generic.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index b926f98892a5..cc1126ac4dc4 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -2092,11 +2092,15 @@ kcmp_cmp(uintptr_t a, uintptr_t b)
 static int
 kcmp_pget(struct thread *td, pid_t pid, struct proc **pp)
 {
+	int error;
+
 	if (pid == td->td_proc->p_pid) {
 		*pp = td->td_proc;
 		return (0);
 	}
-	return (pget(pid, PGET_CANDEBUG | PGET_NOTWEXIT | PGET_HOLD, pp));
+	error = pget(pid, PGET_CANDEBUG | PGET_NOTWEXIT | PGET_HOLD, pp);
+	MPASS(*pp != td->td_proc);
+	return (error);
 }
 
 int