You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2020/11/03 19:25:11 UTC

[incubator-nuttx] branch master updated: arch/arm/src/stm32/stm32_adc.c: do not allow negative ref count

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/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 1ce75cc  arch/arm/src/stm32/stm32_adc.c: do not allow negative ref count
1ce75cc is described below

commit 1ce75cc7c6934bba04967cb4504733e614aec224
Author: Juha Niskanen <ju...@haltian.com>
AuthorDate: Tue Nov 3 18:40:31 2020 +0200

    arch/arm/src/stm32/stm32_adc.c: do not allow negative ref count
    
    When HAVE_HSI_CONTROL, adc_reset_hsi_disable() calls adc_reset()
    followed by adc_shutdown() and this combination is called before
    adc_setup() by upper level ADC driver. Without this patch,
    priv->initialized wraps from 0 to 255 in this case.
    
    Signed-off-by: Juha Niskanen <ju...@haltian.com>
---
 arch/arm/src/stm32/stm32_adc.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/arm/src/stm32/stm32_adc.c b/arch/arm/src/stm32/stm32_adc.c
index 5669ccf..8fda778 100644
--- a/arch/arm/src/stm32/stm32_adc.c
+++ b/arch/arm/src/stm32/stm32_adc.c
@@ -2792,7 +2792,7 @@ static void adc_reset(FAR struct adc_dev_s *dev)
 
   if (priv->initialized > 0)
     {
-      return;
+      goto out;
     }
 
 #ifdef HAVE_HSI_CONTROL
@@ -2814,7 +2814,7 @@ static void adc_reset(FAR struct adc_dev_s *dev)
 #ifdef HAVE_ADC_CMN_DATA
   if (adccmn_lock(priv, true) < 0)
     {
-      return;
+      goto out;
     }
 
   if (priv->cmn->initialized == 0)
@@ -2833,6 +2833,7 @@ static void adc_reset(FAR struct adc_dev_s *dev)
   adccmn_lock(priv, false);
 #endif
 
+out:
   leave_critical_section(flags);
 }
 
@@ -2982,9 +2983,14 @@ static void adc_shutdown(FAR struct adc_dev_s *dev)
 {
   FAR struct stm32_dev_s *priv = (FAR struct stm32_dev_s *)dev->ad_priv;
 
-  /* Shutdown the ADC device only when not in use */
+  /* Decrement count only when ADC device is in use */
+
+  if (priv->initialized > 0)
+    {
+      priv->initialized -= 1;
+    }
 
-  priv->initialized -= 1;
+  /* Shutdown the ADC device only when not in use */
 
   if (priv->initialized > 0)
     {