linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: dwapb: Fold dwapb_context into dwapb_gpio_port
@ 2025-11-19 15:00 Jisheng Zhang
  2025-11-19 17:28 ` Linus Walleij
  2025-11-19 17:53 ` Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Jisheng Zhang @ 2025-11-19 15:00 UTC (permalink / raw)
  To: Hoan Tran, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko
  Cc: linux-gpio, linux-kernel, linux-riscv, Michael Büsch

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=y.
So this probably has an overhead in the same order of magnitude
(pointer + malloc overhead/alignment/fragmentation) in case of PM=y
now."

So let's Fold dwapb_context into struct dwapb_gpio_port.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
CC: Michael Büsch <mb@bues.ch>
---
NOTE: this patch is applied against the following series:
[PATCH v3 00/15] gpio: Use modern PM macros

 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;
 };
 
@@ -363,7 +363,7 @@ static int dwapb_irq_set_wake(struct irq_data *d, unsigned int enable)
 {
 	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
 	struct dwapb_gpio *gpio = to_dwapb_gpio(gc);
-	struct dwapb_context *ctx = gpio->ports[0].ctx;
+	struct dwapb_context *ctx = &gpio->ports[0].ctx;
 	irq_hw_number_t bit = irqd_to_hwirq(d);
 
 	if (enable)
@@ -507,12 +507,6 @@ static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
 	port->gpio = gpio;
 	port->idx = pp->idx;
 
-#ifdef CONFIG_PM_SLEEP
-	port->ctx = devm_kzalloc(gpio->dev, sizeof(*port->ctx), GFP_KERNEL);
-	if (!port->ctx)
-		return -ENOMEM;
-#endif
-
 	dat = gpio->regs + GPIO_EXT_PORTA + pp->idx * GPIO_EXT_PORT_STRIDE;
 	set = gpio->regs + GPIO_SWPORTA_DR + pp->idx * GPIO_SWPORT_DR_STRIDE;
 	dirout = gpio->regs + GPIO_SWPORTA_DDR + pp->idx * GPIO_SWPORT_DDR_STRIDE;
@@ -761,7 +755,7 @@ static int dwapb_gpio_suspend(struct device *dev)
 		for (i = 0; i < gpio->nr_ports; i++) {
 			unsigned int offset;
 			unsigned int idx = gpio->ports[i].idx;
-			struct dwapb_context *ctx = gpio->ports[i].ctx;
+			struct dwapb_context *ctx = &gpio->ports[i].ctx;
 
 			offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_STRIDE;
 			ctx->dir = dwapb_read(gpio, offset);
@@ -809,7 +803,7 @@ static int dwapb_gpio_resume(struct device *dev)
 	for (i = 0; i < gpio->nr_ports; i++) {
 		unsigned int offset;
 		unsigned int idx = gpio->ports[i].idx;
-		struct dwapb_context *ctx = gpio->ports[i].ctx;
+		struct dwapb_context *ctx = &gpio->ports[i].ctx;
 
 		offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_STRIDE;
 		dwapb_write(gpio, offset, ctx->data);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: dwapb: Fold dwapb_context into dwapb_gpio_port
  2025-11-19 15:00 [PATCH] gpio: dwapb: Fold dwapb_context into dwapb_gpio_port Jisheng Zhang
@ 2025-11-19 17:28 ` Linus Walleij
  2025-11-19 17:53 ` Andy Shevchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2025-11-19 17:28 UTC (permalink / raw)
  To: Jisheng Zhang
  Cc: Hoan Tran, Bartosz Golaszewski, Andy Shevchenko, linux-gpio,
	linux-kernel, linux-riscv, Michael Büsch

On Wed, Nov 19, 2025 at 4:18 PM Jisheng Zhang <jszhang@kernel.org> wrote:

> 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=y.
> So this probably has an overhead in the same order of magnitude
> (pointer + malloc overhead/alignment/fragmentation) in case of PM=y
> now."
>
> So let's Fold dwapb_context into struct dwapb_gpio_port.
>
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> CC: Michael Büsch <mb@bues.ch>

Neat.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: dwapb: Fold dwapb_context into dwapb_gpio_port
  2025-11-19 15:00 [PATCH] gpio: dwapb: Fold dwapb_context into dwapb_gpio_port Jisheng Zhang
  2025-11-19 17:28 ` Linus Walleij
@ 2025-11-19 17:53 ` Andy Shevchenko
  2025-11-19 23:59   ` Jisheng Zhang
  2025-11-20 13:19   ` Bartosz Golaszewski
  1 sibling, 2 replies; 5+ messages in thread
From: Andy Shevchenko @ 2025-11-19 17:53 UTC (permalink / raw)
  To: Jisheng Zhang
  Cc: Hoan Tran, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko,
	linux-gpio, linux-kernel, linux-riscv, Michael Büsch

On Wed, Nov 19, 2025 at 11:00:49PM +0800, Jisheng Zhang wrote:
> 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

GPIO

*and I believe this is limitation by Synopsys in HW, but I'm not going to check
the datasheet right now.

> 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=y.
> So this probably has an overhead in the same order of magnitude
> (pointer + malloc overhead/alignment/fragmentation) in case of PM=y
> now."
> 
> So let's Fold dwapb_context into struct dwapb_gpio_port.
> 
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>

> CC: Michael Büsch <mb@bues.ch>

Please, use --cc or move Cc list below...

> ---

...this cutter line. It will have the same effect on the emails, but it will
reduce the noise in the commit message.

> NOTE: this patch is applied against the following series:
> [PATCH v3 00/15] gpio: Use modern PM macros

It's better to just put a link to lore.kernel.org or at least message-id.

...

I have a mixed feelings about this, but if maintainers go with it,
let it be then.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: dwapb: Fold dwapb_context into dwapb_gpio_port
  2025-11-19 17:53 ` Andy Shevchenko
@ 2025-11-19 23:59   ` Jisheng Zhang
  2025-11-20 13:19   ` Bartosz Golaszewski
  1 sibling, 0 replies; 5+ messages in thread
From: Jisheng Zhang @ 2025-11-19 23:59 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Hoan Tran, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko,
	linux-gpio, linux-kernel, linux-riscv, Michael Büsch

On Wed, Nov 19, 2025 at 07:53:20PM +0200, Andy Shevchenko wrote:
> On Wed, Nov 19, 2025 at 11:00:49PM +0800, Jisheng Zhang wrote:
> > 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
> 
> GPIO
> 
> *and I believe this is limitation by Synopsys in HW, but I'm not going to check
> the datasheet right now.

snps doesn't limit this. The max dwapb gpio controller number is 6 as
is grepped the arm/arm64/riscv etc. dts dir.
> 
> > 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=y.
> > So this probably has an overhead in the same order of magnitude
> > (pointer + malloc overhead/alignment/fragmentation) in case of PM=y
> > now."
> > 
> > So let's Fold dwapb_context into struct dwapb_gpio_port.
> > 
> > Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> 
> > CC: Michael Büsch <mb@bues.ch>
> 
> Please, use --cc or move Cc list below...
> 
> > ---
> 
> ...this cutter line. It will have the same effect on the emails, but it will
> reduce the noise in the commit message.
> 
> > NOTE: this patch is applied against the following series:
> > [PATCH v3 00/15] gpio: Use modern PM macros
> 
> It's better to just put a link to lore.kernel.org or at least message-id.
> 
> ...
> 
> I have a mixed feelings about this, but if maintainers go with it,
> let it be then.
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: dwapb: Fold dwapb_context into dwapb_gpio_port
  2025-11-19 17:53 ` Andy Shevchenko
  2025-11-19 23:59   ` Jisheng Zhang
@ 2025-11-20 13:19   ` Bartosz Golaszewski
  1 sibling, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2025-11-20 13:19 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Hoan Tran, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko,
	linux-gpio, linux-kernel, linux-riscv, Michael Büsch,
	Jisheng Zhang

On Wed, 19 Nov 2025 18:53:20 +0100, Andy Shevchenko
<andriy.shevchenko@intel.com> said:
> On Wed, Nov 19, 2025 at 11:00:49PM +0800, Jisheng Zhang wrote:
>> 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
>
> GPIO
>
> *and I believe this is limitation by Synopsys in HW, but I'm not going to check
> the datasheet right now.
>
>> 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=y.
>> So this probably has an overhead in the same order of magnitude
>> (pointer + malloc overhead/alignment/fragmentation) in case of PM=y
>> now."
>>
>> So let's Fold dwapb_context into struct dwapb_gpio_port.
>>
>> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
>
>> CC: Michael Büsch <mb@bues.ch>
>
> Please, use --cc or move Cc list below...
>
>> ---
>
> ...this cutter line. It will have the same effect on the emails, but it will
> reduce the noise in the commit message.
>
>> NOTE: this patch is applied against the following series:
>> [PATCH v3 00/15] gpio: Use modern PM macros
>
> It's better to just put a link to lore.kernel.org or at least message-id.
>
> ...
>
> I have a mixed feelings about this, but if maintainers go with it,
> let it be then.
>

I don't mind it so please resend it with the issues addressed, Jisheng.

Bart

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-11-20 13:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-19 15:00 [PATCH] gpio: dwapb: Fold dwapb_context into dwapb_gpio_port Jisheng Zhang
2025-11-19 17:28 ` Linus Walleij
2025-11-19 17:53 ` Andy Shevchenko
2025-11-19 23:59   ` Jisheng Zhang
2025-11-20 13:19   ` Bartosz Golaszewski

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).