Thread (16 messages) 16 messages, 5 authors, 2024-10-07

Re: [PATCH v1] cleanup: adjust scoped_guard() to avoid potential warning

From: Andy Shevchenko <hidden>
Date: 2024-10-03 17:51:52
Also in: lkml

On Thu, Oct 03, 2024 at 04:12:21PM +0200, Peter Zijlstra wrote:
On Thu, Oct 03, 2024 at 03:46:24PM +0300, Andy Shevchenko wrote:
quoted
On Thu, Oct 03, 2024 at 03:43:17PM +0300, Andy Shevchenko wrote:
quoted
On Thu, Oct 03, 2024 at 01:39:06PM +0200, Przemek Kitszel wrote:
...
quoted
quoted
quoted
+#define __scoped_guard_labeled(_label, _name, args...)			\
+	for (CLASS(_name, scope)(args);					\
+	     __guard_ptr(_name)(&scope) || !__is_cond_ptr(_name);	\
+		     ({ goto _label; }))				\
+		if (0)							\
+		_label:							\
+			break;						\
+		else
I believe the following will folow more the style we use in the kernel:

#define __scoped_guard_labeled(_label, _name, args...)			\
	for (CLASS(_name, scope)(args);					\
	     __guard_ptr(_name)(&scope) || !__is_cond_ptr(_name);	\
		     ({ goto _label; }))				\
		if (0) {						\
_label:									\
			break;						\
		} else
Yeah, needs braces like that. I'm not super opposed to this, however, 
quoted
And FWIW:
1) still NAKed;
I would really like to understand why you don't like this; care to
elaborate Andy?
To me the idea of

int my_foo(...)
{
	NOT_my_foo_macro(...)
		return X;
}

is counter intuitive from C programming. Without knowing the magic behind the
scenes of NOT_my_foo_macro() I would eager to ask for adding a dead code like

int my_foo(...)
{
	NOT_my_foo_macro(...)
		return X;
	return 0;
}

What I would agree on is

int my_foo(...)
{
	return NOT_my_foo_macro(..., X);
}

Or just using guard()().

-- 
With Best Regards,
Andy Shevchenko

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help