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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200924032414.GC11575@sol>
Date:   Thu, 24 Sep 2020 11:24:14 +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>,
        Arnd Bergmann <arnd@...db.de>
Subject: Re: [PATCH v9 10/20] gpiolib: cdev: support
 GPIO_V2_LINE_SET_CONFIG_IOCTL

On Wed, Sep 23, 2020 at 07:15:46PM +0300, Andy Shevchenko wrote:
> On Wed, Sep 23, 2020 at 7:14 PM Andy Shevchenko
> <andy.shevchenko@...il.com> wrote:
> >
> > On Tue, Sep 22, 2020 at 5:35 AM Kent Gibson <warthog618@...il.com> wrote:
> > >
> > > Add support for GPIO_V2_LINE_SET_CONFIG_IOCTL, the uAPI v2
> > > line set config ioctl.
> 
> > > +static long linereq_set_config_unlocked(struct linereq *lr,
> > > +                                       struct gpio_v2_line_config *lc)
> > > +{
> > > +       struct gpio_desc *desc;
> > > +       unsigned int i;
> > > +       u64 flags;
> > > +       bool polarity_change;
> > > +       int ret;
> > > +
> > > +       for (i = 0; i < lr->num_lines; i++) {
> > > +               desc = lr->lines[i].desc;
> > > +               flags = gpio_v2_line_config_flags(lc, i);
> >
> > > +               polarity_change =
> > > +                       (test_bit(FLAG_ACTIVE_LOW, &desc->flags) !=
> > > +                        ((flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW) != 0));
> >
> > Comparison
> 
> Comparison between int / long (not all archs are agreed on this) and
> boolean is not the best we can do.
> 

There is no bool to int comparision here.

There are two comparisons - the inner int vs int => bool and the
outer bool vs bool.  The "!= 0" is effectively an implicit cast to
bool, as is your new_polarity initialisation below.

> What about
> 
>   bool old_polarity = test_bit(FLAG_ACTIVE_LOW, &desc->flags);
>   bool new_polarity = flags & GPIO_V2_LINE_FLAG_ACTIVE_LOW;
> 
>   old_polarity ^ new_polarity
> 

So using bitwise operators on bools is ok??

> and move this under INPUT conditional?
> 

It has to be before the gpio_v2_line_config_flags_to_desc_flags() call,
as that modifies the desc flags, including the new polarity, so
polarity_change would then always be false :-).

Cheers,
Kent.

> > > +
> > > +               gpio_v2_line_config_flags_to_desc_flags(flags, &desc->flags);
> > > +               /*
> > > +                * Lines have to be requested explicitly for input
> > > +                * or output, else the line will be treated "as is".
> > > +                */
> > > +               if (flags & GPIO_V2_LINE_FLAG_OUTPUT) {
> > > +                       int val = gpio_v2_line_config_output_value(lc, i);
> > > +
> > > +                       edge_detector_stop(&lr->lines[i]);
> > > +                       ret = gpiod_direction_output(desc, val);
> > > +                       if (ret)
> > > +                               return ret;
> > > +               } else if (flags & GPIO_V2_LINE_FLAG_INPUT) {
> > > +                       ret = gpiod_direction_input(desc);
> > > +                       if (ret)
> > > +                               return ret;
> > > +
> > > +                       ret = edge_detector_update(&lr->lines[i],
> > > +                                       flags & GPIO_V2_LINE_EDGE_FLAGS,
> > > +                                       polarity_change);
> > > +                       if (ret)
> > > +                               return ret;
> > > +               }
> > > +
> > > +               blocking_notifier_call_chain(&desc->gdev->notifier,
> > > +                                            GPIO_V2_LINE_CHANGED_CONFIG,
> > > +                                            desc);
> > > +       }
> > > +       return 0;
> > > +}
> 
> -- 
> With Best Regards,
> Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ