netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tilman Schmidt <tilman@imap.cc>
To: David Miller <davem@davemloft.net>, Karsten Keil <isdn@linux-pingi.de>
Cc: Hansjoerg Lipp <hjlipp@web.de>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	isdn4linux@listserv.isdn4linux.de,
	i4ldeveloper@listserv.isdn4linux.de
Subject: [PATCH 9/9] gigaset: convert strcmp chain to table lookup
Date: Sun, 25 Oct 2009 20:30:57 +0100 (CET)	[thread overview]
Message-ID: <20091023-patch-gigaset-09.tilman@imap.cc> (raw)
In-Reply-To: <20091023-patch-gigaset-00.tilman@imap.cc>

Replace the sequence of strcmp calls for interpreting ZSAU parameter
strings by a table of known strings and lookup loop to improve
readability.

Impact: readability improvement, no functional change
Signed-off-by: Tilman Schmidt <tilman@imap.cc>
---
 drivers/isdn/gigaset/ev-layer.c |   42 +++++++++++++++++++++++---------------
 drivers/isdn/gigaset/gigaset.h  |    6 -----
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/drivers/isdn/gigaset/ev-layer.c b/drivers/isdn/gigaset/ev-layer.c
index a9a3975..ddeb045 100644
--- a/drivers/isdn/gigaset/ev-layer.c
+++ b/drivers/isdn/gigaset/ev-layer.c
@@ -374,7 +374,11 @@ struct reply_t gigaset_tab_cid[] =
 };
 
 
-static const struct resp_type_t resp_type[] =
+static const struct resp_type_t {
+	unsigned char	*response;
+	int		resp_code;
+	int		type;
+} resp_type[] =
 {
 	{"OK",		RSP_OK,		RT_NOTHING},
 	{"ERROR",	RSP_ERROR,	RT_NOTHING},
@@ -402,6 +406,20 @@ static const struct resp_type_t resp_type[] =
 	{NULL,		0,		0}
 };
 
+static const struct zsau_resp_t {
+	unsigned char	*str;
+	int		code;
+} zsau_resp[] =
+{
+	{"OUTGOING_CALL_PROCEEDING",	ZSAU_OUTGOING_CALL_PROCEEDING},
+	{"CALL_DELIVERED",		ZSAU_CALL_DELIVERED},
+	{"ACTIVE",			ZSAU_ACTIVE},
+	{"DISCONNECT_IND",		ZSAU_DISCONNECT_IND},
+	{"NULL",			ZSAU_NULL},
+	{"DISCONNECT_REQ",		ZSAU_DISCONNECT_REQ},
+	{NULL,				ZSAU_UNKNOWN}
+};
+
 /*
  * Get integer from char-pointer
  */
@@ -480,6 +498,7 @@ void gigaset_handle_modem_response(struct cardstate *cs)
 	int params;
 	int i, j;
 	const struct resp_type_t *rt;
+	const struct zsau_resp_t *zr;
 	int curarg;
 	unsigned long flags;
 	unsigned next, tail, head;
@@ -606,25 +625,14 @@ void gigaset_handle_modem_response(struct cardstate *cs)
 				event->parameter = ZSAU_NONE;
 				break;
 			}
-			if (!strcmp(argv[curarg], "OUTGOING_CALL_PROCEEDING"))
-				event->parameter =
-					ZSAU_OUTGOING_CALL_PROCEEDING;
-			else if (!strcmp(argv[curarg], "CALL_DELIVERED"))
-				event->parameter = ZSAU_CALL_DELIVERED;
-			else if (!strcmp(argv[curarg], "ACTIVE"))
-				event->parameter = ZSAU_ACTIVE;
-			else if (!strcmp(argv[curarg], "DISCONNECT_IND"))
-				event->parameter = ZSAU_DISCONNECT_IND;
-			else if (!strcmp(argv[curarg], "NULL"))
-				event->parameter = ZSAU_NULL;
-			else if (!strcmp(argv[curarg], "DISCONNECT_REQ"))
-				event->parameter = ZSAU_DISCONNECT_REQ;
-			else {
-				event->parameter = ZSAU_UNKNOWN;
+			for (zr = zsau_resp; zr->str; ++zr)
+				if (!strcmp(argv[curarg], zr->str))
+					break;
+			event->parameter = zr->code;
+			if (!zr->str)
 				dev_warn(cs->dev,
 					"%s: unknown parameter %s after ZSAU\n",
 					 __func__, argv[curarg]);
-			}
 			++curarg;
 			break;
 		case RT_STRING:
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
index 3c74cd1..e963a6c 100644
--- a/drivers/isdn/gigaset/gigaset.h
+++ b/drivers/isdn/gigaset/gigaset.h
@@ -357,12 +357,6 @@ struct at_state_t {
 	struct bc_state		*bcs;
 };
 
-struct resp_type_t {
-	unsigned char	*response;
-	int		resp_code;	/* RSP_XXXX */
-	int		type;		/* RT_XXXX */
-};
-
 struct event_t {
 	int type;
 	void *ptr, *arg;
-- 
1.6.2.1.214.ge986c


  parent reply	other threads:[~2009-10-25 19:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-25 19:29 [PATCH 0/9] Gigaset driver patches for 2.6.33 Tilman Schmidt
2009-10-25 19:29 ` [PATCH 1/9] gigaset: CAPI module readability improvements Tilman Schmidt
2009-10-25 19:29 ` [PATCH 2/9] gigaset: fix format string typo in CAPI dial command Tilman Schmidt
2009-10-25 19:29 ` [PATCH 3/9] gigaset: fix bad assumptions about CAPI skbuffs Tilman Schmidt
2009-10-25 19:30 ` [PATCH 4/9] usb_gigaset: code cleanup Tilman Schmidt
2009-10-25 19:30 ` [PATCH 5/9] gigaset: checkpatch cleanup Tilman Schmidt
2009-10-25 19:30 ` [PATCH 6/9] ser_gigaset: " Tilman Schmidt
2009-10-25 20:37   ` Alan Cox
2009-10-25 23:36     ` Tilman Schmidt
2009-10-26  0:54   ` Joe Perches
2009-10-26 23:59     ` Tilman Schmidt
2009-10-27  0:14       ` Joe Perches
2009-10-27 10:20       ` Karsten Keil
2009-10-25 19:30 ` [PATCH 7/9] bas_gigaset: " Tilman Schmidt
2009-10-25 19:30 ` [PATCH 8/9] gigaset: checkpatch cleanup of ev-layer.c Tilman Schmidt
2009-10-25 19:30 ` Tilman Schmidt [this message]
2009-10-29  8:37 ` [PATCH 0/9] Gigaset driver patches for 2.6.33 David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091023-patch-gigaset-09.tilman@imap.cc \
    --to=tilman@imap.cc \
    --cc=davem@davemloft.net \
    --cc=hjlipp@web.de \
    --cc=i4ldeveloper@listserv.isdn4linux.de \
    --cc=isdn4linux@listserv.isdn4linux.de \
    --cc=isdn@linux-pingi.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).