staging: r8188eu: Fix smatch warning in hal/usb_ops_linux.c
authorLarry Finger <Larry.Finger@lwfinger.net>
Wed, 4 Sep 2013 20:56:01 +0000 (15:56 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 17 Sep 2013 14:47:45 +0000 (07:47 -0700)
Smatch reports the following warning:
drivers/staging/rtl8188eu/hal/usb_ops_linux.c:614 usb_read_port() warn: variable dereferenced before check 'precvbuf' (see line 611)

Fixing this particular warning required some refactoring of the code.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8188eu/hal/usb_ops_linux.c

index bc564169b2f0560b155a519d2421fc5ae7f71a56..2a20f2348108058f39c033700f7023f5fc570091 100644 (file)
@@ -605,68 +605,68 @@ _func_enter_;
                return _FAIL;
        }
 
+       if (!precvbuf) {
+               RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
+                        ("usb_read_port:precvbuf==NULL\n"));
+               return _FAIL;
+       }
+
        if ((!precvbuf->reuse) || (precvbuf->pskb == NULL)) {
                precvbuf->pskb = skb_dequeue(&precvpriv->free_recv_skb_queue);
                if (NULL != precvbuf->pskb)
                        precvbuf->reuse = true;
        }
 
-       if (precvbuf != NULL) {
-               rtl8188eu_init_recvbuf(adapter, precvbuf);
-
-               /* re-assign for linux based on skb */
-               if ((!precvbuf->reuse) || (precvbuf->pskb == NULL)) {
-                       precvbuf->pskb = netdev_alloc_skb(adapter->pnetdev, MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ);
-                       if (precvbuf->pskb == NULL) {
-                               RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("init_recvbuf(): alloc_skb fail!\n"));
-                               DBG_88E("#### usb_read_port() alloc_skb fail!#####\n");
-                               return _FAIL;
-                       }
-
-                       tmpaddr = (size_t)precvbuf->pskb->data;
-                       alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1);
-                       skb_reserve(precvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
-
-                       precvbuf->phead = precvbuf->pskb->head;
-                       precvbuf->pdata = precvbuf->pskb->data;
-                       precvbuf->ptail = skb_tail_pointer(precvbuf->pskb);
-                       precvbuf->pend = skb_end_pointer(precvbuf->pskb);
-                       precvbuf->pbuf = precvbuf->pskb->data;
-               } else { /* reuse skb */
-                       precvbuf->phead = precvbuf->pskb->head;
-                       precvbuf->pdata = precvbuf->pskb->data;
-                       precvbuf->ptail = skb_tail_pointer(precvbuf->pskb);
-                       precvbuf->pend = skb_end_pointer(precvbuf->pskb);
-                       precvbuf->pbuf = precvbuf->pskb->data;
+       rtl8188eu_init_recvbuf(adapter, precvbuf);
 
-                       precvbuf->reuse = false;
+       /* re-assign for linux based on skb */
+       if ((!precvbuf->reuse) || (precvbuf->pskb == NULL)) {
+               precvbuf->pskb = netdev_alloc_skb(adapter->pnetdev, MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ);
+               if (precvbuf->pskb == NULL) {
+                       RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("init_recvbuf(): alloc_skb fail!\n"));
+                       DBG_88E("#### usb_read_port() alloc_skb fail!#####\n");
+                       return _FAIL;
                }
 
-               precvpriv->rx_pending_cnt++;
+               tmpaddr = (size_t)precvbuf->pskb->data;
+               alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1);
+               skb_reserve(precvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
+
+               precvbuf->phead = precvbuf->pskb->head;
+               precvbuf->pdata = precvbuf->pskb->data;
+               precvbuf->ptail = skb_tail_pointer(precvbuf->pskb);
+               precvbuf->pend = skb_end_pointer(precvbuf->pskb);
+               precvbuf->pbuf = precvbuf->pskb->data;
+       } else { /* reuse skb */
+               precvbuf->phead = precvbuf->pskb->head;
+               precvbuf->pdata = precvbuf->pskb->data;
+               precvbuf->ptail = skb_tail_pointer(precvbuf->pskb);
+               precvbuf->pend = skb_end_pointer(precvbuf->pskb);
+               precvbuf->pbuf = precvbuf->pskb->data;
+
+               precvbuf->reuse = false;
+       }
 
-               purb = precvbuf->purb;
+       precvpriv->rx_pending_cnt++;
 
-               /* translate DMA FIFO addr to pipehandle */
-               pipe = ffaddr2pipehdl(pdvobj, addr);
+       purb = precvbuf->purb;
 
-               usb_fill_bulk_urb(purb, pusbd, pipe,
-                                 precvbuf->pbuf,
-                                 MAX_RECVBUF_SZ,
-                                 usb_read_port_complete,
-                                 precvbuf);/* context is precvbuf */
+       /* translate DMA FIFO addr to pipehandle */
+       pipe = ffaddr2pipehdl(pdvobj, addr);
 
-               err = usb_submit_urb(purb, GFP_ATOMIC);
-               if ((err) && (err != (-EPERM))) {
-                       RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
-                                ("cannot submit rx in-token(err=0x%.8x), URB_STATUS =0x%.8x",
-                                err, purb->status));
-                       DBG_88E("cannot submit rx in-token(err = 0x%08x),urb_status = %d\n",
-                               err, purb->status);
-                       ret = _FAIL;
-               }
-       } else {
+       usb_fill_bulk_urb(purb, pusbd, pipe,
+                         precvbuf->pbuf,
+                         MAX_RECVBUF_SZ,
+                         usb_read_port_complete,
+                         precvbuf);/* context is precvbuf */
+
+       err = usb_submit_urb(purb, GFP_ATOMIC);
+       if ((err) && (err != (-EPERM))) {
                RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
-                        ("usb_read_port:precvbuf ==NULL\n"));
+                        ("cannot submit rx in-token(err=0x%.8x), URB_STATUS =0x%.8x",
+                        err, purb->status));
+               DBG_88E("cannot submit rx in-token(err = 0x%08x),urb_status = %d\n",
+                       err, purb->status);
                ret = _FAIL;
        }