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: <CACRpkdYv6yosZ1KJazrMzaizpYz-cv-y4LcCqHm+Q94jva8sAA@mail.gmail.com>
Date:   Fri, 18 Jun 2021 11:43:55 +0200
From:   Linus Walleij <linus.walleij@...aro.org>
To:     Piyush Mehta <piyush.mehta@...inx.com>
Cc:     Bartosz Golaszewski <bgolaszewski@...libre.com>,
        Rob Herring <robh+dt@...nel.org>,
        "open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
        "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" 
        <devicetree@...r.kernel.org>,
        linux-kernel <linux-kernel@...r.kernel.org>,
        Linux ARM <linux-arm-kernel@...ts.infradead.org>,
        git <git@...inx.com>, Srinivas Goud <sgoud@...inx.com>,
        Michal Simek <michal.simek@...inx.com>
Subject: Re: [PATCH 2/2] gpio: modepin: Add driver support for modepin GPIO controller

Hi Piyush!

thanks for your patch!

On Tue, Jun 15, 2021 at 10:06 AM Piyush Mehta <piyush.mehta@...inx.com> wrote:

> This patch adds support for the mode pin GPIO controller. GPIO Modepin
> driver set and get the value and status of the PS_MODE pin, based on
> device-tree pin configuration. These 4-bits boot-mode pins are dedicated
> configurable as input/output. After the stabilization of the system,
> these mode pins are sampled.
>
> Signed-off-by: Piyush Mehta <piyush.mehta@...inx.com>

OK, sounds interesting!

> +#include <linux/slab.h>

I think I saw somewhere that this is not needed anymore, check if you need it.

> +#define GET_OUTEN_PIN(pin)             (1U << (pin))

Delete this macro and just use BIT(pin) inline.
#include <linux/bits.h>

> +static int modepin_gpio_get_value(struct gpio_chip *chip, unsigned int pin)
> +{
> +       u32 out_en;
> +       u32 regval = 0;
> +       int ret;
> +
> +       out_en = GET_OUTEN_PIN(pin);

Drop this and out_en

> +       ret = zynqmp_pm_bootmode_read(&regval);
> +       if (ret) {
> +               pr_err("modepin: get value err %d\n", ret);
> +               return ret;
> +       }
> +
> +       return (out_en & (regval >> 8U)) ? 1 : 0;

return !!(regval & BIT(pin + 8));

should work and is easier to read IMO. We just check the right
bit immediately.

> +static void modepin_gpio_set_value(struct gpio_chip *chip, unsigned int pin,
> +                                  int state)
> +{
> +       u32 out_en;
> +       u32 bootpin_val = 0;
> +       int ret;
> +
> +       out_en = GET_OUTEN_PIN(pin);

Skip this helper variable.

> +       state = state != 0 ? out_en : 0;

Uh that is really hard to read and modified a parameter. Skip that too.

> +       bootpin_val = (state << (8U)) | out_en;

What you want is mask and set.

bootpin_val = BIT(pin + 8);

> +       /* Configure bootpin value */
> +       ret = zynqmp_pm_bootmode_write(bootpin_val);

This just looks weird.

Why are you not reading the value first since you are using
read/modify/write?

I *think* you want to do this:

ret = zynqmp_pm_bootmode_read(&val);
if (ret)
   /* error handling */
if (state)
    val |= BIT(pin + 8);
else
    val &= ~BIT(pin + 8);
ret = zynqmp_pm_bootmode_write(val);
if (ret)
   /* error handling */

> +/*
> + * modepin_gpio_dir_in - Set the direction of the specified GPIO pin as input
> + * @chip:      gpio_chip instance to be worked on
> + * @pin:       gpio pin number within the device
> + *
> + * Return: 0 always
> + */
> +static int modepin_gpio_dir_in(struct gpio_chip *chip, unsigned int pin)
> +{
> +       return 0;
> +}

I think you said this was configurable in the commit message.

Use the define GPIO_LINE_DIRECTION_OUT rather than 0.

> +static int modepin_gpio_dir_out(struct gpio_chip *chip, unsigned int pin,
> +                               int state)
> +{
> +       return 0;
> +}

Configurable?

> +       status = devm_gpiochip_add_data(&pdev->dev, chip, chip);
> +       if (status)
> +               dev_err_probe(&pdev->dev, status,
> +                             "Failed to add GPIO chip\n");

just return dev_err_probe(...)

Yours,
Linus Walleij

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ