summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorKelley Nielsen <kelleynnn@gmail.com>2013-11-05 21:39:10 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-11-10 07:53:48 -0800
commit6eca0c1fa29bd4d92cd0cb20fd421c8e631814dc (patch)
tree466d5f14e8c1f2b390bd2d3d8784d1109a182ce4 /drivers
parentd5ae3c482df04a74e03ed944f33209178adaf03f (diff)
staging: ft1000: extract dsp_broadcast_msg_id()
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_hw.c85
1 files changed, 50 insertions, 35 deletions
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
index e9ef27f8e19..52e6b187d0c 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
@@ -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);