On Thu, Mar 12, 2026 at 10:09 AM Luck, Tony <[email protected]> wrote:
>
> > > +       sbridge_dev->n_devs = table->n_devs_per_imc;
> > >
> > > Do you need this? I thought that kzalloc_flex() filled in the 
> > > __counted_by field of the structure for you.
> > kzalloc_flex is just a macro over kzalloc(struct_size()). It does not
> > do automatic __counted_by, which makes no sense.
>
> It is a fancy macro. But may be complier version dependent whether the count 
> is filled in.
>
> See include/linux/slab.h where kzalloc_flex() uses __alloc_flex() which looks 
> like this:
>
>
> #define __alloc_flex(KMALLOC, GFP, TYPE, FAM, COUNT)                    \
> ({                                                                      \
>         const size_t __count = (COUNT);                                 \
>         const size_t __obj_size = struct_size_t(TYPE, FAM, __count);    \
>         TYPE *__obj_ptr = KMALLOC(__obj_size, GFP);                     \
>         if (__obj_ptr)                                                  \
>                 __set_flex_counter(__obj_ptr->FAM, __count);            \
>         __obj_ptr;                                                      \
> })
>
>
> See the __set_flex_counter() ... looks like it is trying to set the 
> counted_by field.
/**
 * __set_flex_counter() - Set the counter associated with the given flexible
 *                        array member that has been annoated by __counted_by().
 * @FAM: Instance of flexible array member within a given struct.
 * @COUNT: Value to store to the __counted_by annotated @FAM_PTR's counter.
 *
 * This is a no-op if no annotation exists. Count needs to be checked with
 * overflows_flex_counter_type() before using this function.
 */
>
> -Tony
>
>

Reply via email to