mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Richard <thomas.richard@bootlin.com>
To: Linus Walleij <linus.walleij@linaro.org>,
	 Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	 Bartosz Golaszewski <brgl@bgdev.pl>,
	 Geert Uytterhoeven <geert+renesas@glider.be>,
	Kees Cook <kees@kernel.org>,  Andy Shevchenko <andy@kernel.org>
Cc: 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,
	 Thomas Richard <thomas.richard@bootlin.com>
Subject: [PATCH v9 02/10] gpio: aggregator: move GPIO forwarder allocation in a dedicated function
Date: Mon, 11 Aug 2025 15:25:45 +0200	[thread overview]
Message-ID: <20250811-aaeon-up-board-pinctrl-support-v9-2-29f0cbbdfb30@bootlin.com> (raw)
In-Reply-To: <20250811-aaeon-up-board-pinctrl-support-v9-0-29f0cbbdfb30@bootlin.com>

Move the GPIO forwarder allocation and static initialization in a dedicated
function.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Thomas Richard <thomas.richard@bootlin.com>
---
 drivers/gpio/gpio-aggregator.c | 50 +++++++++++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index af9d8b3a711dad9e7ca048243443d26d09030713..75c8d0deef2fe25faa61bd5b48af3e74e3817957 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -475,6 +475,35 @@ static int gpiochip_fwd_setup_delay_line(struct device *dev, struct gpio_chip *c
 }
 #endif	/* !CONFIG_OF_GPIO */
 
+static struct gpiochip_fwd *
+devm_gpiochip_fwd_alloc(struct device *dev, unsigned int ngpios)
+{
+	struct gpiochip_fwd *fwd;
+	struct gpio_chip *chip;
+
+	fwd = devm_kzalloc(dev, struct_size(fwd, tmp, fwd_tmp_size(ngpios)), GFP_KERNEL);
+	if (!fwd)
+		return ERR_PTR(-ENOMEM);
+
+	chip = &fwd->chip;
+
+	chip->label = dev_name(dev);
+	chip->parent = dev;
+	chip->owner = THIS_MODULE;
+	chip->get_direction = gpio_fwd_get_direction;
+	chip->direction_input = gpio_fwd_direction_input;
+	chip->direction_output = gpio_fwd_direction_output;
+	chip->get = gpio_fwd_get;
+	chip->get_multiple = gpio_fwd_get_multiple_locked;
+	chip->set = gpio_fwd_set;
+	chip->set_multiple = gpio_fwd_set_multiple_locked;
+	chip->to_irq = gpio_fwd_to_irq;
+	chip->base = -1;
+	chip->ngpio = ngpios;
+
+	return fwd;
+}
+
 /**
  * gpiochip_fwd_create() - Create a new GPIO forwarder
  * @dev: Parent device pointer
@@ -495,16 +524,14 @@ static struct gpiochip_fwd *gpiochip_fwd_create(struct device *dev,
 						struct gpio_desc *descs[],
 						unsigned long features)
 {
-	const char *label = dev_name(dev);
 	struct gpiochip_fwd *fwd;
 	struct gpio_chip *chip;
 	unsigned int i;
 	int error;
 
-	fwd = devm_kzalloc(dev, struct_size(fwd, tmp, fwd_tmp_size(ngpios)),
-			   GFP_KERNEL);
-	if (!fwd)
-		return ERR_PTR(-ENOMEM);
+	fwd = devm_gpiochip_fwd_alloc(dev, ngpios);
+	if (IS_ERR(fwd))
+		return fwd;
 
 	chip = &fwd->chip;
 
@@ -526,19 +553,6 @@ static struct gpiochip_fwd *gpiochip_fwd_create(struct device *dev,
 			chip->set_config = gpio_fwd_set_config;
 	}
 
-	chip->label = label;
-	chip->parent = dev;
-	chip->owner = THIS_MODULE;
-	chip->get_direction = gpio_fwd_get_direction;
-	chip->direction_input = gpio_fwd_direction_input;
-	chip->direction_output = gpio_fwd_direction_output;
-	chip->get = gpio_fwd_get;
-	chip->get_multiple = gpio_fwd_get_multiple_locked;
-	chip->set = gpio_fwd_set;
-	chip->set_multiple = gpio_fwd_set_multiple_locked;
-	chip->to_irq = gpio_fwd_to_irq;
-	chip->base = -1;
-	chip->ngpio = ngpios;
 	fwd->descs = descs;
 
 	if (chip->can_sleep)

-- 
2.47.2


  parent reply	other threads:[~2025-08-11 13:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-11 13:25 [PATCH v9 00/10] Add pinctrl support for the AAEON UP board FPGA Thomas Richard
2025-08-11 13:25 ` [PATCH v9 01/10] gpiolib: add support to register sparse pin range Thomas Richard
2025-08-11 13:25 ` Thomas Richard [this message]
2025-08-11 13:25 ` [PATCH v9 03/10] gpio: aggregator: refactor the code to add GPIO desc in the forwarder Thomas Richard
2025-08-11 13:25 ` [PATCH v9 04/10] gpio: aggregator: refactor the forwarder registration part Thomas Richard
2025-08-11 13:25 ` [PATCH v9 05/10] gpio: aggregator: update gpiochip_fwd_setup_delay_line() parameters Thomas Richard
2025-08-11 13:25 ` [PATCH v9 06/10] gpio: aggregator: export symbols of the GPIO forwarder library Thomas Richard
2025-08-11 13:25 ` [PATCH v9 07/10] gpio: aggregator: handle runtime registration of gpio_desc in gpiochip_fwd Thomas Richard
2025-08-11 13:25 ` [PATCH v9 08/10] gpio: aggregator: add possibility to attach data to the forwarder Thomas Richard
2025-08-11 13:25 ` [PATCH v9 09/10] lib/string_choices: Add str_input_output() helper Thomas Richard
2025-08-11 13:25 ` [PATCH v9 10/10] pinctrl: Add pin controller driver for AAEON UP boards Thomas Richard
2025-08-18 15:45   ` Linus Walleij
2025-08-11 13:48 ` (subset) [PATCH v9 00/10] Add pinctrl support for the AAEON UP board FPGA Bartosz Golaszewski

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=20250811-aaeon-up-board-pinctrl-support-v9-2-29f0cbbdfb30@bootlin.com \
    --to=thomas.richard@bootlin.com \
    --cc=DanieleCleri@aaeon.eu \
    --cc=GaryWang@aaeon.com.tw \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=geert+renesas@glider.be \
    --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 \
    /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

all inboxes | Powered by JetHome®