All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>,
	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:17:33 +0300	[thread overview]
Message-ID: <20201023141733.GV4077@smile.fi.intel.com> (raw)
In-Reply-To: <CAMpxmJWWt5MhqObJabOxtdm9U4rQ6EPvJR3PHBRH_J1uLMat+Q@mail.gmail.com>

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


-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2020-10-23 14:17 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 [this message]
2020-10-23 15:14             ` Bartosz Golaszewski
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=20201023141733.GV4077@smile.fi.intel.com \
    --to=andy.shevchenko@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=brgl@bgdev.pl \
    --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.