Skip to contentSkip to conversation

staging: comedi: sanity check num_subdevices parameter in comedi_alloc_subdevices

PATCH In review H Hartley Sweeten 1 participant 1 message Jun 12, 2012 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 3/8 staging: comedi: sanity check num_subdevices parameter in comedi_alloc_subdevices

Quoted 1 line

From 952298d9ff21bc8fba3ece36a634a7abad89d912 Mon Sep 17 00:00:00 2001

From: H Hartley Sweeten <[email protected]>
Date: Tue, 12 Jun 2012 09:53:02 -0700
Subject: [PATCH 3/8] staging: comedi: sanity check num_subdevices parameter
in comedi_alloc_subdevices

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.

Cc Ian Abbott <[email protected]>
Cc Frank Mori Hess <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/staging/comedi/drivers.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/staging/comedi/drivers.c +2 -0
index 87a87dd..4d5da37 100644
@@ -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),
Signature · 1 line
1.7.7