diff mbox series

net: spi: fix a potential NULL pointer dereference

Message ID 20190310075735.3392-1-kjlu@umn.edu
State Awaiting Upstream
Delegated to: David Miller
Headers show
Series net: spi: fix a potential NULL pointer dereference | expand

Commit Message

Kangjie Lu March 10, 2019, 7:57 a.m. UTC
In case alloc_workqueue fails to allocate the work queue and
returns NULL, the fix releases the resources and returns
-ENOMEM.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/net/can/spi/mcp251x.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Kangjie Lu March 23, 2019, 3:10 a.m. UTC | #1
> On Mar 10, 2019, at 1:57 AM, Kangjie Lu <kjlu@umn.edu> wrote:
> 
> In case alloc_workqueue fails to allocate the work queue and
> returns NULL, the fix releases the resources and returns
> -ENOMEM.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
> drivers/net/can/spi/mcp251x.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
> index e90817608645..2737b9a20dfe 100644
> --- a/drivers/net/can/spi/mcp251x.c
> +++ b/drivers/net/can/spi/mcp251x.c
> @@ -962,6 +962,14 @@ static int mcp251x_open(struct net_device *net)
> 
> 	priv->wq = alloc_workqueue("mcp251x_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
> 				   0);
> +	if (unlikely(!priv->wq)) {
> +		dev_err(&spi->dev, "failed to allocate work queue\n");
> +		mcp251x_power_enable(priv->transceiver, 0);
> +		close_candev(net);
> +		ret = -ENOMEM;
> +		goto open_unlock;
> +	}
> +

Can someone review this patch?


> 	INIT_WORK(&priv->tx_work, mcp251x_tx_work_handler);
> 	INIT_WORK(&priv->restart_work, mcp251x_restart_work_handler);
> 
> -- 
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
index e90817608645..2737b9a20dfe 100644
--- a/drivers/net/can/spi/mcp251x.c
+++ b/drivers/net/can/spi/mcp251x.c
@@ -962,6 +962,14 @@  static int mcp251x_open(struct net_device *net)
 
 	priv->wq = alloc_workqueue("mcp251x_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
 				   0);
+	if (unlikely(!priv->wq)) {
+		dev_err(&spi->dev, "failed to allocate work queue\n");
+		mcp251x_power_enable(priv->transceiver, 0);
+		close_candev(net);
+		ret = -ENOMEM;
+		goto open_unlock;
+	}
+
 	INIT_WORK(&priv->tx_work, mcp251x_tx_work_handler);
 	INIT_WORK(&priv->restart_work, mcp251x_restart_work_handler);