linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Thomas Richard <thomas.richard@bootlin.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	 Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>,  Kees Cook <kees@kernel.org>,
	Andy Shevchenko <andy@kernel.org>,
	linux-gpio@vger.kernel.org,  linux-kernel@vger.kernel.org,
	thomas.petazzoni@bootlin.com,  DanieleCleri@aaeon.eu,
	GaryWang@aaeon.com.tw, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v5 05/12] gpio: aggregator: refactor the code to add GPIO desc in the forwarder
Date: Fri, 9 May 2025 10:38:06 +0200	[thread overview]
Message-ID: <CAMuHMdVLo2w609eFOKRkYAfEMb8XOTNB-XzzZn_89VM-YV_-kA@mail.gmail.com> (raw)
In-Reply-To: <20250506-aaeon-up-board-pinctrl-support-v5-5-3906529757d2@bootlin.com>

Hi Thomas,

Thanks for your patch!

On Tue, 6 May 2025 at 17:21, Thomas Richard <thomas.richard@bootlin.com> wrote:
> Create a dedicated function to add a GPIO desc in the forwarder. Instead of
> passing an array of GPIO descs, now the GPIO descs are passed on by one to

one by one

> the forwarder.

Also, the passed array is no longer stored as-is, but copied.

>
> Signed-off-by: Thomas Richard <thomas.richard@bootlin.com>

> --- a/drivers/gpio/gpio-aggregator.c
> +++ b/drivers/gpio/gpio-aggregator.c
> @@ -509,6 +509,10 @@ devm_gpiochip_fwd_alloc(struct device *dev, unsigned int ngpios)
>         if (!fwd)
>                 return ERR_PTR(-ENOMEM);
>
> +       fwd->descs = devm_kcalloc(dev, ngpios, sizeof(*fwd->descs), GFP_KERNEL);
> +       if (!fwd->descs)
> +               return ERR_PTR(-ENOMEM);
> +
>         chip = &fwd->chip;
>
>         chip->label = label;
> @@ -528,6 +532,36 @@ devm_gpiochip_fwd_alloc(struct device *dev, unsigned int ngpios)
>         return fwd;
>  }
>
> +static int gpiochip_fwd_gpio_add(struct gpiochip_fwd *fwd,
> +                                struct gpio_desc *desc,
> +                                unsigned int offset)
> +{
> +       struct gpio_chip *parent = gpiod_to_chip(desc);
> +       struct gpio_chip *chip = &fwd->chip;
> +
> +       if (offset > chip->ngpio)

>=

> +               return -EINVAL;
> +
> +       /*
> +        * If any of the GPIO lines are sleeping, then the entire forwarder
> +        * will be sleeping.
> +        * If any of the chips support .set_config(), then the forwarder will
> +        * support setting configs.
> +        */
> +       if (gpiod_cansleep(desc))
> +               chip->can_sleep = true;
> +
> +       if (parent && parent->set_config)
> +               chip->set_config = gpio_fwd_set_config;
> +
> +       fwd->descs[offset] = desc;
> +
> +       dev_dbg(chip->parent, "%u => gpio %d irq %d\n", offset,
> +               desc_to_gpio(desc), gpiod_to_irq(desc));
> +
> +       return 0;
> +}
> +
>  /**
>   * gpiochip_fwd_create() - Create a new GPIO forwarder
>   * @dev: Parent device pointer
> @@ -559,26 +593,12 @@ static struct gpiochip_fwd *gpiochip_fwd_create(struct device *dev,
>
>         chip = &fwd->chip;
>
> -       /*
> -        * If any of the GPIO lines are sleeping, then the entire forwarder
> -        * will be sleeping.
> -        * If any of the chips support .set_config(), then the forwarder will
> -        * support setting configs.
> -        */
>         for (i = 0; i < ngpios; i++) {
> -               struct gpio_chip *parent = gpiod_to_chip(descs[i]);
> -
> -               dev_dbg(dev, "%u => gpio %d irq %d\n", i,
> -                       desc_to_gpio(descs[i]), gpiod_to_irq(descs[i]));
> -
> -               if (gpiod_cansleep(descs[i]))
> -                       chip->can_sleep = true;
> -               if (parent && parent->set_config)
> -                       chip->set_config = gpio_fwd_set_config;
> +               error = gpiochip_fwd_gpio_add(fwd, descs[i], i);
> +               if (error)
> +                       return ERR_PTR(error);
>         }
>
> -       fwd->descs = descs;

So the passed array is no longer stored, and thus the caller
(gpio_aggregator_probe()) can free it after the call.

> -
>         if (chip->can_sleep)
>                 mutex_init(&fwd->mlock);
>         else
>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  parent reply	other threads:[~2025-05-09  8:38 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06 15:21 [PATCH v5 00/12] Add pinctrl support for the AAEON UP board FPGA Thomas Richard
2025-05-06 15:21 ` [PATCH v5 01/12] gpiolib: add support to register sparse pin range Thomas Richard
2025-05-07 17:49   ` kernel test robot
2025-05-06 15:21 ` [PATCH v5 02/12] pinctrl: remove extern specifier for functions in machine.h Thomas Richard
2025-05-13 12:59   ` Linus Walleij
2025-05-06 15:21 ` [PATCH v5 03/12] pinctrl: core: add devm_pinctrl_register_mappings() Thomas Richard
2025-05-06 15:21 ` [PATCH v5 04/12] gpio: aggregator: move GPIO forwarder allocation in a dedicated function Thomas Richard
2025-05-09  8:05   ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 05/12] gpio: aggregator: refactor the code to add GPIO desc in the forwarder Thomas Richard
2025-05-07  6:22   ` Andy Shevchenko
2025-05-09  8:38   ` Geert Uytterhoeven [this message]
2025-05-09  8:43     ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 06/12] gpio: aggregator: refactor the forwarder registration part Thomas Richard
2025-05-09  8:50   ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 07/12] gpio: aggregator: update gpiochip_fwd_setup_delay_line() parameters Thomas Richard
2025-05-09  8:53   ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 08/12] gpio: aggregator: export symbols of the GPIO forwarder library Thomas Richard
2025-05-07  6:29   ` Andy Shevchenko
2025-05-07 14:53     ` Thomas Richard
2025-05-07 15:21       ` Andy Shevchenko
2025-05-07 15:23         ` Andy Shevchenko
2025-05-07 15:29           ` Thomas Richard
2025-05-08  7:23           ` Geert Uytterhoeven
2025-05-09  9:07   ` Geert Uytterhoeven
2025-05-12 14:08     ` Thomas Richard
2025-05-12 14:11       ` Andy Shevchenko
2025-05-12 14:30         ` Thomas Richard
2025-05-12 14:42           ` Geert Uytterhoeven
2025-05-12 14:39       ` Geert Uytterhoeven
2025-05-12 15:00         ` Thomas Richard
2025-05-12 15:14           ` Geert Uytterhoeven
2025-05-12 15:33             ` Thomas Richard
2025-05-06 15:21 ` [PATCH v5 09/12] gpio: aggregator: handle runtime registration of gpio_desc in gpiochip_fwd Thomas Richard
2025-05-07  6:34   ` Andy Shevchenko
2025-05-07 10:10     ` Thomas Richard
2025-05-07 13:24       ` Andy Shevchenko
2025-05-07 13:54         ` Thomas Richard
2025-05-07 15:24           ` Andy Shevchenko
2025-05-09 13:33             ` Bartosz Golaszewski
2025-05-09  9:29   ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 10/12] gpio: aggregator: add possibility to attach data to the forwarder Thomas Richard
2025-05-09  9:32   ` Geert Uytterhoeven
2025-05-06 15:21 ` [PATCH v5 11/12] lib/string_choices: Add str_input_output() helper Thomas Richard
2025-05-06 15:21 ` [PATCH v5 12/12] pinctrl: Add pin controller driver for AAEON UP boards Thomas Richard
2025-05-07  6:57   ` Andy Shevchenko
2025-05-07 13:34     ` Thomas Richard
2025-05-07  6:59 ` [PATCH v5 00/12] Add pinctrl support for the AAEON UP board FPGA Andy Shevchenko
2025-05-13 13:02 ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMuHMdVLo2w609eFOKRkYAfEMb8XOTNB-XzzZn_89VM-YV_-kA@mail.gmail.com \
    --to=geert@linux-m68k.org \
    --cc=DanieleCleri@aaeon.eu \
    --cc=GaryWang@aaeon.com.tw \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=kees@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=thomas.richard@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).