aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging/ft1000
diff options
context:
space:
mode:
authorKelley Nielsen <kelleynnn@gmail.com>2013-11-06 05:08:58 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-11-10 07:55:00 -0800
commitf3802bdb15f7bea68ca330d8d909c56ac1e15119 (patch)
tree0d7816e9226ee529c69aa6657912a5643e48cc7a /drivers/staging/ft1000
parent8a58cad260bd37b7d20d222b083b4844d086b2d7 (diff)
downloadlinux-stericsson-f3802bdb15f7bea68ca330d8d909c56ac1e15119.tar.gz
staging: ft1000: flatten nesting in handle_misc_portid
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>
Diffstat (limited to 'drivers/staging/ft1000')
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_hw.c61
1 files changed, 25 insertions, 36 deletions
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
index 95ea5c4b501f..2a23b4427ded 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
@@ -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)