[PATCH 2/5] comedi: addi_apci_1500: fix clearing of the gate enable

From: Greg Kroah-Hartman

Date: Tue Oct 27 2026 - 12:48:54 EST


From: Josef Bacik <josef@xxxxxxxxxxxxxx>

INSN_CONFIG_SET_GATE_SRC reads the mode register of the counter/timer,
is meant to clear the External Gate Enable bit, sets it again if the
external gate was asked for, and writes the register back. The mask lacks
its '~': all the bits but EGE are cleared instead. So

- the external gate can be enabled but never be disabled again, and
- the instruction wipes the mode (continuous or single cycle, external
output, count and trigger enables, retrigger, duty cycle) which
INSN_CONFIG_SET_COUNTER_MODE has programmed: the timer silently falls
back to a single cycle pulse.

With the right mask, the instruction only changes the gate bit. An
application which sets the gate source after the counter mode now keeps
the mode it has asked for.

Fixes: a8c66b684efa ("staging: comedi: addi_apci_1500: rewrite the subdevice support functions")
Cc: stable <stable@xxxxxxxxxx>
Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
drivers/comedi/drivers/addi_apci_1500.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/comedi/drivers/addi_apci_1500.c b/drivers/comedi/drivers/addi_apci_1500.c
index a203e27888e2..3d65aef565b3 100644
--- a/drivers/comedi/drivers/addi_apci_1500.c
+++ b/drivers/comedi/drivers/addi_apci_1500.c
@@ -696,7 +696,7 @@ static int apci1500_timer_insn_config(struct comedi_device *dev,
return -EINVAL;

val = z8536_read(dev, Z8536_CT_MODE_REG(chan));
- val &= Z8536_CT_MODE_EGE;
+ val &= ~Z8536_CT_MODE_EGE;
if (data[1] == 1)
val |= Z8536_CT_MODE_EGE;
else if (data[1] > 1)

--
2.56.0