Re: Clarifying confusion of our variable placement rules caused by cleanup.h
Bart Van Assche <[email protected]>
| Newsgroups | dev.linux.lists.ksummit,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On 11/18/25 8:39 AM, James Bottomley wrote:
> The problem specifically is this added comment in cleanup.h:
>
>> * That bug is fixed by changing init() to call guard() and define +
>> * initialize @obj in this order::
>> *
>> * guard(mutex)(&lock);
>> * struct object *obj __free(remove_free) = alloc_add();
>
> Which is recommending mixing declarations and code contrary to our
> prior rule. I note the rule against mixing variables and code was
> relaxed in the C99 standard (and in a lot of other languages), but
> we've never formally changed our coding rules.
>
> I'm not saying we have to stick with C89, just that if we change
> adherence to it, we should do so globally and document it because
> having incosistency for __free vs other variables really isn't a good
> idea.
A related question is whether or not to allow declarations in the
initialization expression of for-statements. Although some maintainers
reject patches that use this C99 feature, apparently this feature is
already used extensively:
$ git grep -nH 'for (int ' | grep -vE '^Documentation/|^tools/' | wc -l
1239
Thanks,
Bart.