Re: [PATCH] CodingStyle: delete "kmalloc(sizeof(*var))" as preferred allocation form

From: Bernd Petrovitsch
Date: Thu May 25 2017 - 07:31:34 EST


On Thu, 2017-05-25 at 03:35 -0700, Joe Perches wrote:
> On Wed, 2017-05-24 at 13:18 +0300, Alexey Dobriyan wrote:
> > Proper fix is to introduce typed allocation macros with the following
> > signatures:
> >
> > T* lmalloc(T, gfp);

Ack (FWIW).

[...]
> > ÂÂÂÂstruct foo *x;
> > ÂÂÂÂx = lmalloc(struct foo, GFP_KERNEL);
>
> Then code would be written
>
> x = lmalloc(typeof(*x), GFP_KERNEL);

At least it is correct and changes automagically if x changes the type
which
struct bar *x;
x = kmalloc(sizeof(struct foo), GFP_KERNEL);
doesn't do and the compiler doesn't complain.

And the typeof() version could be written that way today but I can't
remember seeing it (in the kernel and elsewhere).

MfG,
Bernd
--
Bernd Petrovitsch Email : bernd@xxxxxxxxxxxxxxxxxxx
LUGA : http://www.luga.at