[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240201225824.hajwp2dbj7zcbkgp@skbuf>
Date: Fri, 2 Feb 2024 00:58:24 +0200
From: Vladimir Oltean <olteanv@...il.com>
To: Luiz Angelo Daros de Luca <luizluca@...il.com>
Cc: Linus Walleij <linus.walleij@...aro.org>,
Alvin Šipraga <alsi@...g-olufsen.dk>,
Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Russell King <linux@...linux.org.uk>, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next v5 11/11] net: dsa: realtek: embed dsa_switch
into realtek_priv
On Tue, Jan 30, 2024 at 08:13:30PM -0300, Luiz Angelo Daros de Luca wrote:
> To eliminate the need for a second memory allocation for dsa_switch, it
> has been embedded within realtek_priv.
>
> Suggested-by: Alvin Šipraga <alsi@...g-olufsen.dk>
> Signed-off-by: Luiz Angelo Daros de Luca <luizluca@...il.com>
> ---
Reviewed-by: Vladimir Oltean <olteanv@...il.com>
I don't think it would be bad if you could just define a local variable
struct dsa_switch *ds = &priv->ds;
in all functions, including those which reference &priv->ds just once.
> diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h
> index 864bb9a88f14..b80bfde1ad04 100644
> --- a/drivers/net/dsa/realtek/realtek.h
> +++ b/drivers/net/dsa/realtek/realtek.h
> @@ -61,7 +61,7 @@ struct realtek_priv {
> const struct realtek_variant *variant;
>
> spinlock_t lock; /* Locks around command writes */
> - struct dsa_switch *ds;
> + struct dsa_switch ds;
> struct irq_domain *irqdomain;
> bool leds_disabled;
>
> diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c
> index 778a962727ab..9066e34e9ace 100644
> --- a/drivers/net/dsa/realtek/rtl8365mb.c
> +++ b/drivers/net/dsa/realtek/rtl8365mb.c
> @@ -880,7 +880,7 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,
> if (!extint)
> return -ENODEV;
>
> - dp = dsa_to_port(priv->ds, port);
> + dp = dsa_to_port(&priv->ds, port);
Nitpick: I don't think it would be bad if you could just define a local variable
struct dsa_switch *ds = &priv->ds;
in all functions, including those which reference &priv->ds just once,
like this one.
> dn = dp->dn;
>
> /* Set the RGMII TX/RX delay
> diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c
> index aa998e15c42b..f65e47339d5b 100644
> --- a/drivers/net/dsa/realtek/rtl83xx.c
> +++ b/drivers/net/dsa/realtek/rtl83xx.c
> @@ -226,16 +226,12 @@ int rtl83xx_register_switch(struct realtek_priv *priv)
> return ret;
> }
>
> - priv->ds = devm_kzalloc(priv->dev, sizeof(*priv->ds), GFP_KERNEL);
> - if (!priv->ds)
> - return -ENOMEM;
> + priv->ds.priv = priv;
> + priv->ds.dev = priv->dev;
> + priv->ds.ops = priv->variant->ds_ops;
> + priv->ds.num_ports = priv->num_ports;
And here, I think it would actually look better to dereference just
through "ds".
Also, priv->dev is dereferenced 4 times in rtl83xx_register_switch(),
maybe you could add a local variable for it in the patch that introduces
rtl83xx_register_switch().
>
> - priv->ds->priv = priv;
> - priv->ds->dev = priv->dev;
> - priv->ds->ops = priv->variant->ds_ops;
> - priv->ds->num_ports = priv->num_ports;
> -
> - ret = dsa_register_switch(priv->ds);
> + ret = dsa_register_switch(&priv->ds);
> if (ret) {
> dev_err_probe(priv->dev, ret, "unable to register switch\n");
> return ret;
Powered by blists - more mailing lists