Re: [RFC net-next 3/4] net: dsa: motorcomm: Dynamically allocate port structures
From: Andrew Lunn
Date: Sat Jun 20 2026 - 04:04:59 EST
On Fri, Jun 19, 2026 at 02:46:24PM +0800, David Yang wrote:
> On Fri, Jun 19, 2026 at 2:06 PM Andrew Lunn <andrew@xxxxxxx> wrote:
> >
> > 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
>
> Dummy ports are no longer assigned control blocks (in yt921x_dsa_setup).
This seems pretty error prone. A missing check will result in an
opps. At least it will be obvious. How big is each port structure? Is
the memory saving worth it?
Andrew