staging: ft1000: extract dsp_broadcast_msg_id()
authorKelley Nielsen <kelleynnn@gmail.com>
Wed, 6 Nov 2013 05:39:10 +0000 (21:39 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 10 Nov 2013 15:53:48 +0000 (07:53 -0800)
The function ft1000_poll, in ft1000_hw.c, is overly complex, with at
least five levels of nesting. Extract the lines in switch case
DSPBCMSGID into their own function, called dsp_broadcast_msg_id(). Pass
one parameter, struct ft1000_usb *dev. Make a copy of struct dpram_blk
*pdpram_blk local to the new function, since it is initialized at the
top of each case in which it appears. Make unsigned long flags local to
the new function. Remove the assignment to struct pseudo_hdr
*ppseudo_hdr, which is otherwise unused in the switch case, and receives
the same assignment at the top of each case in which it appears. Return
an int, 0 for success and -1 for error. Correct style issues in the
extracted lines.

Signed-off-by: Kelley Nielsen <kelleynnn@gmail.com>
Reviewed-by: Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ft1000/ft1000-usb/ft1000_hw.c

index e9ef27f8e19db2e6728c9b2a37b9e6a60215fc23..52e6b187d0cba86c5a4b4a53129c6336eb1a20cd 100644 (file)
@@ -1432,6 +1432,54 @@ out:
        return status;
 }
 
+/* Check which application has registered for dsp broadcast messages */
+static int dsp_broadcast_msg_id(struct ft1000_usb *dev)
+{
+       struct dpram_blk *pdpram_blk;
+       unsigned long flags;
+       int i;
+
+       for (i = 0; i < MAX_NUM_APP; i++) {
+               if ((dev->app_info[i].DspBCMsgFlag)
+                               && (dev->app_info[i].fileobject)
+                               && (dev->app_info[i].NumOfMsg
+                                       < MAX_MSG_LIMIT)) {
+                       pdpram_blk = ft1000_get_buffer(&freercvpool);
+                       if (pdpram_blk != NULL) {
+                               if (ft1000_receive_cmd(dev,
+                                                       pdpram_blk->pbuffer,
+                                                       MAX_CMD_SQSIZE)) {
+                                       /* Put message into the
+                                        * appropriate application block
+                                        * */
+                                       dev->app_info[i].nRxMsg++;
+                                       spin_lock_irqsave(&free_buff_lock,
+                                                       flags);
+                                       list_add_tail(&pdpram_blk->list,
+                                                       &dev->app_info[i]
+                                                       .app_sqlist);
+                                       dev->app_info[i].NumOfMsg++;
+                                       spin_unlock_irqrestore(&free_buff_lock,
+                                                       flags);
+                                       wake_up_interruptible(&dev->app_info[i]
+                                                       .wait_dpram_msg);
+                               } else {
+                                       dev->app_info[i].nRxMsgMiss++;
+                                       ft1000_free_buffer(pdpram_blk,
+                                                       &freercvpool);
+                                       DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
+                                       return -1;
+                               }
+                       } else {
+                               DEBUG("Out of memory in free receive command pool\n");
+                               dev->app_info[i].nRxMsgMiss++;
+                               return -1;
+                       }
+               }
+       }
+       return 0;
+}
+
 int ft1000_poll(void* dev_id)
 {
     struct ft1000_usb *dev = (struct ft1000_usb *)dev_id;
@@ -1446,8 +1494,6 @@ int ft1000_poll(void* dev_id)
     u16 portid;
        struct dpram_blk *pdpram_blk;
        struct pseudo_hdr *ppseudo_hdr;
-    unsigned long flags;
-
     if (ft1000_chkcard(dev) == FALSE) {
         DEBUG("ft1000_poll::ft1000_chkcard: failed\n");
         return -1;
@@ -1480,39 +1526,8 @@ int ft1000_poll(void* dev_id)
                             return status;
                         break;
                     case DSPBCMSGID:
-                        // This is a dsp broadcast message
-                        // Check which application has registered for dsp broadcast messages
-
-                       for (i=0; i<MAX_NUM_APP; i++) {
-                          if ( (dev->app_info[i].DspBCMsgFlag) && (dev->app_info[i].fileobject) &&
-                                         (dev->app_info[i].NumOfMsg < MAX_MSG_LIMIT)  )
-                          {
-                              pdpram_blk = ft1000_get_buffer (&freercvpool);
-                              if (pdpram_blk != NULL) {
-                                  if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE) ) {
-                                       ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer;
-                                      // Put message into the appropriate application block
-                                      dev->app_info[i].nRxMsg++;
-                                      spin_lock_irqsave(&free_buff_lock, flags);
-                                      list_add_tail(&pdpram_blk->list, &dev->app_info[i].app_sqlist);
-                                      dev->app_info[i].NumOfMsg++;
-                                      spin_unlock_irqrestore(&free_buff_lock, flags);
-                                      wake_up_interruptible(&dev->app_info[i].wait_dpram_msg);
-                                   }
-                                   else {
-                                      dev->app_info[i].nRxMsgMiss++;
-                                      // Put memory back to free pool
-                                      ft1000_free_buffer(pdpram_blk, &freercvpool);
-                                      DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
-                                   }
-                               }
-                               else {
-                                   DEBUG("Out of memory in free receive command pool\n");
-                                   dev->app_info[i].nRxMsgMiss++;
-                               }
-                           }
-                       }
-                        break;
+                       status = dsp_broadcast_msg_id(dev);
+                       break;
                     default:
                         pdpram_blk = ft1000_get_buffer (&freercvpool);