Re: [PATCH net-next v2 2/5] net: marvell: prestera: allocate dummy net_device dynamically

From: Breno Leitao
Date: Wed Apr 03 2024 - 10:30:52 EST


On Sun, Mar 31, 2024 at 09:54:38AM +0100, Simon Horman wrote:
> On Thu, Mar 28, 2024 at 04:52:02PM -0700, Breno Leitao wrote:
> > Embedding net_device into structures prohibits the usage of flexible
> > arrays in the net_device structure. For more details, see the discussion
> > at [1].
> >
> > Un-embed the net_device from the private struct by converting it
> > into a pointer. Then use the leverage the new alloc_netdev_dummy()
> > helper to allocate and initialize dummy devices.
> >
> > [1] https://lore.kernel.org/all/20240229225910.79e224cf@xxxxxxxxxx/
> >
> > Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> > ---
> > .../net/ethernet/marvell/prestera/prestera_rxtx.c | 15 ++++++++++++---
> > 1 file changed, 12 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c b/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c
>
> ...
>
> > @@ -654,13 +654,21 @@ static int prestera_sdma_switch_init(struct prestera_switch *sw)
> > if (err)
> > goto err_evt_register;
> >
> > - init_dummy_netdev(&sdma->napi_dev);
> > + sdma->napi_dev = alloc_netdev_dummy(0);
> > + if (!sdma->napi_dev) {
> > + dev_err(dev, "not able to initialize dummy device\n");
> > + goto err_alloc_dummy;
>
> Hi Breno,
>
> This goto will result in the function returning err.
> But err is 0 here. Perhaps it should be set to a negative error value
> instead?

Definitely, that was a good catch.

> Flagged by Smatch.

I am curious how you are running Smatch. I tried to run it here
according to[1] , and I found different and valid errors also, that I
will fix soon. For instance:

drivers/net/ethernet/marvell/prestera/prestera_main.c:433 prestera_port_sfp_bind() error: uninitialized symbol 'err'.
drivers/net/ethernet/marvell/prestera/prestera_main.c:861 prestera_switch_set_base_mac_addr() error: uninitialized symbol 'ret'.

[1] https://rajanvaja.wordpress.com/2021/02/06/how-to-run-smatch-on-linux-kernel/

Thanks