From nobody Tue Dec 16 23:10:48 2025 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 6F45C283CB5; Tue, 6 May 2025 15:21:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746544897; cv=none; b=UB/9yvHmUV/VHSXzayT1ze0JT/+ew+QZlXOu48hKkHDJvxIXbzgJVaLyaI8ceZgMirgY+D3ytkGzq2kwgwCEKCXaq66BqEcBENIUHXATPSH0jYP9JrN6eZzK8iTRoKOj7XaU2J/X9Hb6PJJBHpaX3+xklOpdbhB7BhaIJSrFdp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746544897; c=relaxed/simple; bh=Uw49RaTelOrwOk+FJrDe4DnxOi4wzzFKqU803pdfICs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CfxjANYO7RnqKGwrDfjvKUr9Fbq+q4KO62MXw0a+OzfxmdmSZUwDM2pqXPzwwkFx816dRjtxPS7GlITU8+rBANuDEKVU3wgnQG5geNm5nNpUlt7SZjV/mLxrGRrkBKcLxj87Wn0bEhYZlSQUYfDUxcgNeLNXx5zNHR+KbCG7x1U= 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=K/k4OVkj; arc=none smtp.client-ip=217.70.183.201 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="K/k4OVkj" Received: by mail.gandi.net (Postfix) with ESMTPSA id C8E5C43B37; Tue, 6 May 2025 15:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1746544888; 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=9Q4UReFmn4Pspd3+GoPvOwnJiwMV0hCxt4+MCuhAowQ=; b=K/k4OVkjBIe0UmGom7wiMy/l533oL7psrRqLWsETaK55AXOxjT7wz9yAnaUfbrnhenvA9t qLVPEFBu2eXvCH3dXSC9/ILA6bhBEL98lNWkAhdVJPJ+W/Knb+Xszb3RG0iF9iKjIsYubs BX4Z2UJm7LujApqa/IxtHklN9uxzADENFvnh9Fre+6NieSasb6tVpa3MZp4AEX1quqnTyQ x46/Wl2xFZF/TKwtw9e0OPrpnWgBakvcsX8j8AJkHlM9X2eAqxVK5Sg0h87WXA3kaTy7h2 N1Gki9ZUF5KSpofUTXjvNHhdJqyxY7km+4PVxWwpvAlw+CJYSqVuIWb0pfxGrw== From: Thomas Richard Date: Tue, 06 May 2025 17:21:23 +0200 Subject: [PATCH v5 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: <20250506-aaeon-up-board-pinctrl-support-v5-5-3906529757d2@bootlin.com> References: <20250506-aaeon-up-board-pinctrl-support-v5-0-3906529757d2@bootlin.com> In-Reply-To: <20250506-aaeon-up-board-pinctrl-support-v5-0-3906529757d2@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: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvkeegfeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepvfhhohhmrghsucftihgthhgrrhguuceothhhohhmrghsrdhrihgthhgrrhgusegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeektdehvdeiteehtdelteffheduveelgeelvdetgedvueejgefhhfekgefgfeduveenucfkphepvdgrtddumegtsgdugeemheehieemjegrtddtmegutgekudemrggrugdtmehfuggtrgemtggtudgrnecuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehinhgvthepvdgrtddumegtsgdugeemheehieemjegrtddtmegutgekudemrggrugdtmehfuggtrgemtggtudgrpdhhvghloheplgduvdejrddtrddurddungdpmhgrihhlfhhrohhmpehthhhomhgrshdrrhhitghhrghrugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepudefpdhrtghpthhtohepghgvvghrthdorhgvnhgvshgrshesghhlihguvghrrdgsvgdprhgtphhtthhopegsrhhglhessghguggvvhdrphhlpdhrtghpthhtohepkhgvvghssehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhvghvt ghhvghnkhhosehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtoheplhhinhhushdrfigrlhhlvghijheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqghhpihhosehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhm 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 descs, now the GPIO descs are passed on by one to the forwarder. Signed-off-by: Thomas Richard Reviewed-by: Andy Shevchenko --- drivers/gpio/gpio-aggregator.c | 54 +++++++++++++++++++++++++++++---------= ---- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c index 4268ef94914d..7ca6f1953938 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,36 @@ 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 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 +593,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