From nobody Tue Dec 2 01:03:03 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.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 79096DDAB; Mon, 24 Nov 2025 00:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763945398; cv=none; b=SKweXxWOXFM/DBlCOSdil7yuh7/8p0C9j9xOq+aZekS/h3nrlsfjBSIP0G1PAkd4PrccHx1oJZuv//pjweHQILqGd4jO9lxjOi/UuBn8RfKQ1bSmVQLTZUa16xPdf/zsXXgoakuiDaeUw7tvDa3e2VfWKDHASf+xOiku7pkKHyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763945398; c=relaxed/simple; bh=bUo6ak1zTCbJEyjFXZF8zQG8L5QXu94ygdsiABIZMis=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Q5yzXL65AFqIYu+BlxErthPmenW6gmNxCayZMRTTniPRwAZwZu5+V8TFR23EbfPSBMB3L1c6cISpKJB87n+4hedL0h+Agc+BwlhgINaKCr+Y+2l7c/oCV2PgHbGUr2c1YfEqFjzEtDE1B6PziROP7/013E4qRO53Ns9fmGJ7FXE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kmLdC8ad; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kmLdC8ad" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70071C113D0; Mon, 24 Nov 2025 00:49:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763945398; bh=bUo6ak1zTCbJEyjFXZF8zQG8L5QXu94ygdsiABIZMis=; h=From:To:Cc:Subject:Date:From; b=kmLdC8adeRS9sgUr3rfggh04Rj+4FZS96P5oNR/eYzKD7hJ9kQiZYEOPRfjSufRqJ qoJh+eQEOSIooOE+RgUq6gZagAq1ZaMTZyzK/kx9UmQZHhWLinWb0Qm6Ov1rRaSrg9 sKIk3JCl+IoQolxMIPo4quMDZnR34PH45kUgaLyIeWAdZMJsPnSWkRJElw6hZfy2nL hLh1xDuTt8RAX2PKjkjWwiF+Ziiz8fNLUkxV23HC3yWb3MZURj4sGuFOwxqR7scpmM mJx6eL88v2gx2Xyc5+cKzCsQ9be6lJGc4lxX/ExL5e7ediSEu//b3mWsP1nJDcnuIS AgOykpGC6Splg== From: Jisheng Zhang To: Hoan Tran , Linus Walleij , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko , =?UTF-8?q?Michael=20B=C3=BCsch?= Subject: [PATCH v2] gpio: dwapb: Fold dwapb_context into dwapb_gpio_port Date: Mon, 24 Nov 2025 08:32:06 +0800 Message-ID: <20251124003206.25618-1-jszhang@kernel.org> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fold dwapb_context into struct dwapb_gpio_port to further simplify the code. Sure this brings a tiny 36 bytes data overhead for !PM_SLEEP. After grepping the arm/arm64/riscv dts dir, the max dwapb GPIO port number is 6(the berlin2q soc family), so this means we will waste 216 bytes memory in total which is trivial compared to the system memory. From another side, as Michael mentioned: "The driver currently allocates the struct with kzalloc and stores a pointer to it in case of PM=3Dy. So this probably has an overhead in the same order of magnitude (pointer + malloc overhead/alignment/fragmentation) in case of PM=3Dy now." So let's Fold dwapb_context into struct dwapb_gpio_port. Signed-off-by: Jisheng Zhang Reviewed-by: Linus Walleij --- since v1: - collect Reviewed-by tag - fix commmit msg - add a link to lore.kernel.org for the series which this patch is against. NOTE: this patch is applied against the following series: https://lore.kernel.org/linux-gpio/20251124002105.25429-1-jszhang@kernel.or= g/T/#t drivers/gpio/gpio-dwapb.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c index 4986c465c9a8..a431bea959ed 100644 --- a/drivers/gpio/gpio-dwapb.c +++ b/drivers/gpio/gpio-dwapb.c @@ -101,7 +101,7 @@ struct dwapb_gpio_port { struct gpio_generic_chip chip; struct dwapb_gpio_port_irqchip *pirq; struct dwapb_gpio *gpio; - struct dwapb_context *ctx; + struct dwapb_context ctx; unsigned int idx; }; =20 @@ -363,7 +363,7 @@ static int dwapb_irq_set_wake(struct irq_data *d, unsig= ned int enable) { struct gpio_chip *gc =3D irq_data_get_irq_chip_data(d); struct dwapb_gpio *gpio =3D to_dwapb_gpio(gc); - struct dwapb_context *ctx =3D gpio->ports[0].ctx; + struct dwapb_context *ctx =3D &gpio->ports[0].ctx; irq_hw_number_t bit =3D irqd_to_hwirq(d); =20 if (enable) @@ -507,12 +507,6 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio, port->gpio =3D gpio; port->idx =3D pp->idx; =20 -#ifdef CONFIG_PM_SLEEP - port->ctx =3D devm_kzalloc(gpio->dev, sizeof(*port->ctx), GFP_KERNEL); - if (!port->ctx) - return -ENOMEM; -#endif - dat =3D gpio->regs + GPIO_EXT_PORTA + pp->idx * GPIO_EXT_PORT_STRIDE; set =3D gpio->regs + GPIO_SWPORTA_DR + pp->idx * GPIO_SWPORT_DR_STRIDE; dirout =3D gpio->regs + GPIO_SWPORTA_DDR + pp->idx * GPIO_SWPORT_DDR_STRI= DE; @@ -761,7 +755,7 @@ static int dwapb_gpio_suspend(struct device *dev) for (i =3D 0; i < gpio->nr_ports; i++) { unsigned int offset; unsigned int idx =3D gpio->ports[i].idx; - struct dwapb_context *ctx =3D gpio->ports[i].ctx; + struct dwapb_context *ctx =3D &gpio->ports[i].ctx; =20 offset =3D GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_STRIDE; ctx->dir =3D dwapb_read(gpio, offset); @@ -809,7 +803,7 @@ static int dwapb_gpio_resume(struct device *dev) for (i =3D 0; i < gpio->nr_ports; i++) { unsigned int offset; unsigned int idx =3D gpio->ports[i].idx; - struct dwapb_context *ctx =3D gpio->ports[i].ctx; + struct dwapb_context *ctx =3D &gpio->ports[i].ctx; =20 offset =3D GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_STRIDE; dwapb_write(gpio, offset, ctx->data); --=20 2.51.0