Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1650363 > unrolled thread

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

Started byJoe Perches <joe@perches.com>
First post2017-05-25 12:40 +0200
Last post2017-05-28 21:20 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] CodingStyle: delete "kmalloc(sizeof(*var))" as  preferred allocation form Joe Perches <joe@perches.com> - 2017-05-25 12:40 +0200
    Re: [PATCH] CodingStyle: delete "kmalloc(sizeof(*var))" as  preferred allocation form Bernd Petrovitsch <bernd@petrovitsch.priv.at> - 2017-05-25 13:40 +0200
      Re: [PATCH] CodingStyle: delete "kmalloc(sizeof(*var))" as preferred  allocation form Pavel Machek <pavel@ucw.cz> - 2017-05-28 21:20 +0200

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

FromJoe Perches <joe@perches.com>
Date2017-05-25 12:40 +0200
SubjectRe: [PATCH] CodingStyle: delete "kmalloc(sizeof(*var))" as preferred allocation form
Message-ID<tKYlr-70D-3@gated-at.bofh.it>
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);
[]
>     struct foo *x;
>     x = lmalloc(struct foo, GFP_KERNEL);

Then code would be written

	x = lmalloc(typeof(*x), GFP_KERNEL);

[toc] | [next] | [standalone]


#1650390

FromBernd Petrovitsch <bernd@petrovitsch.priv.at>
Date2017-05-25 13:40 +0200
Message-ID<tKZhw-7An-23@gated-at.bofh.it>
In reply to#1650363
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@petrovitsch.priv.at
                     LUGA : http://www.luga.at

[toc] | [prev] | [next] | [standalone]


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

FromPavel Machek <pavel@ucw.cz>
Date2017-05-28 21:20 +0200
SubjectRe: [PATCH] CodingStyle: delete "kmalloc(sizeof(*var))" as preferred allocation form
Message-ID<tMbTj-66f-7@gated-at.bofh.it>
In reply to#1650390
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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web