[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wh3pguds+vjKy81X2o0uJj+AhwpMu2=mf6jciQjEQ781Q@mail.gmail.com>
Date: Tue, 18 Nov 2025 11:14:21 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Bart Van Assche <bvanassche@....org>
Cc: James Bottomley <James.Bottomley@...senpartnership.com>, ksummit@...ts.linux.dev,
Dan Williams <dan.j.williams@...el.com>, linux-kernel <linux-kernel@...r.kernel.org>,
Dan Carpenter <dan.carpenter@...aro.org>
Subject: Re: Clarifying confusion of our variable placement rules caused by cleanup.h
On Tue, 18 Nov 2025 at 11:05, Bart Van Assche <bvanassche@....org> wrote:
>
> In a C++ style guide I found the following advice for type deduction:
>
> "Use type deduction only if it makes the code clearer to readers who
> aren't familiar with the project, or if it makes the code safer. Do not
> use it merely to avoid the inconvenience of writing an explicit type."
I don't think that's a bad rule, no. I don't think we should encourage
people to switch to automatic types just because they can, but I do
think there are situations where it makes sense and makes the code
simpler.
As mentioned, most of our automatic types currently are hidden in
helper macros. I think it typically works best in those, where you
effectively make them type-agnostic.
But I do think it also makes sense in various allocation scenarios,
where just repeating the same type multiple times adds no real upside.
It's not exactly uncommon to have code like this:
struct xyz *abc = kzalloc(sizeof(struct xyz), GPF_KERNEL);
and I don't think there's any actual *value* in stating that "struct
xyz" twice (or in stating the sizeof()).
Again: I don't think we should *push* people to do this, but I think
it's a reasonable thing to allow. And it's a situation where having
the declaration in the middle of the code really does make sense.
Linus
Powered by blists - more mailing lists