From: Ian Abbott Date: Fri, 30 Jan 2026 16:47:27 +0000 (+0000) Subject: comedi: 8255: Add some I/O base address sanity checks X-Git-Tag: v7.1-rc1~17^2~106 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb51837eeeddac2da41f4c202597c534bb9d8dc9;p=thirdparty%2Fkernel%2Flinux.git comedi: 8255: Add some I/O base address sanity checks The "8255" driver allows a COMEDI device to be constructed from one or more 8255 chips, each at an I/O port base address specified by the admin-supplied configuration options (`it->options[]`). Currently, the driver allows any I/O base addresses to be specified as long as the I/O regions can be reserved, and it converts the specified `int` option values holding the base address to `unsigned long`. It doesn't make sense to allow base addresses that are not aligned to 4-byte boundaries because the hardware register addresses would not be decoded properly, so add a check for valid alignment. Convert the option values that specify the base addresses from `int` to `unsigned int` instead of `unsigned long` so they end up the same on 32-bit and 64-bit systems. Signed-off-by: Ian Abbott Link: https://patch.msgid.link/20260130170416.49994-3-abbotti@mev.co.uk Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/comedi/drivers/8255.c b/drivers/comedi/drivers/8255.c index 5f70938b44773..ff45248ebb297 100644 --- a/drivers/comedi/drivers/8255.c +++ b/drivers/comedi/drivers/8255.c @@ -47,7 +47,7 @@ static int dev_8255_attach(struct comedi_device *dev, struct comedi_devconfig *it) { struct comedi_subdevice *s; - unsigned long iobase; + unsigned int iobase; int ret; int i; @@ -70,13 +70,15 @@ static int dev_8255_attach(struct comedi_device *dev, iobase = it->options[i]; /* - * __comedi_request_region() does not set dev->iobase. + * __comedi_check_request_region() does not set dev->iobase. * * For 8255 devices that are manually attached using * comedi_config, the 'iobase' is the actual I/O port - * base address of the chip. + * base address of the chip. It should be aligned on + * a 4-byte boundary. */ - ret = __comedi_request_region(dev, iobase, I8255_SIZE); + ret = __comedi_check_request_region(dev, iobase, I8255_SIZE, + 0, UINT_MAX, 4); if (ret) return ret; ret = subdev_8255_io_init(dev, s, iobase);