lkml.org 
[lkml]   [2017]   [May]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] CodingStyle: delete "kmalloc(sizeof(*var))" as preferred allocation form
On Thu 2017-05-25 12:46:04, Bernd Petrovitsch wrote:
> 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).

Do we need new() macro that does all the magic internally?

If we have to provide "new and improved" malloc interface at least it should
be improved :-).
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

\
 
 \ /
  Last update: 2017-05-28 21:17    [W:0.051 / U:0.848 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site