git: bd0b4de28d6b - stable/13 - LinuxKPI: uuid: add guid_gen() and guid_copy()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Mon, 26 Jun 2023 12:08:56 UTC
The branch stable/13 has been updated by bz:

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

commit bd0b4de28d6b1fb598b0e2bd5f3713ac427cbda7
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2023-05-23 23:15:12 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2023-06-26 09:20:27 +0000

    LinuxKPI: uuid: add guid_gen() and guid_copy()
    
    Add function used by a wireless driver.
    
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    emaste
    Differential Revision: https://reviews.freebsd.org/D40249
    
    (cherry picked from commit c1b6e9121e889608b86530d1a37047797dfeb460)
---
 sys/compat/linuxkpi/common/include/linux/uuid.h | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/uuid.h b/sys/compat/linuxkpi/common/include/linux/uuid.h
index 31a018497f78..63b77dd7d0bc 100644
--- a/sys/compat/linuxkpi/common/include/linux/uuid.h
+++ b/sys/compat/linuxkpi/common/include/linux/uuid.h
@@ -1,7 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
  *
- * Copyright (c) 2021 The FreeBSD Foundation
+ * Copyright (c) 2021,2023 The FreeBSD Foundation
  *
  * This software was developed by Björn Zeeb under sponsorship from
  * the FreeBSD Foundation.
@@ -33,6 +33,8 @@
 #ifndef	_LINUXKPI_LINUX_UUID_H
 #define	_LINUXKPI_LINUX_UUID_H
 
+#include <linux/random.h>
+
 #define	UUID_STRING_LEN	36
 
 #define	GUID_INIT(x0_3, x4_5, x6_7, x8, x9, x10, x11, x12, x13, x14, x15) \
@@ -59,4 +61,19 @@ typedef struct {
 	char	x[16];
 } guid_t;
 
+static inline void
+guid_gen(guid_t *g)
+{
+
+	get_random_bytes(g, 16);
+	g->x[7] = (g->x[7] & 0x0f) | 0x40;
+	g->x[8] = (g->x[8] & 0x3f) | 0x80;
+}
+
+static inline void
+guid_copy(guid_t *dst, const guid_t *src)
+{
+	memcpy(dst, src, sizeof(*dst));
+}
+
 #endif	/* _LINUXKPI_LINUX_UUID_H */