From: Rosen Penev <rosenp@gmail.com>
To: Bartosz Golaszewski <brgl@kernel.org>
Cc: Kees Cook <kees@kernel.org>,
linux-gpio@vger.kernel.org,
Bamvor Jian Zhang <bamv2005@gmail.com>,
Linus Walleij <linusw@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
open list <linux-kernel@vger.kernel.org>,
"open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be)?b"
<linux-hardening@vger.kernel.org>
Subject: Re: [PATCH] gpio: mockup: allocate lines with main struct
Date: Tue, 24 Mar 2026 11:25:29 -0700 [thread overview]
Message-ID: <CAKxU2N9gCoyDapYmiY31EMPnTr0vPns6nme26xtibw+Ybs5iHA@mail.gmail.com> (raw)
In-Reply-To: <CAMRc=Mcv1TW55R87xiuAOQShX1Tjf_=BkwfoXdDN8SfUK=a5GQ@mail.gmail.com>
On Tue, Mar 24, 2026 at 10:16 AM Bartosz Golaszewski <brgl@kernel.org> wrote:
>
> On Tue, Mar 24, 2026 at 4:56 PM Rosen Penev <rosenp@gmail.com> wrote:
> >
> > On Tue, Mar 24, 2026 at 8:54 AM Bartosz Golaszewski <brgl@kernel.org> wrote:
> > >
> > > On Tue, Mar 24, 2026 at 4:52 PM Rosen Penev <rosenp@gmail.com> wrote:
> > > >
> > > > On Tue, Mar 24, 2026 at 2:16 AM Bartosz Golaszewski <brgl@kernel.org> wrote:
> > > > >
> > > > > On Mon, 23 Mar 2026 17:43:00 +0100, Rosen Penev <rosenp@gmail.com> said:
> > > > > > On Mon, Mar 23, 2026 at 3:00 AM Bartosz Golaszewski <brgl@kernel.org> wrote:
> > > > > >>
> > > > > >> On Sat, Mar 21, 2026 at 12:00 AM Rosen Penev <rosenp@gmail.com> wrote:
> > > > > >> >
> > > > > >> > >
> > > > > >> > > static int gpio_mockup_probe(struct platform_device *pdev)
> > > > > >> > > {
> > > > > >> > > ...
> > > > > >> > > u16 ngpio;
> > > > > >> > > ...
> > > > > >> > > rv = device_property_read_u16(dev, "nr-gpios", &ngpio);
> > > > > >> > > ...
> > > > > >> > > gc->ngpio = ngpio;
> > > > > >> > > ...
> > > > > >> > > chip->lines = devm_kcalloc(dev, gc->ngpio,
> > > > > >> > > sizeof(*chip->lines), GFP_KERNEL);
> > > > > >> > >
> > > > > >> > > But this begs the question: why add nr_lines when ngpio is already part
> > > > > >> > > of the struct:
> > > > > >> > Maintainers for some inexplicable reason want an extra variable for
> > > > > >> > __counted_by works.
> > > > > >>
> > > > > >> I believe what Kees means here is: you can use ngpio for __counted_by() like so:
> > > > > >>
> > > > > >> __counted_by(gc.ngpio)
> > > > > > __counted_by doesn't support nested variables like that.
> > > > > >
> > > > > > drivers/gpio/gpio-mockup.c:59:61: error: ‘gc’ undeclared here (not in
> > > > > > a function)
> > > > > > 59 | struct gpio_mockup_line_status lines[] __counted_by(gc.ngpio);
> > > > >
> > > > > The following spin on your patch builds fine for me:
> > > > >
> > > > > diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
> > > > > index a7d69f3835c1e..9427ab8c45f73 100644
> > > > > --- a/drivers/gpio/gpio-mockup.c
> > > > > +++ b/drivers/gpio/gpio-mockup.c
> > > > > @@ -52,10 +52,10 @@ struct gpio_mockup_line_status {
> > > > >
> > > > > struct gpio_mockup_chip {
> > > > > struct gpio_chip gc;
> > > > > - struct gpio_mockup_line_status *lines;
> > > > > struct irq_domain *irq_sim_domain;
> > > > > struct dentry *dbg_dir;
> > > > > struct mutex lock;
> > > > > + struct gpio_mockup_line_status lines[] __counted_by(gc.ngpio);
> > > > You're using an older compiler. This does not work at all.
> > > >
> > > > *
>
> Indeed, sorry. In that case I don't know what Kees meant. I'm fine
> with a new variable.
I think his comment is that there's already a counting variable, with
or without counted_by.
>
> Bartosz
prev parent reply other threads:[~2026-03-24 18:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-19 0:05 [PATCH] gpio: mockup: allocate lines with main struct Rosen Penev
2026-03-20 13:28 ` Linus Walleij
2026-03-20 18:10 ` Kees Cook
2026-03-20 23:00 ` Rosen Penev
2026-03-23 10:00 ` Bartosz Golaszewski
2026-03-23 16:43 ` Rosen Penev
2026-03-24 9:16 ` Bartosz Golaszewski
2026-03-24 15:51 ` Rosen Penev
2026-03-24 15:54 ` Bartosz Golaszewski
2026-03-24 15:56 ` Rosen Penev
2026-03-24 17:16 ` Bartosz Golaszewski
2026-03-24 18:25 ` Rosen Penev [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAKxU2N9gCoyDapYmiY31EMPnTr0vPns6nme26xtibw+Ybs5iHA@mail.gmail.com \
--to=rosenp@gmail.com \
--cc=bamv2005@gmail.com \
--cc=brgl@kernel.org \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).