linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ivo van Doorn <ivdoorn@gmail.com>
To: "John W. Linville" <linville@tuxdriver.com>
Cc: linux-wireless@vger.kernel.org, rt2400-devel@lists.sourceforge.net
Subject: [PATCH 3/5] rt2x00: Remove duplicate code
Date: Tue, 2 Dec 2008 18:20:22 +0100	[thread overview]
Message-ID: <200812021820.22750.IvDoorn@gmail.com> (raw)
In-Reply-To: <200812021820.05124.IvDoorn@gmail.com>

Simplify rt2x00lib_config_antenna() by moving
duplicate code into a seperate static inlined
function.

Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
---
 drivers/net/wireless/rt2x00/rt2x00config.c |   37 ++++++++++++++-------------
 1 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/drivers/net/wireless/rt2x00/rt2x00config.c b/drivers/net/wireless/rt2x00/rt2x00config.c
index b3bc8b4..e66fb31 100644
--- a/drivers/net/wireless/rt2x00/rt2x00config.c
+++ b/drivers/net/wireless/rt2x00/rt2x00config.c
@@ -108,33 +108,34 @@ void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev,
 	rt2x00dev->ops->lib->config_erp(rt2x00dev, &erp);
 }
 
+static inline
+enum antenna rt2x00lib_config_antenna_check(enum antenna current_ant,
+					    enum antenna default_ant)
+{
+	if (current_ant != ANTENNA_SW_DIVERSITY)
+		return current_ant;
+	return (default_ant != ANTENNA_SW_DIVERSITY) ? default_ant : ANTENNA_B;
+}
+
 void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
 			      struct antenna_setup *ant)
 {
+	struct antenna_setup *def = &rt2x00dev->default_ant;
+	struct antenna_setup *active = &rt2x00dev->link.ant.active;
+
 	/*
 	 * Failsafe: Make sure we are not sending the
 	 * ANTENNA_SW_DIVERSITY state to the driver.
 	 * If that happes fallback to hardware default,
 	 * or our own default.
+	 * The calls to rt2x00lib_config_antenna_check()
+	 * might have caused that we restore back to the already
+	 * active setting. If that has happened we can quit.
 	 */
-	if (ant->rx == ANTENNA_SW_DIVERSITY) {
-		if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
-			ant->rx = ANTENNA_B;
-		else
-			ant->rx = rt2x00dev->default_ant.rx;
-	}
-	if (ant->tx == ANTENNA_SW_DIVERSITY) {
-		if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
-			ant->tx = ANTENNA_B;
-		else
-			ant->tx = rt2x00dev->default_ant.tx;
-	}
+	ant->rx = rt2x00lib_config_antenna_check(ant->rx, def->rx);
+	ant->tx = rt2x00lib_config_antenna_check(ant->tx, def->tx);
 
-	/*
-	 * Only reconfigure when something has changed.
-	 */
-	if (ant->rx == rt2x00dev->link.ant.active.rx &&
-	    ant->tx == rt2x00dev->link.ant.active.tx)
+	if (ant->rx == active->rx && ant->tx == active->tx)
 		return;
 
 	/*
@@ -154,7 +155,7 @@ void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
 	rt2x00lib_reset_link_tuner(rt2x00dev);
 	rt2x00_reset_link_ant_rssi(&rt2x00dev->link);
 
-	memcpy(&rt2x00dev->link.ant.active, ant, sizeof(*ant));
+	memcpy(active, ant, sizeof(*ant));
 
 	if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
 		rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON_LINK);
-- 
1.5.6.1


  reply	other threads:[~2008-12-02 17:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-02 17:19 Please pull 'upstream' branch of rt2x00 Ivo van Doorn
2008-12-02 17:19 ` [PATCH 1/5] rt2x00: Optimize IV/EIV handling Ivo van Doorn
2008-12-02 17:20   ` [PATCH 2/5] rt2x00: Store retry limit values Ivo van Doorn
2008-12-02 17:20     ` Ivo van Doorn [this message]
2008-12-02 17:20       ` [PATCH 4/5] rt2x00: Implement HW encryption (rt2500usb) Ivo van Doorn
2008-12-02 17:20         ` [PATCH 5/5] rt2x00: Release rt2x00 2.2.3 Ivo van Doorn

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=200812021820.22750.IvDoorn@gmail.com \
    --to=ivdoorn@gmail.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    --cc=rt2400-devel@lists.sourceforge.net \
    /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).