[PATCH 3/8] staging: comedi: sanity check num_subdevices parameterin comedi_alloc_subdevices

From: H Hartley Sweeten
Date: Tue Jun 12 2012 - 12:53:02 EST


It's possible for a couple of the comedi drivers to incorrectly call
comedi_alloc_subdevices with num_subdevices = 0. Add a sanity check
before doing the kcalloc.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbot@xxxxxxxxx>
Cc: Frank Mori Hess <kmhess@xxxxxxxxxxxxxxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
drivers/staging/comedi/drivers.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 87a87dd..4d5da37 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -60,6 +60,8 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices)
{
int i;

+ if (num_subdevices < 1)
+ return -EINVAL;
dev->n_subdevices = num_subdevices;
dev->subdevices =
kcalloc(num_subdevices, sizeof(struct comedi_subdevice),
--
1.7.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/