This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new af9e3a3231b analog: Fix open reference counting.
af9e3a3231b is described below
commit af9e3a3231b0308b1793c343dd730297639cae34
Author: Megha Rajput <[email protected]>
AuthorDate: Sat Oct 24 16:03:18 2026 +0000
analog: Fix open reference counting.
Increment the open reference count on every successful open in the DAC,
comparator, and opamp drivers while keeping hardware setup limited to the
first open.
Update the count only after setup succeeds, so failed initialization does
not leave a stale reference. This prevents closing one file descriptor
from shutting down hardware while other descriptors remain open.
Tested:
- QEMU rv-virt KSMP64 build with COMP, DAC, and OPAMP enabled.
- Host regression tests covering both close orders and setup-failure
retries.
- checkpatch and git diff --check.
Assisted-by: ChatGPT:GPT-6
Signed-off-by: Megha Rajput <[email protected]>
---
drivers/analog/comp.c | 12 ++++++------
drivers/analog/dac.c | 14 +++++++++-----
drivers/analog/opamp.c | 13 +++++++------
3 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/drivers/analog/comp.c b/drivers/analog/comp.c
index 523d1f2e77a..dc5732cdd71 100644
--- a/drivers/analog/comp.c
+++ b/drivers/analog/comp.c
@@ -223,14 +223,14 @@ static int comp_open(FAR struct file *filep)
irqstate_t flags = enter_critical_section();
ret = dev->ad_ops->ao_setup(dev);
- if (ret == OK)
- {
- /* Save the new open count on success */
+ leave_critical_section(flags);
+ }
- dev->ad_ocount = tmp;
- }
+ /* Save the new open count on success */
- leave_critical_section(flags);
+ if (ret == OK)
+ {
+ dev->ad_ocount = tmp;
}
}
diff --git a/drivers/analog/dac.c b/drivers/analog/dac.c
index f22ccb7a4ca..edd9a3b0229 100644
--- a/drivers/analog/dac.c
+++ b/drivers/analog/dac.c
@@ -122,6 +122,7 @@ static int dac_open(FAR struct file *filep)
/* Yes.. perform one time hardware initialization. */
irqstate_t flags = enter_critical_section();
+
ret = dev->ad_ops->ao_setup(dev);
if (ret == OK)
{
@@ -129,14 +130,17 @@ static int dac_open(FAR struct file *filep)
dev->ad_xmit.af_head = 0;
dev->ad_xmit.af_tail = 0;
-
- /* Save the new open count on success */
-
- dev->ad_ocount = tmp;
}
leave_critical_section(flags);
}
+
+ /* Save the new open count on success */
+
+ if (ret == OK)
+ {
+ dev->ad_ocount = tmp;
+ }
}
nxmutex_unlock(&dev->ad_closelock);
@@ -183,7 +187,7 @@ static int dac_close(FAR struct file *filep)
while (dev->ad_xmit.af_head != dev->ad_xmit.af_tail)
{
- nxsched_usleep(HALF_SECOND_USEC);
+ nxsched_usleep(HALF_SECOND_USEC);
}
/* Free the IRQ and disable the DAC device */
diff --git a/drivers/analog/opamp.c b/drivers/analog/opamp.c
index a7cfc9a9917..b826e47983b 100644
--- a/drivers/analog/opamp.c
+++ b/drivers/analog/opamp.c
@@ -110,15 +110,16 @@ static int opamp_open(FAR struct file *filep)
/* Yes.. perform one time hardware initialization. */
irqstate_t flags = enter_critical_section();
+
ret = dev->ad_ops->ao_setup(dev);
- if (ret == OK)
- {
- /* Save the new open count on success */
+ leave_critical_section(flags);
+ }
- dev->ad_ocount = tmp;
- }
+ /* Save the new open count on success */
- leave_critical_section(flags);
+ if (ret == OK)
+ {
+ dev->ad_ocount = tmp;
}
}