Skip to content

Commit

Permalink
can: mcp251x: add error check when wq alloc failed
Browse files Browse the repository at this point in the history
add error check when workqueue alloc failed, and remove redundant code
to make it clear.

Fixes: e000016 ("can: Driver for the Microchip MCP251x SPI CAN controllers")
Signed-off-by: Weitao Hou <houweitaoo@gmail.com>
Acked-by: Willem de Bruijn <willemb@google.com>
Tested-by: Sean Nyekjaer <sean@geanix.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Weitao Hou authored and Marc Kleine-Budde committed Jul 24, 2019
1 parent d4b890a commit 375f755
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions drivers/net/can/spi/mcp251x.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,17 +664,6 @@ static int mcp251x_power_enable(struct regulator *reg, int enable)
return regulator_disable(reg);
}

static void mcp251x_open_clean(struct net_device *net)
{
struct mcp251x_priv *priv = netdev_priv(net);
struct spi_device *spi = priv->spi;

free_irq(spi->irq, priv);
mcp251x_hw_sleep(spi);
mcp251x_power_enable(priv->transceiver, 0);
close_candev(net);
}

static int mcp251x_stop(struct net_device *net)
{
struct mcp251x_priv *priv = netdev_priv(net);
Expand Down Expand Up @@ -940,37 +929,43 @@ static int mcp251x_open(struct net_device *net)
flags | IRQF_ONESHOT, DEVICE_NAME, priv);
if (ret) {
dev_err(&spi->dev, "failed to acquire irq %d\n", spi->irq);
mcp251x_power_enable(priv->transceiver, 0);
close_candev(net);
goto open_unlock;
goto out_close;
}

priv->wq = alloc_workqueue("mcp251x_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
0);
if (!priv->wq) {
ret = -ENOMEM;
goto out_clean;
}
INIT_WORK(&priv->tx_work, mcp251x_tx_work_handler);
INIT_WORK(&priv->restart_work, mcp251x_restart_work_handler);

ret = mcp251x_hw_reset(spi);
if (ret) {
mcp251x_open_clean(net);
goto open_unlock;
}
if (ret)
goto out_free_wq;
ret = mcp251x_setup(net, spi);
if (ret) {
mcp251x_open_clean(net);
goto open_unlock;
}
if (ret)
goto out_free_wq;
ret = mcp251x_set_normal_mode(spi);
if (ret) {
mcp251x_open_clean(net);
goto open_unlock;
}
if (ret)
goto out_free_wq;

can_led_event(net, CAN_LED_EVENT_OPEN);

netif_wake_queue(net);
mutex_unlock(&priv->mcp_lock);

open_unlock:
return 0;

out_free_wq:
destroy_workqueue(priv->wq);
out_clean:
free_irq(spi->irq, priv);
mcp251x_hw_sleep(spi);
out_close:
mcp251x_power_enable(priv->transceiver, 0);
close_candev(net);
mutex_unlock(&priv->mcp_lock);
return ret;
}
Expand Down

0 comments on commit 375f755

Please sign in to comment.