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: <CAHp75VfNy4j73nFd2nGSsuGdn0Yat_ENGaaARP_8R9CQKHnnZg@mail.gmail.com>
Date:   Mon, 2 Nov 2020 12:58:36 +0200
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Bartosz Golaszewski <brgl@...ev.pl>
Cc:     Sudip Mukherjee <sudipm.mukherjee@...il.com>,
        Linus Walleij <linus.walleij@...aro.org>,
        "open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Bartosz Golaszewski <bgolaszewski@...libre.com>
Subject: Re: [RFT PATCH 5/7] gpio: exar: unduplicate address and offset computation

On Mon, Oct 26, 2020 at 4:23 PM Bartosz Golaszewski <brgl@...ev.pl> wrote:

...

> +static unsigned int
> +exar_offset_to_sel_addr(struct exar_gpio_chip *exar_gpio, unsigned int offset)
> +{
> +       return (offset + exar_gpio->first_pin) / 8 ? EXAR_OFFSET_MPIOSEL_HI
> +                                                  : EXAR_OFFSET_MPIOSEL_LO;
> +}
> +
> +static unsigned int
> +exar_offset_to_lvl_addr(struct exar_gpio_chip *exar_gpio, unsigned int offset)
> +{
> +       return (offset + exar_gpio->first_pin) / 8 ? EXAR_OFFSET_MPIOLVL_HI
> +                                                  : EXAR_OFFSET_MPIOLVL_LO;
> +}
> +
> +static unsigned int
> +exar_offset_to_bit(struct exar_gpio_chip *exar_gpio, unsigned int offset)
> +{
> +       return (offset + exar_gpio->first_pin) % 8;
> +}

Answering to your question...

It can be done line this:

static unsigned int exar_offset_to_bank_and_bit(..., *bit)
{
       *bit = (offset + exar_gpio->first_pin) % 8;
       return (offset + exar_gpio->first_pin) / 8;
}

static unsigned int exar_offset_to_lvl_addr_and_bit(, *bit)
{
    return exar_offset_to_bank_and_bit(..., bit) ?
        EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
}

...

> +       unsigned int addr = exar_offset_to_lvl_addr(exar_gpio, offset);
> +       unsigned int bit = exar_offset_to_bit(exar_gpio, offset);

unsigned int addr, bit;

addr = exar_offset_to_lvl_addr_and_bit(..., &bit);

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ