git: 63c7a483e552 - main - kboot: Assert errno is negative

From: Warner Losh <imp_at_FreeBSD.org>
Date: Thu, 02 Feb 2023 21:11:52 UTC
The branch main has been updated by imp:

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

commit 63c7a483e55274a824e564e308215cc0f0aee6aa
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-02-02 21:08:03 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-02-02 21:09:55 +0000

    kboot: Assert errno is negative
    
    When converting from a Linux error to a FreeBSD errno, assert that the
    value passed in is negative, as is Linux's custom.
    
    Suggested by:           brooks
    Sponsored by:           Netflix
    Reviewed by:            tsoome, brooks
    Differential Revision:  https://reviews.freebsd.org/D38357
---
 stand/kboot/host_syscall.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/stand/kboot/host_syscall.h b/stand/kboot/host_syscall.h
index 75394afcde6c..64288f48e6f0 100644
--- a/stand/kboot/host_syscall.h
+++ b/stand/kboot/host_syscall.h
@@ -29,6 +29,7 @@
 #define _HOST_SYSCALL_H
 
 #include <stand.h>
+#include <assert.h>
 
 long host_syscall(int number, ...);
 
@@ -214,6 +215,12 @@ ssize_t host_write(int fd, const void *buf, size_t nbyte);
  * function where -1 to -34 are translated to 1 to 34 and all others are EINVAL.
  * Pass the linux return value, which will be the -errno.
  */
-#define host_to_stand_errno(e)	((-e) > 34 ? EINVAL : (-e))
+static __inline int
+host_to_stand_errno(int e)
+{
+	assert(e < 0);
+
+	return((-e) > 34 ? EINVAL : (-e));
+}
 
 #endif