[PATCH 3/5] staging: comedi: comedi_fops: remove BUG_ON() in comedi_free_subdevice_minor()

H Hartley Sweeten hsweeten at visionengravers.com
Mon Aug 10 20:14:01 UTC 2015


Drivers should not crash the kernel.

This function is only called by comedi_device_detach_cleanup() and the
s->minor will always be valid or the device wouldn't have attached in
the first place.

Leave the checks for safety in accessing the comedi_subdevice_minor_table
array but remove the BUG_ON() calls.

Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
Cc: Ian Abbott <abbotti at mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
---
 drivers/staging/comedi/comedi_fops.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index a49b385..dbca28f 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -2831,12 +2831,10 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s)
 
 	if (!s)
 		return;
-	if (s->minor < 0)
+	if (s->minor < COMEDI_NUM_BOARD_MINORS ||
+	    s->minor >= COMEDI_NUM_MINORS)
 		return;
 
-	BUG_ON(s->minor >= COMEDI_NUM_MINORS);
-	BUG_ON(s->minor < COMEDI_NUM_BOARD_MINORS);
-
 	i = s->minor - COMEDI_NUM_BOARD_MINORS;
 	mutex_lock(&comedi_subdevice_minor_table_lock);
 	if (s == comedi_subdevice_minor_table[i])
-- 
2.4.3



More information about the devel mailing list