Commit 32571035 authored by Weitao Hou's avatar Weitao Hou Committed by Greg Kroah-Hartman

can: mcp251x: add error check when wq alloc failed

[ Upstream commit 375f7558 ]

add error check when workqueue alloc failed, and remove redundant code
to make it clear.

Fixes: e0000163 ("can: Driver for the Microchip MCP251x SPI CAN controllers")
Signed-off-by: default avatarWeitao Hou <houweitaoo@gmail.com>
Acked-by: default avatarWillem de Bruijn <willemb@google.com>
Tested-by: default avatarSean Nyekjaer <sean@geanix.com>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent dbf790dc
...@@ -678,17 +678,6 @@ static int mcp251x_power_enable(struct regulator *reg, int enable) ...@@ -678,17 +678,6 @@ static int mcp251x_power_enable(struct regulator *reg, int enable)
return regulator_disable(reg); 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) static int mcp251x_stop(struct net_device *net)
{ {
struct mcp251x_priv *priv = netdev_priv(net); struct mcp251x_priv *priv = netdev_priv(net);
...@@ -954,37 +943,43 @@ static int mcp251x_open(struct net_device *net) ...@@ -954,37 +943,43 @@ static int mcp251x_open(struct net_device *net)
flags | IRQF_ONESHOT, DEVICE_NAME, priv); flags | IRQF_ONESHOT, DEVICE_NAME, priv);
if (ret) { if (ret) {
dev_err(&spi->dev, "failed to acquire irq %d\n", spi->irq); dev_err(&spi->dev, "failed to acquire irq %d\n", spi->irq);
mcp251x_power_enable(priv->transceiver, 0); goto out_close;
close_candev(net);
goto open_unlock;
} }
priv->wq = alloc_workqueue("mcp251x_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM, priv->wq = alloc_workqueue("mcp251x_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
0); 0);
if (!priv->wq) {
ret = -ENOMEM;
goto out_clean;
}
INIT_WORK(&priv->tx_work, mcp251x_tx_work_handler); INIT_WORK(&priv->tx_work, mcp251x_tx_work_handler);
INIT_WORK(&priv->restart_work, mcp251x_restart_work_handler); INIT_WORK(&priv->restart_work, mcp251x_restart_work_handler);
ret = mcp251x_hw_reset(spi); ret = mcp251x_hw_reset(spi);
if (ret) { if (ret)
mcp251x_open_clean(net); goto out_free_wq;
goto open_unlock;
}
ret = mcp251x_setup(net, spi); ret = mcp251x_setup(net, spi);
if (ret) { if (ret)
mcp251x_open_clean(net); goto out_free_wq;
goto open_unlock;
}
ret = mcp251x_set_normal_mode(spi); ret = mcp251x_set_normal_mode(spi);
if (ret) { if (ret)
mcp251x_open_clean(net); goto out_free_wq;
goto open_unlock;
}
can_led_event(net, CAN_LED_EVENT_OPEN); can_led_event(net, CAN_LED_EVENT_OPEN);
netif_wake_queue(net); 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); mutex_unlock(&priv->mcp_lock);
return ret; return ret;
} }
......
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