linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can: mcp251x: add error check when wq alloc failed
@ 2019-06-25 12:50 Weitao Hou
  2019-06-25 14:03 ` Willem de Bruijn
  0 siblings, 1 reply; 3+ messages in thread
From: Weitao Hou @ 2019-06-25 12:50 UTC (permalink / raw)
  To: wg, mkl, davem, gregkh, allison, houweitaoo, tglx, sean
  Cc: linux-can, netdev, linux-kernel

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

Signed-off-by: Weitao Hou <houweitaoo@gmail.com>
---
 drivers/net/can/spi/mcp251x.c | 49 ++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 27 deletions(-)

diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
index 44e99e3d7134..2aec934fab0c 100644
--- a/drivers/net/can/spi/mcp251x.c
+++ b/drivers/net/can/spi/mcp251x.c
@@ -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);
@@ -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;
 }
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] can: mcp251x: add error check when wq alloc failed
  2019-06-25 12:50 [PATCH] can: mcp251x: add error check when wq alloc failed Weitao Hou
@ 2019-06-25 14:03 ` Willem de Bruijn
  2019-06-26  6:26   ` Sean Nyekjaer
  0 siblings, 1 reply; 3+ messages in thread
From: Willem de Bruijn @ 2019-06-25 14:03 UTC (permalink / raw)
  To: Weitao Hou
  Cc: Wolfgang Grandegger, Marc Kleine-Budde, David Miller,
	Greg Kroah-Hartman, allison, tglx, sean, linux-can,
	Network Development, linux-kernel

On Tue, Jun 25, 2019 at 8:51 AM Weitao Hou <houweitaoo@gmail.com> wrote:
>
> add error check when workqueue alloc failed, and remove
> redundant code to make it clear
>
> Signed-off-by: Weitao Hou <houweitaoo@gmail.com>

Acked-by: Willem de Bruijn <willemb@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] can: mcp251x: add error check when wq alloc failed
  2019-06-25 14:03 ` Willem de Bruijn
@ 2019-06-26  6:26   ` Sean Nyekjaer
  0 siblings, 0 replies; 3+ messages in thread
From: Sean Nyekjaer @ 2019-06-26  6:26 UTC (permalink / raw)
  To: Willem de Bruijn, Weitao Hou
  Cc: Wolfgang Grandegger, Marc Kleine-Budde, David Miller,
	Greg Kroah-Hartman, allison, tglx, linux-can,
	Network Development, linux-kernel



On 25/06/2019 16.03, Willem de Bruijn wrote:
> On Tue, Jun 25, 2019 at 8:51 AM Weitao Hou <houweitaoo@gmail.com> wrote:
>>
>> add error check when workqueue alloc failed, and remove
>> redundant code to make it clear
>>
>> Signed-off-by: Weitao Hou <houweitaoo@gmail.com>
> 
> Acked-by: Willem de Bruijn <willemb@google.com>
> 
Tested-by: Sean Nyekjaer <sean@geanix.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-26  6:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-25 12:50 [PATCH] can: mcp251x: add error check when wq alloc failed Weitao Hou
2019-06-25 14:03 ` Willem de Bruijn
2019-06-26  6:26   ` Sean Nyekjaer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).