git: f4f09d270c1d - stable/14 - linuxkpi: rwlock: Simplify code

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Tue, 04 Jun 2024 11:35:31 UTC
The branch stable/14 has been updated by manu:

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

commit f4f09d270c1df58334accb94aadb89fb0f4b9f09
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2024-05-15 09:05:29 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2024-06-04 11:23:11 +0000

    linuxkpi: rwlock: Simplify code
    
    Just use a typedef for rwlock_t, no need to create a useless
    structure.
    
    Reviewed by:            bz
    Sponsored by:           Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D45206
    
    (cherry picked from commit 5c0a1923486e65cd47398e52c03cb289d6120a78)
    
    linuxkpi: rwlock: Fix rwlock_init
    
    Some linux code re-init some spinlock so add MTX_NEW to mtx_init.
    
    Reported by:    rlibby
    Fixes:          5c0a1923486e ("linuxkpi: rwlock: Simplify code")
    
    (cherry picked from commit a7b222db122e99f587d87eeec303c8abc9aea04e)
---
 sys/compat/linuxkpi/common/include/linux/rwlock.h | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/rwlock.h b/sys/compat/linuxkpi/common/include/linux/rwlock.h
index 8c1ee36ac4de..3030ec89ff1e 100644
--- a/sys/compat/linuxkpi/common/include/linux/rwlock.h
+++ b/sys/compat/linuxkpi/common/include/linux/rwlock.h
@@ -34,14 +34,12 @@
 #include <sys/rwlock.h>
 #include <sys/libkern.h>
 
-typedef struct {
-	struct rwlock rw;
-} rwlock_t;
+typedef struct rwlock rwlock_t;
 
-#define	read_lock(_l)		rw_rlock(&(_l)->rw)
-#define	write_lock(_l)		rw_wlock(&(_l)->rw)
-#define	read_unlock(_l)		rw_runlock(&(_l)->rw)
-#define	write_unlock(_l)	rw_wunlock(&(_l)->rw)
+#define	read_lock(_l)		rw_rlock(_l)
+#define	write_lock(_l)		rw_wlock(_l)
+#define	read_unlock(_l)		rw_runlock(_l)
+#define	write_unlock(_l)	rw_wunlock(_l)
 #define	read_lock_irq(lock)	read_lock((lock))
 #define	read_unlock_irq(lock)	read_unlock((lock))
 #define	write_lock_irq(lock)	write_lock((lock))
@@ -54,13 +52,6 @@ typedef struct {
     do { read_unlock(lock); } while (0)
 #define	write_unlock_irqrestore(lock, flags)				\
     do { write_unlock(lock); } while (0)
-
-static inline void
-rwlock_init(rwlock_t *lock)
-{
-
-	memset(&lock->rw, 0, sizeof(lock->rw));
-	rw_init_flags(&lock->rw, "lnxrw", RW_NOWITNESS);
-}
+#define	rwlock_init(_l)	rw_init_flags(_l, "lnxrw", RW_NOWITNESS | RW_NEW)
 
 #endif	/* _LINUXKPI_LINUX_RWLOCK_H_ */