The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] staging/dgap: move duplicated code from the dgap_cm.* functions
@ 2015-11-25 13:10 Alexander Kuleshov
  2015-11-26  6:26 ` Sudip Mukherjee
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Kuleshov @ 2015-11-25 13:10 UTC (permalink / raw)
  To: Lidza Louina
  Cc: Daeseok Youn, Greg Kroah-Hartman, driverdev-devel, devel,
	linux-kernel, Alexander Kuleshov

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.
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging/dgap: move duplicated code from the dgap_cm.* functions
  2015-11-25 13:10 [PATCH] staging/dgap: move duplicated code from the dgap_cm.* functions Alexander Kuleshov
@ 2015-11-26  6:26 ` Sudip Mukherjee
  2015-11-26 18:50   ` Alexander Kuleshov
  0 siblings, 1 reply; 3+ messages in thread
From: Sudip Mukherjee @ 2015-11-26  6:26 UTC (permalink / raw)
  To: Alexander Kuleshov
  Cc: Lidza Louina, devel, Greg Kroah-Hartman, Daeseok Youn,
	driverdev-devel, linux-kernel

On Wed, Nov 25, 2015 at 07:10:30PM +0600, Alexander Kuleshov wrote:
> 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 ?

regards
sudip

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging/dgap: move duplicated code from the dgap_cm.* functions
  2015-11-26  6:26 ` Sudip Mukherjee
@ 2015-11-26 18:50   ` Alexander Kuleshov
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Kuleshov @ 2015-11-26 18:50 UTC (permalink / raw)
  To: Sudip Mukherjee
  Cc: Lidza Louina, devel, Greg Kroah-Hartman, Daeseok Youn,
	driverdev-devel, LKML

On Thu, Nov 26, 2015 at 12:26 PM, Sudip Mukherjee
<sudipm.mukherjee@gmail.com> wrote:
> Signed-off-by ?

Hello Sudip,

I've put it in the v2 (https://lkml.org/lkml/2015/11/25/650)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-26 18:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-25 13:10 [PATCH] staging/dgap: move duplicated code from the dgap_cm.* functions Alexander Kuleshov
2015-11-26  6:26 ` Sudip Mukherjee
2015-11-26 18:50   ` Alexander Kuleshov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox