From nobody Mon Feb 9 19:04:59 2026 Received: from smtp82.ord1d.emailsrvr.com (smtp82.ord1d.emailsrvr.com [184.106.54.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CE0E357715 for ; Fri, 30 Jan 2026 17:04:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=184.106.54.82 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769792689; cv=none; b=X3b4pufQwW7MJ4f898IH56aiSf/sxz+Ev3cCoM8jOIE46oajvsJiAUsQOXF9LDXe/fybuwiZ2E3nfnMmP8F2ISZGDGFI1HyYuG42w/nQ1mzxcDaQqH1QKk8ZASuqkzP2Zku3cBpI+5oqrM7XyJI1I0Wug/qyZI57I0fsYHFKdXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769792689; c=relaxed/simple; bh=K0k6H4oFK+wtakFAw6qBGCSbxhvsHg4MJSUk7IwqkKg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kkAs1DXDhziCIgAbT3HVFyf1nxcpR4hE8JRHvrWHEo3USnn+7HqII+QFs0r29FsFB6CN34vHZ5iWqORU1+JD9xi7YcWsEAib7rNDp5idke2P5gjWMAjom3AHKJmyUSSXaD2DFmeOxQwG19Xz2CM12tYt785qPYZq4z3zDQ5FMzY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mev.co.uk; spf=pass smtp.mailfrom=mev.co.uk; dkim=pass (1024-bit key) header.d=mev.co.uk header.i=@mev.co.uk header.b=FWHzjNo3; arc=none smtp.client-ip=184.106.54.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mev.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mev.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mev.co.uk header.i=@mev.co.uk header.b="FWHzjNo3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20221208-6x11dpa4; t=1769792684; bh=K0k6H4oFK+wtakFAw6qBGCSbxhvsHg4MJSUk7IwqkKg=; h=From:To:Subject:Date:From; b=FWHzjNo3BWUAN/ZIJ2lD60KGfFN5WOVcO5Pa/aQkQr+w1gz2HlxqpiRAWf//WSUp9 YVVn3dYqQo0qUT0ZRPBMq2/s5VCK5d6GbREIsR/Qi4bCL+7M3k71TQW+gM5/1TylEg JBDqk4p/q5lZwsm++gJt4HjlbYZrSAAX8MIft3Cs= X-Auth-ID: abbotti@mev.co.uk Received: by smtp19.relay.ord1d.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id 99EEB602FA; Fri, 30 Jan 2026 12:04:43 -0500 (EST) From: Ian Abbott To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Ian Abbott , H Hartley Sweeten Subject: [PATCH 13/46] comedi: das16: Add sanity checks for I/O base address Date: Fri, 30 Jan 2026 16:47:38 +0000 Message-ID: <20260130170416.49994-14-abbotti@mev.co.uk> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260130170416.49994-1-abbotti@mev.co.uk> References: <20260130170416.49994-1-abbotti@mev.co.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Classification-ID: 429d5722-7f90-4557-8586-08913fa85e9e-14-1 Content-Type: text/plain; charset="utf-8" The "das16" driver uses an admin-supplied configuration option (`it->options[0]`) to configure the I/O port base address of a various DAS16 compatible boards. It currently allows any base address to be configured but the hardware only supports base addresses (configured by an on-board DIP switch) in the range 0 to 0x3f0 on 16- or 32-byte boundaries. Some of the boards have an 8255 chip at offset 0x10 and require the board to be configured on a 32-byte boundary unless some on-board jumpers are set to limit the board to decoding only the first 0x10 registers, disabling access to the 8255. Some other boards place the 8255 chip (and some other registers) at offset 0x400 from the base address, decoding 0x10 registers at the base address and 0x8 registers at the base address plus 0x400. Add a sanity check to ensure the device is not configured at an unsupported base address. If the device has the 8255 chip at offset 0x10, and is being configured with the base address at an odd 16-byte boundary, limit the size of the region to 0x10 and disable the 8255 subdevice. Signed-off-by: Ian Abbott --- drivers/comedi/drivers/das16.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/comedi/drivers/das16.c b/drivers/comedi/drivers/das16.c index 1f85572c21b4..6eebfda2cb53 100644 --- a/drivers/comedi/drivers/das16.c +++ b/drivers/comedi/drivers/das16.c @@ -1018,6 +1018,7 @@ static int das16_attach(struct comedi_device *dev, st= ruct comedi_devconfig *it) const struct das16_board *board =3D dev->board_ptr; struct das16_private_struct *devpriv; struct comedi_subdevice *s; + unsigned int iobase =3D it->options[0]; unsigned int osc_base; unsigned int status; int ret; @@ -1037,11 +1038,25 @@ static int das16_attach(struct comedi_device *dev, = struct comedi_devconfig *it) devpriv->dev =3D dev; =20 if (board->size < 0x400) { - ret =3D comedi_request_region(dev, it->options[0], board->size); + unsigned int size =3D board->size; + + if (size > 0x10 && (iobase & 0x10) !=3D 0) { + /* + * The board has more than 0x10 registers and is + * being placed on an odd 16-byte boundary. The + * board has some jumpers to configure this mode, + * disabling the 8255 at offset 0x10, so only 0x10 + * registers will need to be mapped in this mode. + */ + size =3D 0x10; + } + ret =3D comedi_check_request_region(dev, iobase, size, + 0, 0x3ff, 16); if (ret) return ret; } else { - ret =3D comedi_request_region(dev, it->options[0], 0x10); + ret =3D comedi_check_request_region(dev, iobase, 0x10, + 0, 0x3ff, 16); if (ret) return ret; /* Request an additional region for the 8255 */ @@ -1146,9 +1161,15 @@ static int das16_attach(struct comedi_device *dev, s= truct comedi_devconfig *it) /* 8255 Digital I/O subdevice */ if (board->has_8255) { s =3D &dev->subdevices[4]; - ret =3D subdev_8255_io_init(dev, s, board->i8255_offset); - if (ret) - return ret; + if (board->i8255_offset =3D=3D 0x10 && (dev->iobase & 0x10) !=3D 0) { + dev_info(dev->class_dev, + "Disabling 8255 subdevice on unsupported base address\n"); + s->type =3D COMEDI_SUBD_UNUSED; + } else { + ret =3D subdev_8255_io_init(dev, s, board->i8255_offset); + if (ret) + return ret; + } } =20 das16_reset(dev); --=20 2.51.0