[PATCH 41/46] comedi: pcmda12: Add sanity checks for I/O base address

Ian Abbott posted 46 patches 1 week, 3 days ago
[PATCH 41/46] comedi: pcmda12: Add sanity checks for I/O base address
Posted by Ian Abbott 1 week, 3 days ago
The "pcmda12" driver uses an admin-supplied configuration option
(`it->options[0]`) to configure the I/O port base address of a
PCM-D/A-12 or PCM-A/D-16 board.  It currently allows any base address to
be configured.  I cannot find a full manual, but the short datasheet
says it uses 15 consecutive I/O addresses on "any even sixteen port
boundary", so assume it supports base addresses (configured by on-board
jumpers) in the range 0 to 0x3E0 on 32-byte boundaries.

Add a sanity check to ensure the device is not configured at an
unsupported base address.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/comedi/drivers/pcmda12.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/comedi/drivers/pcmda12.c b/drivers/comedi/drivers/pcmda12.c
index 611f13bedca0..6efd1ae6271a 100644
--- a/drivers/comedi/drivers/pcmda12.c
+++ b/drivers/comedi/drivers/pcmda12.c
@@ -120,7 +120,14 @@ static int pcmda12_attach(struct comedi_device *dev,
 	struct comedi_subdevice *s;
 	int ret;
 
-	ret = comedi_request_region(dev, it->options[0], 0x10);
+	/*
+	 * The datasheet says it requires 16 contiguous addresses and is
+	 * "configurable on any even sixteen port boundary".  So require
+	 * a 32-byte boundary and assume it uses 10-bit addresses like
+	 * similar boards.
+	 */
+	ret = comedi_check_request_region(dev, it->options[0], 0x10,
+					  0, 0x3ff, 32);
 	if (ret)
 		return ret;
 
-- 
2.51.0