Re: [PATCH] bcachefs: Annotate bch_replicas_entry_{v0,v1} with __counted_by()

From: Kent Overstreet
Date: Sun Aug 25 2024 - 18:56:58 EST


On Sun, Aug 25, 2024 at 10:41:55PM GMT, Thorsten Blum wrote:
> On 25. Aug 2024, at 20:43, Kent Overstreet <kent.overstreet@xxxxxxxxx> wrote:
> > On Sun, Aug 25, 2024 at 03:36:02PM GMT, Thorsten Blum wrote:
> >> Add the __counted_by compiler attribute to the flexible array members
> >> devs to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
> >> CONFIG_FORTIFY_SOURCE.
> >>
> >> Increment nr_devs before adding a new device to the devs array and
> >> adjust the array indexes accordingly.
> >
> > The nr_devs changes are pretty gross - please add a helper for that
>
> How about a macro in replicas_format.h like this:
>
> #define replicas_entry_add_dev(e, d) ({
> (e)->nr_devs++;
> (e)->devs[(e)->nr_devs - 1] = (d);
> })

Does it need to be a macro?