Re: [PATCH v6 1/5] slab: Introduce kmalloc_obj() and family

Dan Carpenter
2026-02-19T08:24:13Z

On Thu, Feb 19, 2026 at 11:01:04AM +0300, Dan Carpenter wrote:
> On Wed, Dec 03, 2025 at 03:30:31PM -0800, Kees Cook wrote:
> > Introduce type-aware kmalloc-family helpers to replace the common
> > idioms for single object and arrays of objects allocation:
> >
> > ptr = kmalloc(sizeof(*ptr), gfp);
> > ptr = kmalloc(sizeof(struct some_obj_name), gfp);
> > ptr = kzalloc(sizeof(*ptr), gfp);
> > ptr = kmalloc_array(count, sizeof(*ptr), gfp);
> > ptr = kcalloc(count, sizeof(*ptr), gfp);
> >
> > These become, respectively:
> >
> > ptr = kmalloc_obj(*ptr, gfp);
>
> We are already getting patches that covert these to:
>
> ptr = kmalloc_obj(ptr, gfp);
>
> (without the *). This feels like the obvious bug people will introduce
> with this API. I sort of think that "ptr = kmalloc_obj(ptr, gfp);" is
> more natural, so maybe we could make it work that way instead?

Never mind. It causes a compile error when people leave out the
asterisk. Thanks for that.

regards,
dan carpenter