From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Andy Shevchenko <andriy.shevchenko@intel.com>,
Dan Carpenter <dan.carpenter@linaro.org>
Cc: <linux-kernel@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.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>
Subject: Re: [RFC PATCH v2] Simply enable one to write code like:
Date: Wed, 2 Oct 2024 11:55:45 +0200 [thread overview]
Message-ID: <a4efffb9-9c63-4cb1-94a3-050260fe0a81@intel.com> (raw)
In-Reply-To: <ZvwTZxN1F6X6Wd2i@google.com>
On 10/1/24 17:21, Dmitry Torokhov wrote:
> Hi Przemek,
>
> On Tue, Oct 01, 2024 at 04:57:18PM +0200, Przemek Kitszel wrote:
>> int foo(struct my_drv *adapter)
>> {
>> scoped_guard(spinlock, &adapter->some_spinlock)
>> return adapter->spinlock_protected_var;
>> }
>
> Could you change the subject to say something like:
>
> "Adjust cond_guard() implementation to avoid potential warnings"
>
> And then give detailed explanation in the body?
thanks, sure
(and apologies that I forgot to add any subject :F (this was just my
very first non-subject paragraph))
>
>>
>> Current scoped_guard() implementation does not support that,
>> due to compiler complaining:
>> error: control reaches end of non-void function [-Werror=return-type]
>>
>> One could argue that for such use case it would be better to use
>> guard(spinlock)(&adapter->some_spinlock), I disagree. I could also say
>> that coding with my proposed locking style is also very pleasant, as I'm
>> doing so for a few weeks already.
>
> I'd drop this paragraph from the patch description (and moved past "---"
> if you prefer to keep it for additional context.
I will think about that, especially given that since v2 this patch is
not only fixing "my case", but just it's regular hardening for static
analysis needs.
>> +#define DEFINE_CLASS_IS_CONDITIONAL(_name, _is_cond) \
>
> This is not supposed to be used outside of cleanup.h so probably
> __DEFINE_CLASS_IS_CONDITIONAL()?
indeed
>> +#define __scoped_guard_labeled(_label, _name, args...) \
>> + if (0) \
>> + _label: ; \
>> + else \
>> + for (CLASS(_name, scope)(args); \
>> + __guard_ptr(_name)(&scope) || !__is_cond_ptr(_name); \
>> + ({goto _label;}))
>
> The "jump back" throws me a little, do you think if can be rewritten as:
>
> if (true)
> for (...)
> else
> _label: /* dummy */ ;
user code must be glued at the end, so there must be "if (0) label:"
however I figured that you could reorder for and else:
for (
CLASS(...);
__guard_ptr(...) || __is_cond_ptr(...);
({ goto label; })
)
if (0)
label:
break;
else
// actual user code glued here
and this jumps forward
>
>>
>> #define scoped_cond_guard(_name, _fail, args...) \
>> for (CLASS(_name, scope)(args), \
>
> With your __is_cond_ptr() can this be made to warn or error if
> scoped_cond_guard() is used with a non-conditional lock/class? As that
> would make no sense.
good idea, thanks
next prev parent reply other threads:[~2024-10-02 9:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-01 14:57 [RFC PATCH v2] Simply enable one to write code like: Przemek Kitszel
2024-10-01 15:09 ` Andy Shevchenko
2024-10-02 8:07 ` Przemek Kitszel
2024-10-01 15:21 ` Dmitry Torokhov
2024-10-02 9:55 ` Przemek Kitszel [this message]
2024-10-01 15:29 ` Dan Carpenter
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=a4efffb9-9c63-4cb1-94a3-050260fe0a81@intel.com \
--to=przemyslaw.kitszel@intel.com \
--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=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nex.sw.ncis.osdt.itp.upstreaming@intel.com \
--cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox