[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <e6fabaa541704463804f48b5931e8a43f7ee75eb.camel@sipsolutions.net>
Date: Wed, 27 Mar 2024 22:43:33 +0100
From: Johannes Berg <johannes@...solutions.net>
To: Jakub Sitnicki <jakub@...udflare.com>
Cc: Jakub Kicinski <kuba@...nel.org>, netdev@...r.kernel.org, Peter Zijlstra
	 <peterz@...radead.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 0/3] using guard/__free in networking
On Wed, 2024-03-27 at 22:28 +0100, Johannes Berg wrote:
> 
> +typedef struct class_##_name##_drop##_t {				\
> +	class_##_name##_t obj;						\
> +	void (*destructor)(struct class_##_name##_drop##_t *);		\
> +} class_##_name##_drop##_t;						\
No, I misread the compiler output, it does output a real destructor
function to push it into a stack variable with this...
So I guess it'd have to be
void my_something(my_t *my)
{
..
	named_guard(lock, mutex)(&my->mutex);
..
	if (foo)
		return -EINVAL; // automatically unlocks
..
	// no need for lock any more
	drop_guard(lock, mutex);
..
	// do other things now unlocked
}
instead, syntax-wise.
Which obviously simplifies the changes:
diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h
index c2d09bc4f976..cf39a4a3f56f 100644
--- a/include/linux/cleanup.h
+++ b/include/linux/cleanup.h
@@ -163,6 +163,12 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \
 #define guard(_name) \
 	CLASS(_name, __UNIQUE_ID(guard))
 
+#define named_guard(_name, _class) \
+	CLASS(_class, _name)
+
+#define drop_guard(_name, _class) \
+	do { class_##_class##_destructor(&_name); _name = NULL; } while (0)
+
 #define __guard_ptr(_name) class_##_name##_lock_ptr
 
 #define scoped_guard(_name, args...)					\
Powered by blists - more mailing lists