s5j/adc: check the number of configured channels
authorHeesub Shin <heesub.shin@samsung.com>
Fri, 7 Apr 2017 05:44:54 +0000 (14:44 +0900)
committerHeesub Shin <heesub.shin@samsung.com>
Tue, 18 Apr 2017 03:02:12 +0000 (12:02 +0900)
S5J has 4 ADC channels maximum. If it is requested to be configured
greater than that, s5j_adc_initialize() should return an error.

Change-Id: I4dd071c288b530b90c86b55dca78a12b9cc1bde6
Signed-off-by: Heesub Shin <heesub.shin@samsung.com>
os/arch/arm/src/s5j/s5j_adc.c
os/arch/arm/src/s5j/s5j_adc.h

index e63b7ac..24941d4 100644 (file)
@@ -84,7 +84,7 @@ struct s5j_dev_s
        uint8_t current;        /* Current ADC channel being converted */
 
        struct work_s work;     /* Supports the IRQ handling */
-       uint8_t chanlist[4];
+       uint8_t chanlist[S5J_ADC_MAX_CHANNELS];
 };
 
 /****************************************************************************
@@ -470,6 +470,12 @@ struct adc_dev_s *s5j_adc_initialize(FAR const uint8_t *chanlist,
        priv->dev        = &g_adcdev;
        priv->cchannels  = cchannels;
 
+       if (cchannels > S5J_ADC_MAX_CHANNELS) {
+               lldbg("S5J has maximum %d ADC channels.\n",
+                                               S5J_ADC_MAX_CHANNELS);
+               return NULL;
+       }
+
        memcpy(priv->chanlist, chanlist, cchannels);
 
        return &g_adcdev;
index d0c58b2..8ad80a5 100644 (file)
@@ -65,6 +65,7 @@
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
+#define S5J_ADC_MAX_CHANNELS   4
 
 #ifndef __ASSEMBLY__