From: H Hartley Sweeten Date: Tue, 12 Jun 2012 18:57:45 +0000 (-0700) Subject: staging: comedi: sanity check num_subdevices parameter in comedi_alloc_subdevices X-Git-Tag: v3.6-rc1~100^2~824 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7f801c41714729f7741a042de839918be2bb56f0;p=platform%2Fupstream%2Fkernel-adaptation-pc.git 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. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Cc: Frank Mori Hess Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 979aa0e..61161ce 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),