From: Peter Zijlstra <peterz@infradead.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Przemek Kitszel <przemyslaw.kitszel@intel.com>,
linux-kernel@vger.kernel.org,
amadeuszx.slawinski@linux.intel.com,
Tony Nguyen <anthony.l.nguyen@intel.com>,
nex.sw.ncis.osdt.itp.upstreaming@intel.com,
netdev@vger.kernel.org, Markus Elfring <Markus.Elfring@web.de>,
Kees Cook <kees@kernel.org>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: [PATCH v1] cleanup: adjust scoped_guard() to avoid potential warning
Date: Fri, 4 Oct 2024 11:33:08 +0200 [thread overview]
Message-ID: <20241004093308.GI18071@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <Zv7ZsieITDle2lgl@smile.fi.intel.com>
On Thu, Oct 03, 2024 at 08:51:46PM +0300, Andy Shevchenko wrote:
> > 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;
> }
Well, this is kernel coding, we don't really do (std) C anymore, and
using *anything* without knowing the magic behind it is asking for fail.
Also, something like:
int my_foo()
{
for (;;)
return X;
}
or
int my_foo()
{
do {
return X;
} while (0);
}
is perfectly valid C that no compiler should be complaining about. Yes
its a wee bit daft, but if you want to write it, that's fine.
The point being that the compiler can determine there is no path not
hitting that return.
Apparently the current for loop is defeating the compiler, I see no
reason not to change it in such a way that the compiler is able to
determine wtf happens -- that can only help.
> What I would agree on is
>
> int my_foo(...)
> {
> return NOT_my_foo_macro(..., X);
> }
That just really won't work with things as they are ofcourse.
> Or just using guard()().
That's always an option. You don't *have* to use the -- to you -- weird
form.
next prev parent reply other threads:[~2024-10-04 9:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-03 11:39 [PATCH v1] cleanup: adjust scoped_guard() to avoid potential warning Przemek Kitszel
2024-10-03 12:34 ` Markus Elfring
2024-10-03 12:44 ` Andy Shevchenko
2024-10-03 16:00 ` Markus Elfring
2024-10-07 10:13 ` Przemek Kitszel
2024-10-07 10:46 ` Markus Elfring
2024-10-03 12:43 ` [PATCH v1] " Andy Shevchenko
2024-10-03 12:46 ` Andy Shevchenko
2024-10-03 13:38 ` Przemek Kitszel
2024-10-03 17:47 ` Andy Shevchenko
2024-10-03 14:12 ` Peter Zijlstra
2024-10-03 17:51 ` Andy Shevchenko
2024-10-04 9:33 ` Peter Zijlstra [this message]
2024-10-04 13:52 ` Andy Shevchenko
2024-10-03 13:00 ` Dmitry Torokhov
2024-10-03 13:42 ` Przemek Kitszel
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=20241004093308.GI18071@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Markus.Elfring@web.de \
--cc=amadeuszx.slawinski@linux.intel.com \
--cc=andriy.shevchenko@intel.com \
--cc=anthony.l.nguyen@intel.com \
--cc=dan.carpenter@linaro.org \
--cc=dmitry.torokhov@gmail.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nex.sw.ncis.osdt.itp.upstreaming@intel.com \
--cc=przemyslaw.kitszel@intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox