Commit 941825e1 authored by Colin Ian King's avatar Colin Ian King Committed by Marcel Holtmann

ieee802154: ca8210: Add checks for kmalloc allocation failures

Ensure we don't end up with a null pointer dereferences by checking
for for allocation failures.  Allocate by sizeof(*ptr) rather than
the type to fix checkpack warnings.  Also merge multiple lines into
one line for the kmalloc call.

Detected by CoverityScan, CID#1422435 ("Dereference null return value")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent f1554b7b
...@@ -634,6 +634,8 @@ static int ca8210_test_int_driver_write( ...@@ -634,6 +634,8 @@ static int ca8210_test_int_driver_write(
dev_dbg(&priv->spi->dev, "%#03x\n", buf[i]); dev_dbg(&priv->spi->dev, "%#03x\n", buf[i]);
fifo_buffer = kmalloc(len, GFP_KERNEL); fifo_buffer = kmalloc(len, GFP_KERNEL);
if (!fifo_buffer)
return -ENOMEM;
memcpy(fifo_buffer, buf, len); memcpy(fifo_buffer, buf, len);
kfifo_in(&test->up_fifo, &fifo_buffer, 4); kfifo_in(&test->up_fifo, &fifo_buffer, 4);
wake_up_interruptible(&priv->test.readq); wake_up_interruptible(&priv->test.readq);
...@@ -759,10 +761,10 @@ static void ca8210_rx_done(struct cas_control *cas_ctl) ...@@ -759,10 +761,10 @@ static void ca8210_rx_done(struct cas_control *cas_ctl)
&priv->spi->dev, &priv->spi->dev,
"Resetting MAC...\n"); "Resetting MAC...\n");
mlme_reset_wpc = kmalloc( mlme_reset_wpc = kmalloc(sizeof(*mlme_reset_wpc),
sizeof(struct work_priv_container), GFP_KERNEL);
GFP_KERNEL if (!mlme_reset_wpc)
); goto finish;
INIT_WORK( INIT_WORK(
&mlme_reset_wpc->work, &mlme_reset_wpc->work,
ca8210_mlme_reset_worker ca8210_mlme_reset_worker
...@@ -925,10 +927,10 @@ static int ca8210_spi_transfer( ...@@ -925,10 +927,10 @@ static int ca8210_spi_transfer(
dev_dbg(&spi->dev, "ca8210_spi_transfer called\n"); dev_dbg(&spi->dev, "ca8210_spi_transfer called\n");
cas_ctl = kmalloc( cas_ctl = kmalloc(sizeof(*cas_ctl), GFP_ATOMIC);
sizeof(struct cas_control), if (!cas_ctl)
GFP_ATOMIC return -ENOMEM;
);
cas_ctl->priv = priv; cas_ctl->priv = priv;
memset(cas_ctl->tx_buf, SPI_IDLE, CA8210_SPI_BUF_SIZE); memset(cas_ctl->tx_buf, SPI_IDLE, CA8210_SPI_BUF_SIZE);
memset(cas_ctl->tx_in_buf, SPI_IDLE, CA8210_SPI_BUF_SIZE); memset(cas_ctl->tx_in_buf, SPI_IDLE, CA8210_SPI_BUF_SIZE);
......
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