[PATCH v1 4/5] pinctrl: intel: Refactor intel_gpio_add_pin_ranges() to make it shorter

Andy Shevchenko posted 5 patches 2 weeks, 5 days ago
[PATCH v1 4/5] pinctrl: intel: Refactor intel_gpio_add_pin_ranges() to make it shorter
Posted by Andy Shevchenko 2 weeks, 5 days ago
Refactor intel_gpio_add_pin_ranges() to make it shorter in binary
and source formats.

Function                                     old     new   delta
intel_gpio_add_pin_ranges                    219     215      -4
Total: Before=15522, After=15518, chg -0.03%

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/intel/pinctrl-intel.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
index 97bf5ec78db4..7311b787dfc6 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -1361,16 +1361,15 @@ static int intel_gpio_irq_init_hw(struct gpio_chip *gc)
 int intel_gpio_add_pin_ranges(struct gpio_chip *gc)
 {
 	struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
+	const struct device *dev = pctrl->dev;
 	const struct intel_community *community;
 	const struct intel_padgroup *grp;
 	int ret;
 
 	for_each_intel_gpio_group(pctrl, community, grp) {
-		ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev),
-					     grp->gpio_base, grp->base,
-					     grp->size);
+		ret = gpiochip_add_pin_range(gc, dev_name(dev), grp->gpio_base, grp->base, grp->size);
 		if (ret)
-			return dev_err_probe(pctrl->dev, ret, "failed to add GPIO pin range\n");
+			return dev_err_probe(dev, ret, "failed to add GPIO pin range\n");
 	}
 
 	return 0;
-- 
2.50.1
Re: [PATCH v1 4/5] pinctrl: intel: Refactor intel_gpio_add_pin_ranges() to make it shorter
Posted by Mika Westerberg 2 weeks, 4 days ago
On Wed, Mar 18, 2026 at 04:10:18PM +0100, Andy Shevchenko wrote:
> Refactor intel_gpio_add_pin_ranges() to make it shorter in binary
> and source formats.
> 
> Function                                     old     new   delta
> intel_gpio_add_pin_ranges                    219     215      -4
> Total: Before=15522, After=15518, chg -0.03%

Well if you enable optimization the compiler probably puts this into
register and you don't see any changes here. Also code-wise this is
neglible IMHO.
Re: [PATCH v1 4/5] pinctrl: intel: Refactor intel_gpio_add_pin_ranges() to make it shorter
Posted by Andy Shevchenko 2 weeks, 4 days ago
On Thu, Mar 19, 2026 at 07:03:45AM +0100, Mika Westerberg wrote:
> On Wed, Mar 18, 2026 at 04:10:18PM +0100, Andy Shevchenko wrote:
> > Refactor intel_gpio_add_pin_ranges() to make it shorter in binary
> > and source formats.
> > 
> > Function                                     old     new   delta
> > intel_gpio_add_pin_ranges                    219     215      -4
> > Total: Before=15522, After=15518, chg -0.03%
> 
> Well if you enable optimization the compiler probably puts this into
> register and you don't see any changes here.

What do you mean? I do not alter what kernel uses.

> Also code-wise this is neglible IMHO.

Maybe, but still good to have also shorter in source as well — we have
-1 LoC at the end of the day.

-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH v1 4/5] pinctrl: intel: Refactor intel_gpio_add_pin_ranges() to make it shorter
Posted by Mika Westerberg 2 weeks, 4 days ago
On Thu, Mar 19, 2026 at 08:56:04AM +0200, Andy Shevchenko wrote:
> On Thu, Mar 19, 2026 at 07:03:45AM +0100, Mika Westerberg wrote:
> > On Wed, Mar 18, 2026 at 04:10:18PM +0100, Andy Shevchenko wrote:
> > > Refactor intel_gpio_add_pin_ranges() to make it shorter in binary
> > > and source formats.
> > > 
> > > Function                                     old     new   delta
> > > intel_gpio_add_pin_ranges                    219     215      -4
> > > Total: Before=15522, After=15518, chg -0.03%
> > 
> > Well if you enable optimization the compiler probably puts this into
> > register and you don't see any changes here.
> 
> What do you mean? I do not alter what kernel uses.

Enable -Ox and compare then. I think there is Kconfig option for that too.

> > Also code-wise this is neglible IMHO.
> 
> Maybe, but still good to have also shorter in source as well — we have
> -1 LoC at the end of the day.

Well this is silly. Your other patch adds "unsigned " to every other place
growing the driver "horizonally" but that's okay.
Re: [PATCH v1 4/5] pinctrl: intel: Refactor intel_gpio_add_pin_ranges() to make it shorter
Posted by Andy Shevchenko 2 weeks, 4 days ago
On Thu, Mar 19, 2026 at 08:07:16AM +0100, Mika Westerberg wrote:
> On Thu, Mar 19, 2026 at 08:56:04AM +0200, Andy Shevchenko wrote:
> > On Thu, Mar 19, 2026 at 07:03:45AM +0100, Mika Westerberg wrote:
> > > On Wed, Mar 18, 2026 at 04:10:18PM +0100, Andy Shevchenko wrote:
> > > > Refactor intel_gpio_add_pin_ranges() to make it shorter in binary
> > > > and source formats.
> > > > 
> > > > Function                                     old     new   delta
> > > > intel_gpio_add_pin_ranges                    219     215      -4
> > > > Total: Before=15522, After=15518, chg -0.03%
> > > 
> > > Well if you enable optimization the compiler probably puts this into
> > > register and you don't see any changes here.
> > 
> > What do you mean? I do not alter what kernel uses.
> 
> Enable -Ox and compare then. I think there is Kconfig option for that too.

I don't see it. Can you elaborate?

> > > Also code-wise this is neglible IMHO.
> > 
> > Maybe, but still good to have also shorter in source as well — we have
> > -1 LoC at the end of the day.
> 
> Well this is silly.

You usually likes - statistics. So, here we are.

> Your other patch adds "unsigned " to every other place
> growing the driver "horizonally" but that's okay.

That's unrelated to this patch and to this certain improvement.

-- 
With Best Regards,
Andy Shevchenko