[En-Nut-Discussion] Evaluating USART IOCTL errors

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Mon Jul 2 17:52:34 CEST 2012


Hello,

our dev/usart.c IOCTL setting code doesn't honor if the lower level device
driver signals some error. Even if the lower level driver is unable to
fullfill the flag, the flag remains set. 
Setting e.g. USART_MF_BLOCKWRITE for a device with no Blockmode will set the
USART_MF_BLOCKWRITE flag and writing to the device later will stall, as the
upper level code path for Blockmode is taken.

Is appended way of coding the right thing? It handles the
dcb_set_flow_control cases. Only setting a feature might fail. 

Should I check in?

Bye
-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
diff --git a/nut/dev/usart.c b/nut/dev/usart.c
index 0d7c407..83ba8ef 100644
--- a/nut/dev/usart.c
+++ b/nut/dev/usart.c
@@ -784,6 +784,8 @@ int UsartIOCtl(NUTDEVICE * dev, int req, void *conf)
         else
             dcb->dcb_modeflags &= ~USART_MF_LOCALECHO;
         rc = (dcb->dcb_set_flow_control) (dcb->dcb_modeflags);
+        if (rc == -1)
+            dcb->dcb_modeflags &= ~USART_MF_LOCALECHO;
         break;
     case UART_GETLOCALECHO:
         if (dcb->dcb_modeflags & USART_MF_LOCALECHO)
@@ -798,6 +800,8 @@ int UsartIOCtl(NUTDEVICE * dev, int req, void *conf)
         else
             dcb->dcb_modeflags &= ~USART_MF_XONXOFF;
         rc = (dcb->dcb_set_flow_control) (dcb->dcb_modeflags);
+        if (rc == -1)
+            dcb->dcb_modeflags &= ~USART_MF_XONXOFF;
         break;
     case UART_GETFLOWCONTROL:
         *lvp = (*dcb->dcb_get_flow_control) ();
@@ -809,6 +813,8 @@ int UsartIOCtl(NUTDEVICE * dev, int req, void *conf)
         else
             dcb->dcb_modeflags &= ~USART_MF_BLOCKREAD;
         rc = (dcb->dcb_set_flow_control) (dcb->dcb_modeflags);
+        if (rc == -1)
+            dcb->dcb_modeflags &= ~USART_MF_BLOCKREAD;
         break;
     case UART_GETBLOCKREAD:
         *lvp = (*dcb->dcb_get_flow_control) ();
@@ -820,6 +826,8 @@ int UsartIOCtl(NUTDEVICE * dev, int req, void *conf)
         else
             dcb->dcb_modeflags &= ~USART_MF_BLOCKWRITE;
         rc = (dcb->dcb_set_flow_control) (dcb->dcb_modeflags);
+        if (rc == -1)
+            dcb->dcb_modeflags &= ~USART_MF_BLOCKWRITE;
         break;
     case UART_GETBLOCKWRITE:
         *lvp = (*dcb->dcb_get_flow_control) ();



More information about the En-Nut-Discussion mailing list