mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yang Zi <2959243019@qq.com>
To: abbotti@mev.co.uk, hsweeten@visionengravers.com
Cc: gregkh@linuxfoundation.org, u.kleine-koenig@baylibre.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH] comedi: addi_apci_3xxx: fix subdevice count underallocation
Date: Tue, 25 Aug 2026 17:07:54 +0800	[thread overview]
Message-ID: <tencent_BC89ED84AE795F9D75CCF0A65E679B78490A@qq.com> (raw)

In apci3xxx_auto_attach(), the number of subdevices is computed with

    n_subdevices = (board->ai_n_chan ? 0 : 1) + board->has_ao + ...

The ternary is inverted: when the board has analog input channels
(ai_n_chan != 0), it counts 0 instead of 1, so the AI subdevice that is
actually created is not accounted for. As a result
comedi_alloc_subdevices() allocates one entry too few, and the later
subdevice initialization (notably the TTL Digital I/O subdevice, which
is populated last) writes past the end of the allocated array, causing a
slab out-of-bounds write.

Flip the ternary to count 1 when ai_n_chan is non-zero and 0 otherwise,
matching the subdevice creation order in the function.

Signed-off-by: Yang Zi <2959243019@qq.com>
---
diff --git a/drivers/comedi/drivers/addi_apci_3xxx.c b/drivers/comedi/drivers/addi_apci_3xxx.c
index 695cce103177..1dcda82d9503 100644
--- a/drivers/comedi/drivers/addi_apci_3xxx.c
+++ b/drivers/comedi/drivers/addi_apci_3xxx.c
@@ -787,7 +787,7 @@ static int apci3xxx_auto_attach(struct comedi_device *dev,
             dev->irq = pcidev->irq;
     }
 
-    n_subdevices = (board->ai_n_chan ? 0 : 1) + board->has_ao +
+    n_subdevices = (board->ai_n_chan ? 1 : 0) + board->has_ao +
                board->has_dig_in + board->has_dig_out +
                board->has_ttl_io;
     ret = comedi_alloc_subdevices(dev, n_subdevices);



             reply	other threads:[~2026-08-25  9:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  9:07 Yang Zi [this message]
2026-08-25  9:16 ` Ian Abbott

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_BC89ED84AE795F9D75CCF0A65E679B78490A@qq.com \
    --to=2959243019@qq.com \
    --cc=abbotti@mev.co.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=hsweeten@visionengravers.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=u.kleine-koenig@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®