linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][bluetooth-next][V2] ieee802154: ca8210: Add checks for kmalloc allocation failures
@ 2017-03-29 17:05 Colin King
  2017-03-29 17:17 ` David Miller
  2017-03-29 18:54 ` Marcel Holtmann
  0 siblings, 2 replies; 4+ messages in thread
From: Colin King @ 2017-03-29 17:05 UTC (permalink / raw)
  To: Harry Morris, linuxdev, Alexander Aring, Stefan Schmidt,
	linux-wpan, netdev
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

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: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/ieee802154/ca8210.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
index 53fa87bfede0..25fd3b04b3c0 100644
--- a/drivers/net/ieee802154/ca8210.c
+++ b/drivers/net/ieee802154/ca8210.c
@@ -634,6 +634,8 @@ static int ca8210_test_int_driver_write(
 		dev_dbg(&priv->spi->dev, "%#03x\n", buf[i]);
 
 	fifo_buffer = kmalloc(len, GFP_KERNEL);
+	if (!fifo_buffer)
+		return -ENOMEM;
 	memcpy(fifo_buffer, buf, len);
 	kfifo_in(&test->up_fifo, &fifo_buffer, 4);
 	wake_up_interruptible(&priv->test.readq);
@@ -759,10 +761,10 @@ static void ca8210_rx_done(struct cas_control *cas_ctl)
 				&priv->spi->dev,
 				"Resetting MAC...\n");
 
-			mlme_reset_wpc = kmalloc(
-				sizeof(struct work_priv_container),
-				GFP_KERNEL
-			);
+			mlme_reset_wpc = kmalloc(sizeof(*mlme_reset_wpc),
+						 GFP_KERNEL);
+			if (!mlme_reset_wpc)
+				goto finish;
 			INIT_WORK(
 				&mlme_reset_wpc->work,
 				ca8210_mlme_reset_worker
@@ -925,10 +927,10 @@ static int ca8210_spi_transfer(
 
 	dev_dbg(&spi->dev, "ca8210_spi_transfer called\n");
 
-	cas_ctl = kmalloc(
-		sizeof(struct cas_control),
-		GFP_ATOMIC
-	);
+	cas_ctl = kmalloc(sizeof(*cas_ctl), GFP_ATOMIC);
+	if (!cas_ctl)
+		return -ENOMEM;
+
 	cas_ctl->priv = priv;
 	memset(cas_ctl->tx_buf, SPI_IDLE, CA8210_SPI_BUF_SIZE);
 	memset(cas_ctl->tx_in_buf, SPI_IDLE, CA8210_SPI_BUF_SIZE);
-- 
2.11.0

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

* Re: [PATCH][bluetooth-next][V2] ieee802154: ca8210: Add checks for kmalloc allocation failures
  2017-03-29 17:05 [PATCH][bluetooth-next][V2] ieee802154: ca8210: Add checks for kmalloc allocation failures Colin King
@ 2017-03-29 17:17 ` David Miller
  2017-03-29 18:51   ` Marcel Holtmann
  2017-03-29 18:54 ` Marcel Holtmann
  1 sibling, 1 reply; 4+ messages in thread
From: David Miller @ 2017-03-29 17:17 UTC (permalink / raw)
  To: colin.king
  Cc: h.morris, linuxdev, aar, stefan, linux-wpan, netdev,
	kernel-janitors, linux-kernel

From: Colin King <colin.king@canonical.com>
Date: Wed, 29 Mar 2017 18:05:40 +0100

>  drivers/net/ieee802154/ca8210.c | 18 ++++++++++--------

This file doesn't exist in any of my trees.

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

* Re: [PATCH][bluetooth-next][V2] ieee802154: ca8210: Add checks for kmalloc allocation failures
  2017-03-29 17:17 ` David Miller
@ 2017-03-29 18:51   ` Marcel Holtmann
  0 siblings, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2017-03-29 18:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: Colin King, Harry Morris, linuxdev, Alexander Aring,
	Stefan Schmidt, linux-wpan, Network Development, kernel-janitors,
	linux-kernel

Hi Dave,

>> drivers/net/ieee802154/ca8210.c | 18 ++++++++++--------
> 
> This file doesn't exist in any of my trees.
> 

because we have not send you a bluetooth-next pull request yet. I review it and take it through my tree first.

Regards

Marcel

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

* Re: [PATCH][bluetooth-next][V2] ieee802154: ca8210: Add checks for kmalloc allocation failures
  2017-03-29 17:05 [PATCH][bluetooth-next][V2] ieee802154: ca8210: Add checks for kmalloc allocation failures Colin King
  2017-03-29 17:17 ` David Miller
@ 2017-03-29 18:54 ` Marcel Holtmann
  1 sibling, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2017-03-29 18:54 UTC (permalink / raw)
  To: Colin King
  Cc: Harry Morris, linuxdev, Alexander Aring, Stefan Schmidt,
	linux-wpan, netdev, kernel-janitors, linux-kernel

Hi Colin,

> 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: Colin Ian King <colin.king@canonical.com>
> ---
> drivers/net/ieee802154/ca8210.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

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

end of thread, other threads:[~2017-03-29 18:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-29 17:05 [PATCH][bluetooth-next][V2] ieee802154: ca8210: Add checks for kmalloc allocation failures Colin King
2017-03-29 17:17 ` David Miller
2017-03-29 18:51   ` Marcel Holtmann
2017-03-29 18:54 ` Marcel Holtmann

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).