Re: Clarifying confusion of our variable placement rules caused by cleanup.h
Linus Torvalds <[email protected]>
| Newsgroups | dev.linux.lists.ksummit,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAHk-=wh3pguds+vjKy81X2o0uJj+AhwpMu2=mf6jciQjEQ781Q@mail.gmail.com> |
On Tue, 18 Nov 2025 at 11:05, Bart Van Assche <[email protected]> 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