[PATCH] comedi: Possible NULL dereference of user_ai_range_table in das16_attach()

Roel Kluin roel.kluin at gmail.com
Mon Aug 31 09:29:09 UTC 2009


user_ai_range_table allocation may fail, prevent a dereference of NULL.

Signed-off-by: Roel Kluin <roel.kluin at gmail.com>
---
It also appears that there is no cleanup upon errors, should it be
added?

diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c
index 59af86a..58f5b20 100644
--- a/drivers/staging/comedi/drivers/das16.c
+++ b/drivers/staging/comedi/drivers/das16.c
@@ -1499,6 +1499,8 @@ static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 		devpriv->user_ai_range_table =
 			kmalloc(sizeof(struct comedi_lrange) + sizeof(struct comedi_krange),
 			GFP_KERNEL);
+		if (devpriv->user_ai_range_table == NULL)
+			return -ENOMEM;
 		/*  initialize ai range */
 		devpriv->user_ai_range_table->length = 1;
 		user_ai_range = devpriv->user_ai_range_table->range;
@@ -1512,6 +1514,8 @@ static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 		devpriv->user_ao_range_table =
 			kmalloc(sizeof(struct comedi_lrange) + sizeof(struct comedi_krange),
 			GFP_KERNEL);
+		if (devpriv->user_ao_range_table == NULL)
+			return -ENOMEM;
 		/*  initialize ao range */
 		devpriv->user_ao_range_table->length = 1;
 		user_ao_range = devpriv->user_ao_range_table->range;



More information about the devel mailing list