Re: [PATCH] Documentation: adopt new coding style of type-aware kmalloc-family

From: Manuel Ebner

Date: Sun Apr 19 2026 - 07:34:17 EST


On Sun, 2026-04-19 at 04:29 -0600, Jonathan Corbet wrote:
> Manuel Ebner <manuelebner@xxxxxxxxxxx> writes:
>
> > Update the documentation to reflect new type-aware kmalloc-family as
> > suggested in commit 2932ba8d9c99 ("slab: Introduce kmalloc_obj() and
> > family")
> >
> > ptr = kmalloc(sizeof(*ptr), gfp);
> >  -> ptr = kmalloc_obj(*ptr, gfp);
> > ptr = kmalloc(sizeof(struct some_obj_name), gfp);
> >  -> ptr = kmalloc_obj(*ptr, gfp);
> > ptr = kzalloc(sizeof(*ptr), gfp);
> >  -> ptr = kzalloc_obj(*ptr, gfp);
> > ptr = kmalloc_array(count, sizeof(*ptr), gfp);
> >  -> ptr = kmalloc_objs(*ptr, count, gfp);
> > ptr = kcalloc(count, sizeof(*ptr), gfp);
> >  -> ptr = kzalloc_objs(*ptr, count, gfp);
> >
> > Signed-off-by: Manuel Ebner <manuelebner@xxxxxxxxxxx>
>
> Just to be sure, did you write this patch yourself, or did you use some
> sort of coding assistant?

I wrote the patch myself.

> Adding Kees, who did this work and might have something to add here.

Thanks.


> > ---
> >  .../RCU/Design/Requirements/Requirements.rst         |  6 +++---
> >  Documentation/RCU/listRCU.rst                        |  2 +-
> >  Documentation/RCU/whatisRCU.rst                      |  4 ++--
>
> This patch will surely need to be split up; the RCU folks, for example,
> will want to evaluate the change separately.

will do that in [v2]

>
> >  Documentation/core-api/kref.rst                      |  4 ++--
> >  Documentation/core-api/list.rst                      |  4 ++--
> >  Documentation/core-api/memory-allocation.rst         |  4 ++--
> >  Documentation/driver-api/mailbox.rst                 |  4 ++--
> >  Documentation/driver-api/media/v4l2-fh.rst           |  2 +-
> >  Documentation/kernel-hacking/locking.rst             |  4 ++--
> >  Documentation/locking/locktypes.rst                  |  4 ++--
> >  Documentation/process/coding-style.rst               |  8 ++++----
> >  .../sound/kernel-api/writing-an-alsa-driver.rst      | 12 ++++++------
> >  Documentation/spi/spi-summary.rst                    |  4 ++--
> >  .../translations/it_IT/kernel-hacking/locking.rst    |  4 ++--
> >  .../translations/it_IT/locking/locktypes.rst         |  4 ++--
> >  .../translations/it_IT/process/coding-style.rst      |  2 +-
> >  .../translations/sp_SP/process/coding-style.rst      |  2 +-
> >  Documentation/translations/zh_CN/core-api/kref.rst   |  4 ++--
> >  .../translations/zh_CN/process/coding-style.rst      |  2 +-
> >  .../zh_CN/video4linux/v4l2-framework.txt             |  2 +-
> >  .../translations/zh_TW/process/coding-style.rst      |  2 +-
> >  21 files changed, 42 insertions(+), 42 deletions(-)
> >
> > diff --git a/Documentation/RCU/Design/Requirements/Requirements.rst
> > b/Documentation/RCU/Design/Requirements/Requirements.rst
> > index b5cdbba3ec2e..faca5a9c8c12 100644
> > --- a/Documentation/RCU/Design/Requirements/Requirements.rst
> > +++ b/Documentation/RCU/Design/Requirements/Requirements.rst
> > @@ -206,7 +206,7 @@ non-\ ``NULL``, locklessly accessing the ``->a`` and ``-
> > >b`` fields.
> >  
> >         1 bool add_gp_buggy(int a, int b)
> >         2 {
> > -       3   p = kmalloc(sizeof(*p), GFP_KERNEL);
> > +       3   p = kmalloc_obj(*p, GFP_KERNEL);
>
> So you have not gone with the "implicit GFP_KERNEL" approach that Linus
> added.  Given that, I assume, he wanted that to be the normal style, we
> should probably go with it.

I scanned those 8 replies by Linus, but i can't figure out what you mean with
implicit GFP_Kernel approach, can you give me a hint?

https://lore.kernel.org/all/?q=slab%3A+Introduce+kmalloc_obj%28%29+and+family+f%3Atorvalds

> Thanks,
>
> jon

Thanks,

manuel