staging: ft1000: flatten nesting in handle_misc_portid
authorKelley Nielsen <kelleynnn@gmail.com>
Wed, 6 Nov 2013 13:08:58 +0000 (05:08 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 10 Nov 2013 15:55:00 +0000 (07:55 -0800)
The newly extracted function handle_misc_portid still has several
unnecessary levels of nesting, having inherited its logic from the
original extracted lines. Move handling for failed memory allocation
(of *pdpram_blk) to the top of the function, and return -1 from within
it. This eliminates the if statement around the body of the function.
Change two levels of nested if/else to an if/else-if/else. Create a
label, exit_failure, at the end of the function with the cleanup code,
and goto it at all points of failure. Also, goto it if the call to
ft1000_receive_cmd() fails, instead of descending into an if block if
it succeeds. Pull all lines from inside the former if blocks to the
left, and rejoin lines to take advantage of reclaimed horizontal space.

Signed-off-by: Kelley Nielsen <kelleynnn@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ft1000/ft1000-usb/ft1000_hw.c

index 95ea5c4b501fee1a9955130585bac4c1bd022763..2a23b4427dede41d651d1909d243c0360c6f2fe3 100644 (file)
@@ -1486,46 +1486,35 @@ static int handle_misc_portid(struct ft1000_usb *dev)
        int i;
 
        pdpram_blk = ft1000_get_buffer(&freercvpool);
-       if (pdpram_blk != NULL) {
-               if (ft1000_receive_cmd(dev, pdpram_blk->pbuffer,
-                                       MAX_CMD_SQSIZE)) {
-                       /* Search for correct application block */
-                       for (i = 0; i < MAX_NUM_APP; i++) {
-                               if (dev->app_info[i].app_id
-                                               == ((struct pseudo_hdr *)
-                                               pdpram_blk->pbuffer)
-                                               ->portdest)
-                                       break;
-                               return -1;
-                       }
-                       if (i == MAX_NUM_APP) {
-                               DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ((struct pseudo_hdr *)pdpram_blk->pbuffer)->portdest);
-                               ft1000_free_buffer(pdpram_blk, &freercvpool);
-                       } else {
-                               if (dev->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
-                                       ft1000_free_buffer(pdpram_blk,
-                                                       &freercvpool);
-                                       return -1;
-                               } else {
-                                       dev->app_info[i].nRxMsg++;
-                                       /* Put message into the appropriate
-                                        * application block
-                                        * */
-                                       list_add_tail(&pdpram_blk->list,
-                                                       &dev->app_info[i]
-                                                       .app_sqlist);
-                                       dev->app_info[i].NumOfMsg++;
-                               }
-                       }
-               } else {
-                       ft1000_free_buffer(pdpram_blk, &freercvpool);
-                       return -1;
-               }
-       } else {
+       if (pdpram_blk == NULL) {
                DEBUG("Out of memory in free receive command pool\n");
                return -1;
        }
+       if (!ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE))
+               goto exit_failure;
+
+       /* Search for correct application block */
+       for (i = 0; i < MAX_NUM_APP; i++) {
+               if (dev->app_info[i].app_id == ((struct pseudo_hdr *)
+                                       pdpram_blk->pbuffer)->portdest)
+                       break;
+       }
+       if (i == MAX_NUM_APP) {
+               DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ((struct pseudo_hdr *)pdpram_blk->pbuffer)->portdest);
+               goto exit_failure;
+       } else if (dev->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
+               goto exit_failure;
+       } else {
+               dev->app_info[i].nRxMsg++;
+               /* Put message into the appropriate application block */
+               list_add_tail(&pdpram_blk->list, &dev->app_info[i].app_sqlist);
+               dev->app_info[i].NumOfMsg++;
+       }
        return 0;
+
+exit_failure:
+       ft1000_free_buffer(pdpram_blk, &freercvpool);
+       return -1;
 }
 
 int ft1000_poll(void* dev_id)