Messages in this thread | | | From | Denis Vlasenko <> | Subject | Re: p = kmalloc(sizeof(*p), ) | Date | Tue, 20 Sep 2005 14:56:04 +0300 |
| |
> > > p = kmalloc(sizeof(*p), ...) > > > > > > is not grep-friendly, and can not be used to identify potential > > > initialisation sites. However: > > > > > > p = kmalloc(sizeof(struct foo), ...) > > > > > > is grep-friendly, and will lead you to inspect each place where > > > such a structure is allocated for correct initialisation. > > > > I would disagree on this one. You can still grep all the places where > > the local variable is declared in. Furthermore, structs are not always > > initialized where they're kmalloc'd so you need to manually inspect > > anyway. > > Think about it some more. You've added a new member to struct foo. > You want to fix up all the places which allocate struct foo to > initialise this new member. Grepping for 'struct foo' returns 100 > files. Grepping for kmalloc in those 100 files returns 100 files. > > Do you open all 100 in an editor and manually try and locate the five > kmalloc instances of this structure, and end up missing some. > > Or do you do the sane thing and use kmalloc(sizeof(struct foo), ...) > and grep for "kmalloc[[:space:]]*(sizeof[[:space:]]*(struct foo)" > which returns only the five files and fix those up with knowledge > that you've found all the instances?
Both are inferior to Alans macro
p = typed_kmalloc(struct foo, ...);
which has greppable struct name, saves typing sizeof() and also gives you typechecking (fails with "pointers to different types" if p is not struct foo*). -- vda - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |