Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752025AbbKYRxx (ORCPT ); Wed, 25 Nov 2015 12:53:53 -0500 Received: from mail-lf0-f45.google.com ([209.85.215.45]:36777 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751188AbbKYRxp (ORCPT ); Wed, 25 Nov 2015 12:53:45 -0500 From: Alexander Kuleshov To: Lidza Louina Cc: Daeseok Youn , Greg Kroah-Hartman , driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Alexander Kuleshov Subject: [PATCH v2] staging/dgap: move duplicated code from the dgap_cm.* functions Date: Wed, 25 Nov 2015 23:51:21 +0600 Message-Id: <1448473881-9757-1-git-send-email-kuleshovmail@gmail.com> X-Mailer: git-send-email 2.6.2.485.g1bc8fea Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4837 Lines: 180 The dgap driver contains three functions: dgap_cmdb(), dgap_cmdw() and dgap_cmdw_exit which are contain duplicated code which waits if necessary before updating the pointer to limit outstanding commands. This patch introduces the wait_for_fep_cmds_limit() function which is will be called from these functions to prevent code duplication. Signed-off-by: Alexander Kuleshov --- Forgot Signed-off-by line drivers/staging/dgap/dgap.c | 103 ++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 66 deletions(-) diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c index bad3551..0a20253 100644 --- a/drivers/staging/dgap/dgap.c +++ b/drivers/staging/dgap/dgap.c @@ -2328,6 +2328,37 @@ schedule_poller: add_timer(&dgap_poll_timer); } + +/* + * Wait if necessary before updating the head + * pointer to limit the number of outstanding + * commands to the FEP. If the time spent waiting + * is outlandish, declare the FEP dead. + */ +static void wait_for_fep_cmds_limit(struct channel_t *ch, + struct __iomem cm_t *cm_addr, + u16 head, u16 tail, uint ncmds) +{ + int n; + int count; + + for (count = dgap_count ;;) { + head = readw(&cm_addr->cm_head); + tail = readw(&cm_addr->cm_tail); + + n = (head - tail) & (CMDMAX - CMDSTART - 4); + + if (n <= ncmds * sizeof(struct cm_t)) + break; + + if (--count == 0) { + ch->ch_bd->state = BOARD_FAILED; + return; + } + udelay(10); + } +} + /*======================================================================= * * dgap_cmdb - Sends a 2 byte command to the FEP. @@ -2345,8 +2376,6 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1, { char __iomem *vaddr; struct __iomem cm_t *cm_addr; - uint count; - uint n; u16 head; u16 tail; @@ -2391,27 +2420,9 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1, writew(head, &cm_addr->cm_head); - /* - * Wait if necessary before updating the head - * pointer to limit the number of outstanding - * commands to the FEP. If the time spent waiting - * is outlandish, declare the FEP dead. - */ - for (count = dgap_count ;;) { - head = readw(&cm_addr->cm_head); - tail = readw(&cm_addr->cm_tail); - - n = (head - tail) & (CMDMAX - CMDSTART - 4); + wait_for_fep_cmds_limit(ch, cm_addr, head, tail, ncmds); - if (n <= ncmds * sizeof(struct cm_t)) - break; - - if (--count == 0) { - ch->ch_bd->state = BOARD_FAILED; - return; - } - udelay(10); - } + return; } /*======================================================================= @@ -2429,8 +2440,6 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds) { char __iomem *vaddr; struct __iomem cm_t *cm_addr; - uint count; - uint n; u16 head; u16 tail; @@ -2473,27 +2482,9 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds) writew(head, &cm_addr->cm_head); - /* - * Wait if necessary before updating the head - * pointer to limit the number of outstanding - * commands to the FEP. If the time spent waiting - * is outlandish, declare the FEP dead. - */ - for (count = dgap_count ;;) { - head = readw(&cm_addr->cm_head); - tail = readw(&cm_addr->cm_tail); - - n = (head - tail) & (CMDMAX - CMDSTART - 4); + wait_for_fep_cmds_limit(ch, cm_addr, head, tail, ncmds); - if (n <= ncmds * sizeof(struct cm_t)) - break; - - if (--count == 0) { - ch->ch_bd->state = BOARD_FAILED; - return; - } - udelay(10); - } + return; } /*======================================================================= @@ -2511,8 +2502,6 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds) { char __iomem *vaddr; struct __iomem cm_t *cm_addr; - uint count; - uint n; u16 head; u16 tail; @@ -2567,27 +2556,9 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds) writew(head, &cm_addr->cm_head); - /* - * Wait if necessary before updating the head - * pointer to limit the number of outstanding - * commands to the FEP. If the time spent waiting - * is outlandish, declare the FEP dead. - */ - for (count = dgap_count ;;) { - head = readw(&cm_addr->cm_head); - tail = readw(&cm_addr->cm_tail); - - n = (head - tail) & (CMDMAX - CMDSTART - 4); + wait_for_fep_cmds_limit(ch, cm_addr, head, tail, ncmds); - if (n <= ncmds * sizeof(struct cm_t)) - break; - - if (--count == 0) { - ch->ch_bd->state = BOARD_FAILED; - return; - } - udelay(10); - } + return; } /*======================================================================= -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/