git: a108252a712a - stable/13 - LinuxKPI: lockdep add lockdep_assert_not_held()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sun, 20 Feb 2022 18:15:43 UTC
The branch stable/13 has been updated by bz:

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

commit a108252a712aec9ed2cc4bdbdd76d45d253fd3ea
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-02-09 12:01:32 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-02-20 16:25:03 +0000

    LinuxKPI: lockdep add lockdep_assert_not_held()
    
    Add lockdep_assert_not_held() asserting LA_UNLOCKED as needed by a
    driver.
    
    Reviewed by:    hselasky
    Differential Revision: https://reviews.freebsd.org/D34232
    
    (cherry picked from commit 064c110f4b551cbf3f2ef6f567736005c2d7007a)
---
 sys/compat/linuxkpi/common/include/linux/lockdep.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/lockdep.h b/sys/compat/linuxkpi/common/include/linux/lockdep.h
index a801f2c2bbac..66bda709606e 100644
--- a/sys/compat/linuxkpi/common/include/linux/lockdep.h
+++ b/sys/compat/linuxkpi/common/include/linux/lockdep.h
@@ -50,6 +50,11 @@ struct pin_cookie {
 #define	lockdep_init_map(_map, _name, _key, _x) do { } while(0)
 
 #ifdef INVARIANTS
+#define	lockdep_assert_not_held(m) do {					\
+	struct lock_object *__lock = (struct lock_object *)(m);		\
+	LOCK_CLASS(__lock)->lc_assert(__lock, LA_UNLOCKED);		\
+} while (0)
+
 #define	lockdep_assert_held(m) do {					\
 	struct lock_object *__lock = (struct lock_object *)(m);		\
 	LOCK_CLASS(__lock)->lc_assert(__lock, LA_LOCKED);		\
@@ -72,6 +77,7 @@ lockdep_is_held(void *__m)
 #define	lockdep_is_held_type(_m, _t) lockdep_is_held(_m)
 
 #else
+#define	lockdep_assert_not_held(m) do { (void)(m); } while (0)
 #define	lockdep_assert_held(m) do { (void)(m); } while (0)
 
 #define	lockdep_assert_held_once(m) do { (void)(m); } while (0)