@@ -115,7 +115,7 @@ static int adc_open(FAR struct file *filep)
115115 * finished.
116116 */
117117
118- ret = nxmutex_lock (& dev -> ad_closelock );
118+ ret = nxmutex_lock (& dev -> ad_lock );
119119 if (ret >= 0 )
120120 {
121121 /* Increment the count of references to the device. If this is the
@@ -166,7 +166,7 @@ static int adc_open(FAR struct file *filep)
166166 dev -> ad_ocount = tmp ;
167167 }
168168
169- nxmutex_unlock (& dev -> ad_closelock );
169+ nxmutex_unlock (& dev -> ad_lock );
170170 }
171171
172172 return ret ;
@@ -188,7 +188,7 @@ static int adc_close(FAR struct file *filep)
188188 irqstate_t flags ;
189189 int ret ;
190190
191- ret = nxmutex_lock (& dev -> ad_closelock );
191+ ret = nxmutex_lock (& dev -> ad_lock );
192192 if (ret >= 0 )
193193 {
194194 /* Decrement the references to the driver. If the reference count will
@@ -198,7 +198,7 @@ static int adc_close(FAR struct file *filep)
198198 if (dev -> ad_ocount > 1 )
199199 {
200200 dev -> ad_ocount -- ;
201- nxmutex_unlock (& dev -> ad_closelock );
201+ nxmutex_unlock (& dev -> ad_lock );
202202 }
203203 else
204204 {
@@ -212,7 +212,7 @@ static int adc_close(FAR struct file *filep)
212212 dev -> ad_ops -> ao_shutdown (dev ); /* Disable the ADC */
213213 leave_critical_section (flags );
214214
215- nxmutex_unlock (& dev -> ad_closelock );
215+ nxmutex_unlock (& dev -> ad_lock );
216216 }
217217 }
218218
@@ -230,7 +230,6 @@ static ssize_t adc_read(FAR struct file *filep, FAR char *buffer,
230230 FAR struct adc_dev_s * dev = inode -> i_private ;
231231 FAR struct adc_fifo_s * fifo = & dev -> ad_recv ;
232232 size_t nread ;
233- irqstate_t flags ;
234233 int ret = 0 ;
235234 int msglen ;
236235
@@ -273,7 +272,13 @@ static ssize_t adc_read(FAR struct file *filep, FAR char *buffer,
273272 {
274273 /* Interrupts must be disabled while accessing the fifo FIFO */
275274
276- flags = enter_critical_section ();
275+ ret = nxmutex_lock (& dev -> ad_lock );
276+
277+ if (ret < 0 )
278+ {
279+ return ret ;
280+ }
281+
277282 while (fifo -> af_head == fifo -> af_tail )
278283 {
279284 /* Check if there was an overrun, if set we need to return EIO */
@@ -412,7 +417,7 @@ static ssize_t adc_read(FAR struct file *filep, FAR char *buffer,
412417 ret = nread ;
413418
414419return_with_irqdisabled :
415- leave_critical_section ( flags );
420+ nxmutex_unlock ( & dev -> ad_lock );
416421 }
417422
418423 ainfo ("Returning: %d\n" , ret );
@@ -754,7 +759,7 @@ int adc_register(FAR const char *path, FAR struct adc_dev_s *dev)
754759 /* Initialize semaphores & mutex */
755760
756761 nxsem_init (& dev -> ad_recv .af_sem , 0 , 0 );
757- nxmutex_init (& dev -> ad_closelock );
762+ nxmutex_init (& dev -> ad_lock );
758763
759764 /* Reset the ADC hardware */
760765
@@ -812,7 +817,7 @@ int adc_register(FAR const char *path, FAR struct adc_dev_s *dev)
812817 }
813818
814819 nxsem_destroy (& dev -> ad_recv .af_sem );
815- nxmutex_destroy (& dev -> ad_closelock );
820+ nxmutex_destroy (& dev -> ad_lock );
816821 return ret ;
817822 }
818823
0 commit comments