[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2d02da3bebb2273782e535201cc9512f3cdbccab.1740926808.git.christophe.jaillet@wanadoo.fr>
Date: Sun, 2 Mar 2025 15:59:15 +0100
From: Christophe JAILLET <christophe.jaillet@...adoo.fr>
To: maddy@...ux.ibm.com,
mpe@...erman.id.au,
npiggin@...il.com,
christophe.leroy@...roup.eu,
naveen@...nel.org
Cc: linuxppc-dev@...ts.ozlabs.org,
linux-kernel@...r.kernel.org,
kernel-janitors@...r.kernel.org,
Christophe JAILLET <christophe.jaillet@...adoo.fr>
Subject: [PATCH 1/2] powerpc: gpio_mdio: Use devm_mdiobus_alloc_size()
Use mdiobus_alloc_size() instead of a hand written mdiobus_alloc() +
kzalloc().
This is less verbose and more robust. It also reduces memory fragmentation
and saves a few bytes of memory.
While at it, switch to devm_mdiobus_alloc_size() for extra simplification.
Signed-off-by: Christophe JAILLET <christophe.jaillet@...adoo.fr>
---
This patch is compile tested only.
Some memory is saved because pahole states, on a x86_64, that:
struct mii_bus {
...
/* size: 3640, cachelines: 57, members: 23 */
/* sum members: 3633, holes: 2, sum holes: 7 */
/* member types with holes: 3, total: 4, bit paddings: 1, total: 1 bit */
/* paddings: 1, sum paddings: 3 */
/* forced alignments: 1, forced holes: 1, sum forced holes: 4 */
/* last cacheline: 56 bytes */
}
Because of the way allocation works, 4096 bytes are allocated. When
mdiobus_alloc_size() is used, struct gpio_priv fits in this "wasted" space
and so is available "for free".
---
arch/powerpc/platforms/pasemi/gpio_mdio.c | 26 +++++------------------
1 file changed, 5 insertions(+), 21 deletions(-)
diff --git a/arch/powerpc/platforms/pasemi/gpio_mdio.c b/arch/powerpc/platforms/pasemi/gpio_mdio.c
index e4538d471256..2c54f5f063b7 100644
--- a/arch/powerpc/platforms/pasemi/gpio_mdio.c
+++ b/arch/powerpc/platforms/pasemi/gpio_mdio.c
@@ -213,15 +213,11 @@ static int gpio_mdio_probe(struct platform_device *ofdev)
const unsigned int *prop;
int err;
- err = -ENOMEM;
- priv = kzalloc(sizeof(struct gpio_priv), GFP_KERNEL);
- if (!priv)
- goto out;
-
- new_bus = mdiobus_alloc();
-
+ new_bus = devm_mdiobus_alloc_size(dev, sizeof(*priv));
if (!new_bus)
- goto out_free_priv;
+ return -ENOMEM;
+
+ priv = new_bus->priv;
new_bus->name = "pasemi gpio mdio bus";
new_bus->read = &gpio_mdio_read;
@@ -230,7 +226,6 @@ static int gpio_mdio_probe(struct platform_device *ofdev)
prop = of_get_property(np, "reg", NULL);
snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", *prop);
- new_bus->priv = priv;
prop = of_get_property(np, "mdc-pin", NULL);
priv->mdc_pin = *prop;
@@ -246,17 +241,10 @@ static int gpio_mdio_probe(struct platform_device *ofdev)
if (err != 0) {
pr_err("%s: Cannot register as MDIO bus, err %d\n",
new_bus->name, err);
- goto out_free_irq;
+ return err;
}
return 0;
-
-out_free_irq:
- kfree(new_bus);
-out_free_priv:
- kfree(priv);
-out:
- return err;
}
@@ -267,10 +255,6 @@ static void gpio_mdio_remove(struct platform_device *dev)
mdiobus_unregister(bus);
dev_set_drvdata(&dev->dev, NULL);
-
- kfree(bus->priv);
- bus->priv = NULL;
- mdiobus_free(bus);
}
static const struct of_device_id gpio_mdio_match[] =
--
2.48.1
Powered by blists - more mailing lists