Commit 3b734ff6 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

nfp: flower: fix error path during representor creation

Don't store repr pointer to reprs array until the representor is
successfully created. This avoids message about "representor
destruction" even when it was never created. Also it cleans-up the flow.
Also, check return value after port alloc.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6d9f868f
...@@ -247,12 +247,16 @@ nfp_flower_spawn_vnic_reprs(struct nfp_app *app, ...@@ -247,12 +247,16 @@ nfp_flower_spawn_vnic_reprs(struct nfp_app *app,
err = -ENOMEM; err = -ENOMEM;
goto err_reprs_clean; goto err_reprs_clean;
} }
RCU_INIT_POINTER(reprs->reprs[i], repr);
/* For now we only support 1 PF */ /* For now we only support 1 PF */
WARN_ON(repr_type == NFP_REPR_TYPE_PF && i); WARN_ON(repr_type == NFP_REPR_TYPE_PF && i);
port = nfp_port_alloc(app, port_type, repr); port = nfp_port_alloc(app, port_type, repr);
if (IS_ERR(port)) {
err = PTR_ERR(port);
nfp_repr_free(repr);
goto err_reprs_clean;
}
if (repr_type == NFP_REPR_TYPE_PF) { if (repr_type == NFP_REPR_TYPE_PF) {
port->pf_id = i; port->pf_id = i;
port->vnic = priv->nn->dp.ctrl_bar; port->vnic = priv->nn->dp.ctrl_bar;
...@@ -271,9 +275,11 @@ nfp_flower_spawn_vnic_reprs(struct nfp_app *app, ...@@ -271,9 +275,11 @@ nfp_flower_spawn_vnic_reprs(struct nfp_app *app,
port_id, port, priv->nn->dp.netdev); port_id, port, priv->nn->dp.netdev);
if (err) { if (err) {
nfp_port_free(port); nfp_port_free(port);
nfp_repr_free(repr);
goto err_reprs_clean; goto err_reprs_clean;
} }
RCU_INIT_POINTER(reprs->reprs[i], repr);
nfp_info(app->cpp, "%s%d Representor(%s) created\n", nfp_info(app->cpp, "%s%d Representor(%s) created\n",
repr_type == NFP_REPR_TYPE_PF ? "PF" : "VF", i, repr_type == NFP_REPR_TYPE_PF ? "PF" : "VF", i,
repr->name); repr->name);
...@@ -344,16 +350,17 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv) ...@@ -344,16 +350,17 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv)
err = -ENOMEM; err = -ENOMEM;
goto err_reprs_clean; goto err_reprs_clean;
} }
RCU_INIT_POINTER(reprs->reprs[phys_port], repr);
port = nfp_port_alloc(app, NFP_PORT_PHYS_PORT, repr); port = nfp_port_alloc(app, NFP_PORT_PHYS_PORT, repr);
if (IS_ERR(port)) { if (IS_ERR(port)) {
err = PTR_ERR(port); err = PTR_ERR(port);
nfp_repr_free(repr);
goto err_reprs_clean; goto err_reprs_clean;
} }
err = nfp_port_init_phy_port(app->pf, app, port, i); err = nfp_port_init_phy_port(app->pf, app, port, i);
if (err) { if (err) {
nfp_port_free(port); nfp_port_free(port);
nfp_repr_free(repr);
goto err_reprs_clean; goto err_reprs_clean;
} }
...@@ -365,6 +372,7 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv) ...@@ -365,6 +372,7 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv)
cmsg_port_id, port, priv->nn->dp.netdev); cmsg_port_id, port, priv->nn->dp.netdev);
if (err) { if (err) {
nfp_port_free(port); nfp_port_free(port);
nfp_repr_free(repr);
goto err_reprs_clean; goto err_reprs_clean;
} }
...@@ -373,6 +381,7 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv) ...@@ -373,6 +381,7 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv)
eth_tbl->ports[i].base, eth_tbl->ports[i].base,
phys_port); phys_port);
RCU_INIT_POINTER(reprs->reprs[phys_port], repr);
nfp_info(app->cpp, "Phys Port %d Representor(%s) created\n", nfp_info(app->cpp, "Phys Port %d Representor(%s) created\n",
phys_port, repr->name); phys_port, repr->name);
} }
......
...@@ -348,12 +348,17 @@ int nfp_repr_init(struct nfp_app *app, struct net_device *netdev, ...@@ -348,12 +348,17 @@ int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,
return err; return err;
} }
static void nfp_repr_free(struct nfp_repr *repr) static void __nfp_repr_free(struct nfp_repr *repr)
{ {
free_percpu(repr->stats); free_percpu(repr->stats);
free_netdev(repr->netdev); free_netdev(repr->netdev);
} }
void nfp_repr_free(struct net_device *netdev)
{
__nfp_repr_free(netdev_priv(netdev));
}
struct net_device *nfp_repr_alloc(struct nfp_app *app) struct net_device *nfp_repr_alloc(struct nfp_app *app)
{ {
struct net_device *netdev; struct net_device *netdev;
...@@ -385,7 +390,7 @@ static void nfp_repr_clean_and_free(struct nfp_repr *repr) ...@@ -385,7 +390,7 @@ static void nfp_repr_clean_and_free(struct nfp_repr *repr)
nfp_info(repr->app->cpp, "Destroying Representor(%s)\n", nfp_info(repr->app->cpp, "Destroying Representor(%s)\n",
repr->netdev->name); repr->netdev->name);
nfp_repr_clean(repr); nfp_repr_clean(repr);
nfp_repr_free(repr); __nfp_repr_free(repr);
} }
void nfp_reprs_clean_and_free(struct nfp_app *app, struct nfp_reprs *reprs) void nfp_reprs_clean_and_free(struct nfp_app *app, struct nfp_reprs *reprs)
......
...@@ -123,6 +123,7 @@ void nfp_repr_inc_rx_stats(struct net_device *netdev, unsigned int len); ...@@ -123,6 +123,7 @@ void nfp_repr_inc_rx_stats(struct net_device *netdev, unsigned int len);
int nfp_repr_init(struct nfp_app *app, struct net_device *netdev, int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,
u32 cmsg_port_id, struct nfp_port *port, u32 cmsg_port_id, struct nfp_port *port,
struct net_device *pf_netdev); struct net_device *pf_netdev);
void nfp_repr_free(struct net_device *netdev);
struct net_device *nfp_repr_alloc(struct nfp_app *app); struct net_device *nfp_repr_alloc(struct nfp_app *app);
void nfp_reprs_clean_and_free(struct nfp_app *app, struct nfp_reprs *reprs); void nfp_reprs_clean_and_free(struct nfp_app *app, struct nfp_reprs *reprs);
void nfp_reprs_clean_and_free_by_type(struct nfp_app *app, void nfp_reprs_clean_and_free_by_type(struct nfp_app *app,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment