lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20200920112323.GC793608@sol>
Date:   Sun, 20 Sep 2020 19:23:23 +0800
From:   Kent Gibson <warthog618@...il.com>
To:     Andy Shevchenko <andy.shevchenko@...il.com>
Cc:     Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        "open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
        Bartosz Golaszewski <bgolaszewski@...libre.com>,
        Linus Walleij <linus.walleij@...aro.org>
Subject: Re: [PATCH v8 09/20] gpiolib: cdev: support edge detection for uAPI
 v2

On Tue, Sep 15, 2020 at 01:39:41PM +0300, Andy Shevchenko wrote:
> On Wed, Sep 9, 2020 at 1:33 PM Kent Gibson <warthog618@...il.com> wrote:
> >
> > Add support for edge detection to lines requested using
> > GPIO_V2_GET_LINE_IOCTL.
> >
> > The edge_detector implementation is based on the v1 lineevent
> > implementation.
> 
> ...
> 
[snip]
> > +
> > +       /*
> > +        * We may be running from a nested threaded interrupt in which case
> > +        * we didn't get the timestamp from edge_irq_handler().
> > +        */
> 
> > +       if (!line->timestamp) {
> 
> Can it be positive conditional?
> 

Not sure what you mean - switch the order of the if/else?

> > +               le.timestamp = ktime_get_ns();
> > +               if (lr->num_lines != 1)
> > +                       line->req_seqno = atomic_inc_return(&lr->seqno);
> > +       } else {
> > +               le.timestamp = line->timestamp;
> > +       }
> > +       line->timestamp = 0;
> > +
> > +       if (line->eflags == (GPIO_V2_LINE_FLAG_EDGE_RISING |
> > +                            GPIO_V2_LINE_FLAG_EDGE_FALLING)) {
> > +               int level = gpiod_get_value_cansleep(line->desc);
> > +
> > +               if (level)
> > +                       /* Emit low-to-high event */
> > +                       le.id = GPIO_V2_LINE_EVENT_RISING_EDGE;
> > +               else
> > +                       /* Emit high-to-low event */
> > +                       le.id = GPIO_V2_LINE_EVENT_FALLING_EDGE;
> > +       } else if (line->eflags == GPIO_V2_LINE_FLAG_EDGE_RISING) {
> > +               /* Emit low-to-high event */
> > +               le.id = GPIO_V2_LINE_EVENT_RISING_EDGE;
> > +       } else if (line->eflags == GPIO_V2_LINE_FLAG_EDGE_FALLING) {
> > +               /* Emit high-to-low event */
> > +               le.id = GPIO_V2_LINE_EVENT_FALLING_EDGE;
> > +       } else {
> > +               return IRQ_NONE;
> > +       }
> > +       line->line_seqno++;
> > +       le.line_seqno = line->line_seqno;
> > +       le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno;
> > +       le.offset = gpio_chip_hwgpio(line->desc);
> > +
> > +       ret = kfifo_in_spinlocked_noirqsave(&lr->events, &le,
> > +                                           1, &lr->wait.lock);
> > +       if (ret)
> > +               wake_up_poll(&lr->wait, EPOLLIN);
> > +       else
> 
> > +               pr_debug_ratelimited("event FIFO is full - event dropped\n");
> 
> Oh, can we really avoid printf() in IRQ context?
> 

Even in the IRQ thread?  Would a tracepoint be preferable?

Btw, this is drawn from the v1 implmentation.

> > +
> > +static void edge_detector_stop(struct line *line)
> > +{
> 
> > +       if (line->irq) {
> > +               free_irq(line->irq, line);
> > +               line->irq = 0;
> > +       }
> 
> Perhaps
> 
> if (!line->irq)
>   return;
> 
> ?
> 

No - the function is extended in subsequent patches.  I usually make a
note of cases like this in the commentary, but missed this one.

> > +       if (!eflags)
> > +               return 0;
> > +
> > +       irq = gpiod_to_irq(line->desc);
> > +       if (irq <= 0)
> 
> > +               return -ENODEV;
> 
> Why shadowing actual error code?
> 

Another one drawn from the v1 implementation, so not sure.
gpiod_to_irq() can potentially return EINVAL, which is definitely not
appropriate to return, or ENXIO, which is actually more appropriate??

Cheers,
Kent.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ