* [PATCH net-next] net: dsa: mt7530: Constify struct regmap_config
@ 2025-07-13 15:09 Christophe JAILLET
2025-07-13 20:36 ` Daniel Golle
2025-07-13 21:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2025-07-13 15:09 UTC (permalink / raw)
To: Chester A. Unal, Daniel Golle, DENG Qingfang, Sean Wang,
Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Matthias Brugger,
AngeloGioacchino Del Regno
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, netdev,
linux-arm-kernel, linux-mediatek
'struct regmap_config' are not modified in these drivers. They be
statically defined instead of allocated and populated at run-time.
The main benefits are:
- it saves some memory at runtime
- the structures can be declared as 'const', which is always better for
structures that hold some function pointers
- the code is less verbose
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/net/dsa/mt7530-mdio.c | 21 +++++++++------------
drivers/net/dsa/mt7530-mmio.c | 21 ++++++++++-----------
2 files changed, 19 insertions(+), 23 deletions(-)
diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c
index 51df42ccdbe6..0286a6cecb6f 100644
--- a/drivers/net/dsa/mt7530-mdio.c
+++ b/drivers/net/dsa/mt7530-mdio.c
@@ -136,10 +136,17 @@ static const struct of_device_id mt7530_of_match[] = {
};
MODULE_DEVICE_TABLE(of, mt7530_of_match);
+static const struct regmap_config regmap_config = {
+ .reg_bits = 16,
+ .val_bits = 32,
+ .reg_stride = 4,
+ .max_register = MT7530_CREV,
+ .disable_locking = true,
+};
+
static int
mt7530_probe(struct mdio_device *mdiodev)
{
- static struct regmap_config *regmap_config;
struct mt7530_priv *priv;
struct device_node *dn;
int ret;
@@ -193,18 +200,8 @@ mt7530_probe(struct mdio_device *mdiodev)
return PTR_ERR(priv->io_pwr);
}
- regmap_config = devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config),
- GFP_KERNEL);
- if (!regmap_config)
- return -ENOMEM;
-
- regmap_config->reg_bits = 16;
- regmap_config->val_bits = 32;
- regmap_config->reg_stride = 4;
- regmap_config->max_register = MT7530_CREV;
- regmap_config->disable_locking = true;
priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus, priv,
- regmap_config);
+ ®map_config);
if (IS_ERR(priv->regmap))
return PTR_ERR(priv->regmap);
diff --git a/drivers/net/dsa/mt7530-mmio.c b/drivers/net/dsa/mt7530-mmio.c
index 842d74268e77..1dc8b93fb51a 100644
--- a/drivers/net/dsa/mt7530-mmio.c
+++ b/drivers/net/dsa/mt7530-mmio.c
@@ -18,10 +18,17 @@ static const struct of_device_id mt7988_of_match[] = {
};
MODULE_DEVICE_TABLE(of, mt7988_of_match);
+static const struct regmap_config sw_regmap_config = {
+ .name = "switch",
+ .reg_bits = 16,
+ .val_bits = 32,
+ .reg_stride = 4,
+ .max_register = MT7530_CREV,
+};
+
static int
mt7988_probe(struct platform_device *pdev)
{
- static struct regmap_config *sw_regmap_config;
struct mt7530_priv *priv;
void __iomem *base_addr;
int ret;
@@ -49,16 +56,8 @@ mt7988_probe(struct platform_device *pdev)
return -ENXIO;
}
- sw_regmap_config = devm_kzalloc(&pdev->dev, sizeof(*sw_regmap_config), GFP_KERNEL);
- if (!sw_regmap_config)
- return -ENOMEM;
-
- sw_regmap_config->name = "switch";
- sw_regmap_config->reg_bits = 16;
- sw_regmap_config->val_bits = 32;
- sw_regmap_config->reg_stride = 4;
- sw_regmap_config->max_register = MT7530_CREV;
- priv->regmap = devm_regmap_init_mmio(&pdev->dev, base_addr, sw_regmap_config);
+ priv->regmap = devm_regmap_init_mmio(&pdev->dev, base_addr,
+ &sw_regmap_config);
if (IS_ERR(priv->regmap))
return PTR_ERR(priv->regmap);
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: dsa: mt7530: Constify struct regmap_config
2025-07-13 15:09 [PATCH net-next] net: dsa: mt7530: Constify struct regmap_config Christophe JAILLET
@ 2025-07-13 20:36 ` Daniel Golle
2025-07-13 21:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Golle @ 2025-07-13 20:36 UTC (permalink / raw)
To: Christophe JAILLET
Cc: Chester A. Unal, DENG Qingfang, Sean Wang, Andrew Lunn,
Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Matthias Brugger, AngeloGioacchino Del Regno,
linux-kernel, kernel-janitors, netdev, linux-arm-kernel,
linux-mediatek
On Sun, Jul 13, 2025 at 05:09:24PM +0200, Christophe JAILLET wrote:
> 'struct regmap_config' are not modified in these drivers. They be
> statically defined instead of allocated and populated at run-time.
>
> The main benefits are:
> - it saves some memory at runtime
> - the structures can be declared as 'const', which is always better for
> structures that hold some function pointers
> - the code is less verbose
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> drivers/net/dsa/mt7530-mdio.c | 21 +++++++++------------
> drivers/net/dsa/mt7530-mmio.c | 21 ++++++++++-----------
> 2 files changed, 19 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c
> index 51df42ccdbe6..0286a6cecb6f 100644
> --- a/drivers/net/dsa/mt7530-mdio.c
> +++ b/drivers/net/dsa/mt7530-mdio.c
> @@ -136,10 +136,17 @@ static const struct of_device_id mt7530_of_match[] = {
> };
> MODULE_DEVICE_TABLE(of, mt7530_of_match);
>
> +static const struct regmap_config regmap_config = {
Maybe calling this one 'regmap_config_mdio'...
> + .reg_bits = 16,
> + .val_bits = 32,
> + .reg_stride = 4,
> + .max_register = MT7530_CREV,
> + .disable_locking = true,
> +};
> +
> ...
> diff --git a/drivers/net/dsa/mt7530-mmio.c b/drivers/net/dsa/mt7530-mmio.c
> index 842d74268e77..1dc8b93fb51a 100644
> --- a/drivers/net/dsa/mt7530-mmio.c
> +++ b/drivers/net/dsa/mt7530-mmio.c
> @@ -18,10 +18,17 @@ static const struct of_device_id mt7988_of_match[] = {
> };
> MODULE_DEVICE_TABLE(of, mt7988_of_match);
>
> +static const struct regmap_config sw_regmap_config = {
... and this one 'regmap_config_mmio' would be a bit nicer.
> + .name = "switch",
> + .reg_bits = 16,
> + .val_bits = 32,
> + .reg_stride = 4,
> + .max_register = MT7530_CREV,
> +};
> +
Other than that:
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: dsa: mt7530: Constify struct regmap_config
2025-07-13 15:09 [PATCH net-next] net: dsa: mt7530: Constify struct regmap_config Christophe JAILLET
2025-07-13 20:36 ` Daniel Golle
@ 2025-07-13 21:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-07-13 21:40 UTC (permalink / raw)
To: Christophe JAILLET
Cc: chester.a.unal, daniel, dqfext, sean.wang, andrew, olteanv, davem,
edumazet, kuba, pabeni, matthias.bgg, angelogioacchino.delregno,
linux-kernel, kernel-janitors, netdev, linux-arm-kernel,
linux-mediatek
Hello:
This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:
On Sun, 13 Jul 2025 17:09:24 +0200 you wrote:
> 'struct regmap_config' are not modified in these drivers. They be
> statically defined instead of allocated and populated at run-time.
>
> The main benefits are:
> - it saves some memory at runtime
> - the structures can be declared as 'const', which is always better for
> structures that hold some function pointers
> - the code is less verbose
>
> [...]
Here is the summary with links:
- [net-next] net: dsa: mt7530: Constify struct regmap_config
https://git.kernel.org/netdev/net-next/c/9eb73f92a0b0
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-13 21:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-13 15:09 [PATCH net-next] net: dsa: mt7530: Constify struct regmap_config Christophe JAILLET
2025-07-13 20:36 ` Daniel Golle
2025-07-13 21:40 ` patchwork-bot+netdevbpf
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).