Re: [PATCH v2 05/18] gpiolib: cdev: support GPIO_GET_LINE_IOCTL and GPIOLINE_GET_VALUES_IOCTL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 03, 2020 at 10:02:50PM +0200, Bartosz Golaszewski wrote:
> On Sun, Aug 2, 2020 at 5:32 AM Kent Gibson <warthog618@xxxxxxxxx> wrote:
> >
> > On Fri, Jul 31, 2020 at 06:05:10PM +0200, Bartosz Golaszewski wrote:
> > > On Sun, Jul 26, 2020 at 3:12 AM Kent Gibson <warthog618@xxxxxxxxx> wrote:
> 
> [snip!]
> 
> > > > >
> > > > > > +static u64 gpioline_config_flags(struct gpioline_config *lc, int line_idx)
> > > > > > +{
> > > > > > +       int i;
> > > > > > +
> > > > > > +       for (i = lc->num_attrs - 1; i >= 0; i--) {
> > > > >
> > > > > Much better to read is
> > > > >
> > > > > unsigned int i = lc->num_attrs;
> > > > >
> > > > > while (i--) {
> > > > >  ...
> > > > > }
> > > > >
> > > >
> > > > Really? I find that the post-decrement in the while makes determining the
> > > > bounds of the loop more confusing.
> > > >
> > >
> > > Agreed, Andy: this is too much nit-picking. :)
> > >
> >
> > I was actually hoping for some feedback on the direction of that loop,
> > as it relates to the handling of multiple instances of the same
> > attribute associated with a given line.
> >
> > The reverse loop here implements a last in wins policy, but I'm now
> > thinking the kernel should be encouraging userspace to only associate a
> > given attribute with a line once, and that a first in wins would help do
> > that - as additional associations would be ignored.
> >
> > Alternatively, the kernel should enforce that an attribute can only be
> > associated once, but that would require adding more request validation.
> >
> 
> I guess this would result in a lot of churn to do validation which is
> largely unnecessary? To me the first in wins sounds more consistent.
> 

Fully validating the attrs would involve a lot of tedious looping, which
would be pointless 99.99% of the time, so I was hoping to avoid it.
OTOH we're interacting with hardware so I don't want to be doing
anything that userspace hasn't explicitly requested.

But I would be satisfied with clearly documenting the behaviour - and
in most cases libgpiod will be taking care of it anyway...

> Also: I just started going through the patches - nice idea with the
> GPIO attributes, I really like it. Although I need to give it a longer
> thought tomorrow - I'm wondering if we can maybe unify them and the
> flags.
> 

I had an earlier draft that did just that - and that is partially why
the loop is last in wins - I was using slot 0 as the default flags.
But the default flags cover a lot of use cases, including all of v1, and
it was simple and cheap to provide a default - and it simplified the
initial port of libgpiod to v2...

Cheers,
Kent.




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux