Re: [RFC net-next 3/4] net: dsa: motorcomm: Dynamically allocate port structures

From: Andrew Lunn

Date: Fri Jun 19 2026 - 02:06:47 EST


On Fri, Jun 19, 2026 at 04:26:31AM +0800, David Yang wrote:
> With support for LED introduced later, struct yt921x_priv will be 17k
> which is not very good for a single kmalloc(). Convert the ports array
> to a array of pointers to stop bloating the priv struct.
>
> Signed-off-by: David Yang <mmyangfl@xxxxxxxxx>
> ---
> drivers/net/dsa/motorcomm/chip.c | 95 ++++++++++++++++++++++++--------
> drivers/net/dsa/motorcomm/chip.h | 3 +-
> 2 files changed, 75 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index 6dee25b6754a..d44f7749de02 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
> @@ -548,11 +548,14 @@ yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp)
> /* Read and handle overflow of 32bit MIBs. MIB buffer must be zeroed before. */
> static int yt921x_read_mib(struct yt921x_priv *priv, int port)
> {
> - struct yt921x_port *pp = &priv->ports[port];
> + struct yt921x_port *pp = priv->ports[port];
> struct device *dev = to_device(priv);
> struct yt921x_mib *mib = &pp->mib;
> int res = 0;
>
> + if (!pp)
> + return -ENODEV;
> +

Are all these tests actually needed? If you cannot allocate the
memory, i would expect the probe to fail, so you can never get here.

Andrew