From nobody Tue Feb 10 02:49:54 2026 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BEE62D1937; Tue, 29 Apr 2025 14:08:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745935715; cv=none; b=Qf+ULL60EA66mi25a+3jNYIl/qOMoOEve1v+CDXLAz1wkKiJWamR0DFEKtEcaRqkOVxelH+vrRMH6qjL/nsrMJz9ReXtV/Eusx0X8+KBUBx5MVYcb5KntuAY2cLHzxax6d9UWwtY3sIDfqf/iLmHa+7zKraP6HDlzshXAAL/izw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745935715; c=relaxed/simple; bh=/8HviQiKkU+d2ORW3lAXBM7ZsjagpZrXY9Ck6vLFSyo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SmIj/KuXxtrpZOZVEaVfuGsEOZnouvozZr8d0lwRfZsOv3LxiswgVGV9EW/NkRrlpLAywKpwyLfenDpn9/kEgVGKICiyBWoeFQxE6UzjlHi2xBO+EP7ejjIZRcGfXNcgZYyLmqwtCQZydEkRjtCKj2boP18Ew2z+8dyBIP3uSbc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=oeXkajaZ; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="oeXkajaZ" Received: by mail.gandi.net (Postfix) with ESMTPSA id E9CB0438B5; Tue, 29 Apr 2025 14:08:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1745935711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WX8JIbn2cUceBlHvqVMgZ+mBEYl70+adDNEug9/PKiU=; b=oeXkajaZIss1UXGlmx1/IPpLzugwCEcPppee7EiEd7Fq7kj19HI/O/K34ufRuqnV4SxF2I XEL7uO9kPAtwa9MVoRrd0PJ3EycCdFjNUoe6aKlovmrcxlukBIo4kQIQfKqaV2wZQzHBxk /YlnI69SvjFZp7w/C5gpY0K7cfFWWUvsbsn6HKnA23NuBWAcissdq+ikxvhZ29ELYKnJPG JyfRIN6rSQJIGTj9u52uAKv755F7w5Nm2LMrUF316iI+x9qRbPfetGX5GbBlyUZ3dgcgsN qrzr9Oc/aa6W4nxd17alzeEvxpGR9gb3FttRCYoYqopkug+Ev4Jw+9mEmAtZFQ== From: Thomas Richard Date: Tue, 29 Apr 2025 16:08:19 +0200 Subject: [PATCH v4 05/12] gpio: aggregator: refactor the code to add GPIO desc in the forwarder Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250429-aaeon-up-board-pinctrl-support-v4-5-b3fffc11417d@bootlin.com> References: <20250429-aaeon-up-board-pinctrl-support-v4-0-b3fffc11417d@bootlin.com> In-Reply-To: <20250429-aaeon-up-board-pinctrl-support-v4-0-b3fffc11417d@bootlin.com> To: Linus Walleij , Andy Shevchenko , Bartosz Golaszewski , Geert Uytterhoeven , Kees Cook , Andy Shevchenko 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 X-Mailer: b4 0.14.1 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvieegtddvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepvfhhohhmrghsucftihgthhgrrhguuceothhhohhmrghsrdhrihgthhgrrhgusegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeektdehvdeiteehtdelteffheduveelgeelvdetgedvueejgefhhfekgefgfeduveenucfkphepvdgrtddumegtsgdugeemheehieemjegrtddtmegutgekudemrggrugdtmehfuggtrgemtggtudgrnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdgrtddumegtsgdugeemheehieemjegrtddtmegutgekudemrggrugdtmehfuggtrgemtggtudgrpdhhvghloheplgduvdejrddtrddurddungdpmhgrihhlfhhrohhmpehthhhomhgrshdrrhhitghhrghrugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepudefpdhrtghpthhtoheplhhinhhugidqhhgrrhguvghnihhnghesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhhsrdifrghllhgvihhjsehlihhnrghrohdrohhrghdprhgtphhtthhopegrnhguhieskhgvrhhnvghlrdhorhhgp dhrtghpthhtohepkhgvvghssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehgvggvrhhtodhrvghnvghsrghssehglhhiuggvrhdrsggvpdhrtghpthhtohepffgrnhhivghlvgevlhgvrhhisegrrggvohhnrdgvuhdprhgtphhtthhopegrnhgurhhihidrshhhvghvtghhvghnkhhosehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhm X-GND-Sasl: thomas.richard@bootlin.com Create a dedicated function to add a GPIO desc in the forwarder. Instead of passing an array of GPIO desc, now the GPIO desc are passed on by one to the forwarder. Signed-off-by: Thomas Richard --- drivers/gpio/gpio-aggregator.c | 57 +++++++++++++++++++++++++++++---------= ---- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c index 4268ef94914d..78bb84ca8a05 100644 --- a/drivers/gpio/gpio-aggregator.c +++ b/drivers/gpio/gpio-aggregator.c @@ -509,6 +509,10 @@ devm_gpiochip_fwd_alloc(struct device *dev, unsigned i= nt ngpios) if (!fwd) return ERR_PTR(-ENOMEM); =20 + fwd->descs =3D devm_kcalloc(dev, ngpios, sizeof(*fwd->descs), GFP_KERNEL); + if (!fwd->descs) + return ERR_PTR(-ENOMEM); + chip =3D &fwd->chip; =20 chip->label =3D label; @@ -528,6 +532,39 @@ devm_gpiochip_fwd_alloc(struct device *dev, unsigned i= nt ngpios) return fwd; } =20 +static int gpiochip_fwd_gpio_add(struct gpiochip_fwd *fwd, + struct gpio_desc *desc, + unsigned int offset) +{ + struct gpio_chip *parent =3D gpiod_to_chip(desc); + struct gpio_chip *chip =3D &fwd->chip; + + if (offset > chip->ngpio) + return -EINVAL; + + if (fwd->descs[offset]) + return -EEXIST; + + /* + * 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 =3D true; + + if (parent && parent->set_config) + chip->set_config =3D gpio_fwd_set_config; + + fwd->descs[offset] =3D desc; + + dev_dbg(chip->parent, "%u =3D> 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 +596,12 @@ static struct gpiochip_fwd *gpiochip_fwd_create(struc= t device *dev, =20 chip =3D &fwd->chip; =20 - /* - * 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 =3D 0; i < ngpios; i++) { - struct gpio_chip *parent =3D gpiod_to_chip(descs[i]); - - dev_dbg(dev, "%u =3D> gpio %d irq %d\n", i, - desc_to_gpio(descs[i]), gpiod_to_irq(descs[i])); - - if (gpiod_cansleep(descs[i])) - chip->can_sleep =3D true; - if (parent && parent->set_config) - chip->set_config =3D gpio_fwd_set_config; + error =3D gpiochip_fwd_gpio_add(fwd, descs[i], i); + if (error) + return ERR_PTR(error); } =20 - fwd->descs =3D descs; - if (chip->can_sleep) mutex_init(&fwd->mlock); else --=20 2.39.5