All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Kent Gibson <warthog618@gmail.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Jack Winch <sunt.un.morcov@gmail.com>,
	Helmut Grohne <helmut.grohne@intenta.de>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>
Subject: Re: [libgpiod][PATCH] treewide: rework struct gpiod_line_bulk
Date: Fri, 23 Oct 2020 17:14:30 +0200	[thread overview]
Message-ID: <CAMRc=McrkroEpxx5nw7N3EgbGp1B7SOqTFr7x=J5oxh3NpFoKg@mail.gmail.com> (raw)
In-Reply-To: <20201023141733.GV4077@smile.fi.intel.com>

On Fri, Oct 23, 2020 at 4:16 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Fri, Oct 23, 2020 at 02:44:06PM +0200, Bartosz Golaszewski wrote:
> > On Fri, Oct 23, 2020 at 2:08 PM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > >
> > > On Fri, Oct 23, 2020 at 3:06 PM Andy Shevchenko
> > > <andy.shevchenko@gmail.com> wrote:
> > > > On Fri, Oct 23, 2020 at 2:39 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> > > > > On Fri, Oct 23, 2020 at 12:24 PM Andy Shevchenko
> > > > > <andy.shevchenko@gmail.com> wrote:
> > >
> > > ...
> > >
> > > > > Nope because gcc will scream:
> > > > >
> > > > > error: flexible array member in union
> > > >
> > > > Ah, of course. Should be
> > > >   struct ... **lines;
> > >
> > > But it is not gonna work... we need an array here. or just one member
> > >
> > > struct *lines;
> > >
> > > bulk:
> > >   lines = malloc(num_lines * sizeof(lines));
> > >   xxx->lines = lines;
> > >
> > > single:
> > >   xxx->lines = line;
> >
> > The definition I used is clearer - it's explicit about using an array
> > with a single member by default and can be extended as needed when
> > allocating.
>
> According to [1] it makes harder to avoid sizeof() type of calculation
> mistakes for such struct.
>
> From my point of view extending something that has been already predefined
> is not cool. But it's up to you to decide.
>
> [1]: https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays
>

Your point is valid but we're not talking about a structure commonly
used across a vact code base that is the linux kernel. We're talking
about a structure that is private to a single .c file and its size is
calculated exactly once right next to where it's defined. Risk of
misusing it is miniscule IMO.

I think it's fine for what we need here: a struct that can be extended
when allocated dynamically but also which can be used on the stack for
the very precise use-case - holding a single line.

Bartosz

  reply	other threads:[~2020-10-23 15:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-23  9:28 [libgpiod][PATCH] treewide: rework struct gpiod_line_bulk Bartosz Golaszewski
2020-10-23 10:24 ` Andy Shevchenko
2020-10-23 11:38   ` Bartosz Golaszewski
2020-10-23 12:06     ` Andy Shevchenko
2020-10-23 12:09       ` Andy Shevchenko
2020-10-23 12:44         ` Bartosz Golaszewski
2020-10-23 14:17           ` Andy Shevchenko
2020-10-23 15:14             ` Bartosz Golaszewski [this message]
2020-10-23 11:24 ` Kent Gibson
2020-10-24  8:01 ` Kent Gibson
2020-10-25 20:25   ` Bartosz Golaszewski

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='CAMRc=McrkroEpxx5nw7N3EgbGp1B7SOqTFr7x=J5oxh3NpFoKg@mail.gmail.com' \
    --to=brgl@bgdev.pl \
    --cc=andy.shevchenko@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=geert@linux-m68k.org \
    --cc=helmut.grohne@intenta.de \
    --cc=linux-gpio@vger.kernel.org \
    --cc=sunt.un.morcov@gmail.com \
    --cc=warthog618@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.