Skip to content

Commit

Permalink
net: dsa: sja1105: call dsa_unregister_switch when allocating memory …
Browse files Browse the repository at this point in the history
…fails

commit dc596e3 upstream.

Unlike other drivers which pretty much end their .probe() execution with
dsa_register_switch(), the sja1105 does some extra stuff. When that
fails with -ENOMEM, the driver is quick to return that, forgetting to
call dsa_unregister_switch(). Not critical, but a bug nonetheless.

Fixes: 4d75250 ("net: dsa: sja1105: offload the Credit-Based Shaper qdisc")
Fixes: a68578c ("net: dsa: Make deferred_xmit private to sja1105")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
vladimiroltean authored and gregkh committed Jun 3, 2021
1 parent dd8609f commit 83999bf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions drivers/net/dsa/sja1105/sja1105_main.c
Expand Up @@ -3483,8 +3483,10 @@ static int sja1105_probe(struct spi_device *spi)
priv->cbs = devm_kcalloc(dev, priv->info->num_cbs_shapers,
sizeof(struct sja1105_cbs_entry),
GFP_KERNEL);
if (!priv->cbs)
return -ENOMEM;
if (!priv->cbs) {
rc = -ENOMEM;
goto out_unregister_switch;
}
}

/* Connections between dsa_port and sja1105_port */
Expand All @@ -3509,7 +3511,7 @@ static int sja1105_probe(struct spi_device *spi)
dev_err(ds->dev,
"failed to create deferred xmit thread: %d\n",
rc);
goto out;
goto out_destroy_workers;
}
skb_queue_head_init(&sp->xmit_queue);
sp->xmit_tpid = ETH_P_SJA1105;
Expand All @@ -3519,7 +3521,8 @@ static int sja1105_probe(struct spi_device *spi)
}

return 0;
out:

out_destroy_workers:
while (port-- > 0) {
struct sja1105_port *sp = &priv->ports[port];

Expand All @@ -3528,6 +3531,10 @@ static int sja1105_probe(struct spi_device *spi)

kthread_destroy_worker(sp->xmit_worker);
}

out_unregister_switch:
dsa_unregister_switch(ds);

return rc;
}

Expand Down

0 comments on commit 83999bf

Please sign in to comment.