From: Kelley Nielsen Date: Wed, 6 Nov 2013 13:08:11 +0000 (-0800) Subject: staging: ft1000: extract helper handle_misc_portid() X-Git-Tag: upstream/snapshot3+hdmi~3491^2~783^2~232 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8a58cad260bd37b7d20d222b083b4844d086b2d7;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git staging: ft1000: extract helper handle_misc_portid() The function ft1000_poll, in ft1000_hw.c, is complex, with deep levels of nesting, unnecessary variables, and style issues. Extract the default case of the switch statement to its own function, handle_misc_portid. Make the variable struct dpram_blk *pdpram_blk local to the new function and remove it from the old. The variable struct pseudo_hdr *ppseudo_hdr is used only once, to access a member of another struct, so eliminate it and access the member directly. Return -1 in all the places where the code fails, and 0 on successful completion. Fix coding style errors. Signed-off-by: Kelley Nielsen Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c index 52e6b18..95ea5c4 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c @@ -1480,6 +1480,54 @@ static int dsp_broadcast_msg_id(struct ft1000_usb *dev) return 0; } +static int handle_misc_portid(struct ft1000_usb *dev) +{ + struct dpram_blk *pdpram_blk; + 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 { + DEBUG("Out of memory in free receive command pool\n"); + return -1; + } + return 0; +} + int ft1000_poll(void* dev_id) { struct ft1000_usb *dev = (struct ft1000_usb *)dev_id; @@ -1492,8 +1540,7 @@ int ft1000_poll(void* dev_id) u16 data; u16 modulo; u16 portid; - struct dpram_blk *pdpram_blk; - struct pseudo_hdr *ppseudo_hdr; + if (ft1000_chkcard(dev) == FALSE) { DEBUG("ft1000_poll::ft1000_chkcard: failed\n"); return -1; @@ -1529,45 +1576,8 @@ int ft1000_poll(void* dev_id) status = dsp_broadcast_msg_id(dev); break; default: - 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; - // Search for correct application block - for (i=0; iapp_info[i].app_id == ppseudo_hdr->portdest) { - break; - } - } - - if (i == MAX_NUM_APP) { - DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr->portdest); - // Put memory back to free pool - ft1000_free_buffer(pdpram_blk, &freercvpool); - } - else { - if (dev->app_info[i].NumOfMsg > MAX_MSG_LIMIT) { - // Put memory back to free pool - ft1000_free_buffer(pdpram_blk, &freercvpool); - } - 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 { - // Put memory back to free pool - ft1000_free_buffer(pdpram_blk, &freercvpool); - } - } - else { - DEBUG("Out of memory in free receive command pool\n"); - } - break; + status = handle_misc_portid(dev); + break; } } else {