git: 452f4636c3ba - main - linux(4): Return ENOTSUP for unsupported clockid

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Tue, 31 May 2022 08:59:36 UTC
The branch main has been updated by dchagin:

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

commit 452f4636c3ba1f51f2f549ccc31fd4177254fb6d
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2022-05-31 08:43:00 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2022-05-31 08:43:00 +0000

    linux(4): Return ENOTSUP for unsupported clockid
    
    It's much better from the user perspective to get a sane error code.
    
    MFC after:              2 weeks
---
 sys/compat/linux/linux_time.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/sys/compat/linux/linux_time.c b/sys/compat/linux/linux_time.c
index 0be7025abe05..5d2269190931 100644
--- a/sys/compat/linux/linux_time.c
+++ b/sys/compat/linux/linux_time.c
@@ -278,8 +278,11 @@ linux_to_native_clockid(clockid_t *n, clockid_t l)
 
 	if (l < 0) {
 		/* cpu-clock */
-		if ((l & LINUX_CLOCKFD_MASK) == LINUX_CLOCKFD)
-			return (EINVAL);
+		if (LINUX_CPUCLOCK_WHICH(l) == LINUX_CLOCKFD) {
+			LIN_SDT_PROBE1(time, linux_to_native_clockid,
+			    unsupported_clockid, l);
+			return (ENOTSUP);
+		}
 		if (LINUX_CPUCLOCK_WHICH(l) >= LINUX_CPUCLOCK_MAX)
 			return (EINVAL);
 
@@ -319,11 +322,11 @@ linux_to_native_clockid(clockid_t *n, clockid_t l)
 	case LINUX_CLOCK_TAI:
 		LIN_SDT_PROBE1(time, linux_to_native_clockid,
 		    unsupported_clockid, l);
-		return (EINVAL);
+		return (ENOTSUP);
 	default:
 		LIN_SDT_PROBE1(time, linux_to_native_clockid,
 		    unknown_clockid, l);
-		return (EINVAL);
+		return (ENOTSUP);
 	}
 
 	return (0);