All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Waiman Long <longman@redhat.com>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [PATCH 1/3] cleanup: provide DEFINE_LOCK_GUARD_ARGS()
Date: Wed, 10 Jan 2024 14:00:41 -0800	[thread overview]
Message-ID: <ZZ8TiS9S6aRmtjna@boqun-archlinux> (raw)
In-Reply-To: <20240110203215.36396-2-brgl@bgdev.pl>

On Wed, Jan 10, 2024 at 09:32:13PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> This macro allows defining lock guard with additional arguments that
> can be passed to the locking function. This is useful for implementing
> guards for nested locking.
> 
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
>  include/linux/cleanup.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h
> index c2d09bc4f976..921db45023bb 100644
> --- a/include/linux/cleanup.h
> +++ b/include/linux/cleanup.h
> @@ -246,5 +246,11 @@ __DEFINE_LOCK_GUARD_0(_name, _lock)
>  	static inline void * class_##_name##_ext##_lock_ptr(class_##_name##_t *_T) \
>  	{ return class_##_name##_lock_ptr(_T); }
>  
> +/*
> + * Helper for implementing guard locks with additional arguments passed to
> + * the locking function.
> + */
> +#define DEFINE_LOCK_GUARD_ARGS(_name, _type, _lock, _unlock, _args...)	\
> +DEFINE_CLASS(_name, _type, _unlock, ({ _lock; _T; }), _type _T, _args)
>  

First I think the name should really be DEFINE_GUARD_ARGS(), these
DEFINE_LOCK_GUARD_*() functions have different meaning. Also this should
really be a more generic case than DEFINE_GUARD(), so how about the
following:

diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h
index c2d09bc4f976..4fcdcb478fd1 100644
--- a/include/linux/cleanup.h
+++ b/include/linux/cleanup.h
@@ -148,11 +148,14 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \
  *
  */
 
-#define DEFINE_GUARD(_name, _type, _lock, _unlock) \
-	DEFINE_CLASS(_name, _type, if (_T) { _unlock; }, ({ _lock; _T; }), _type _T); \
+#define DEFINE_GUARD_ARGS(_name, _type, _lock, _unlock, _args...) \
+	DEFINE_CLASS(_name, _type, if (_T) { _unlock; }, ({ _lock; _T; }), _type _T, ##_args) \
 	static inline void * class_##_name##_lock_ptr(class_##_name##_t *_T) \
 	{ return *_T; }
 
+#define DEFINE_GUARD(_name, _type, _lock, _unlock) \
+	DEFINE_GUARD_ARGS(_name, _type, _lock, _unlock)
+
 #define DEFINE_GUARD_COND(_name, _ext, _condlock) \
 	EXTEND_CLASS(_name, _ext, \
 		     ({ void *_t = _T; if (_T && !(_condlock)) _t = NULL; _t; }), \

Thoughts?

Regards,
Boqun


>  #endif /* __LINUX_GUARDS_H */
> -- 
> 2.40.1
> 

  reply	other threads:[~2024-01-10 22:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10 20:32 [PATCH 0/3] cleanup: provide and use a locking guard for nested read semaphores Bartosz Golaszewski
2024-01-10 20:32 ` [PATCH 1/3] cleanup: provide DEFINE_LOCK_GUARD_ARGS() Bartosz Golaszewski
2024-01-10 22:00   ` Boqun Feng [this message]
2024-01-10 20:32 ` [PATCH 2/3] locking/rwsem: provide a lock guard for down_read_nested() Bartosz Golaszewski
2024-01-10 20:32 ` [PATCH 3/3] gpiolib: pin GPIO devices in place during descriptor lookup Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZZ8TiS9S6aRmtjna@boqun-archlinux \
    --to=boqun.feng@gmail.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.