netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean Sacren <sakiwit@gmail.com>
To: Alexander Smirnov <alex.bluesman.smirnov@gmail.com>,
	Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Cc: Alexander Aring <alex.aring@gmail.com>,
	linux-zigbee-devel@lists.sourceforge.net, netdev@vger.kernel.org
Subject: [PATCH net-next] ieee802154: use helper function to get rid of redundancy
Date: Sat, 31 May 2014 17:39:02 -0600	[thread overview]
Message-ID: <1401579542-17108-1-git-send-email-sakiwit@gmail.com> (raw)

In some call sites of at86rf230_write_subreg(), they are rather
redundant. Use a helper function to replace those call sites for
efficiency.

With at86rf230_write_subreg_by_page(), now ->rssi_base_val is
assigned before at86rf230_write_subreg() is evaluated. Looking at
at86rf230_write_subreg(), that change could possibly affect

		__at86rf230_read_subreg()
and
		__at86rf230_write()

only or vice versa. Yet by the definition of

		struct at86rf230_local

changing ->rssi_base_val will in no way affect those two functions
above and evaluation of those two has no impact on ->rssi_base_val.
Thus, at86rf230_write_subreg_by_page() itself is safe.

Additionally at86rf230_write_subreg_by_channel() is simple and safe.

Signed-off-by: Jean Sacren <sakiwit@gmail.com>
---
 drivers/net/ieee802154/at86rf230.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 4517b149ed07..5aecbd1c402c 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -597,25 +597,37 @@ at86rf230_set_channel(struct at86rf230_local *lp, int page, int channel)
 	return at86rf230_write_subreg(lp, SR_CHANNEL, channel);
 }
 
+static int at86rf230_write_subreg_by_channel(struct at86rf230_local *lp,
+					     int channel)
+{
+	if (channel)
+		channel = 1;
+
+	return at86rf230_write_subreg(lp, SR_SUB_MODE, channel);
+}
+
+static int at86rf230_write_subreg_by_page(struct at86rf230_local *lp, int page)
+{
+	if (page) {
+		lp->rssi_base_val = -98;
+		page = 1;
+	} else {
+		lp->rssi_base_val = -100;
+	}
+
+	return at86rf230_write_subreg(lp, SR_BPSK_QPSK, page);
+}
+
 static int
 at86rf212_set_channel(struct at86rf230_local *lp, int page, int channel)
 {
 	int rc;
 
-	if (channel == 0)
-		rc = at86rf230_write_subreg(lp, SR_SUB_MODE, 0);
-	else
-		rc = at86rf230_write_subreg(lp, SR_SUB_MODE, 1);
+	rc = at86rf230_write_subreg_by_channel(lp, channel);
 	if (rc < 0)
 		return rc;
 
-	if (page == 0) {
-		rc = at86rf230_write_subreg(lp, SR_BPSK_QPSK, 0);
-		lp->rssi_base_val = -100;
-	} else {
-		rc = at86rf230_write_subreg(lp, SR_BPSK_QPSK, 1);
-		lp->rssi_base_val = -98;
-	}
+	rc = at86rf230_write_subreg_by_page(lp, page);
 	if (rc < 0)
 		return rc;
 

             reply	other threads:[~2014-05-31 23:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-31 23:39 Jean Sacren [this message]
2014-06-01  7:26 ` [PATCH net-next] ieee802154: use helper function to get rid of redundancy Alexander Aring
2014-06-01 14:23   ` Jean Sacren
     [not found]     ` <20140601142317.GA19754-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-06-01 14:35       ` Alexander Aring
2014-06-01 15:35         ` Jean Sacren
2014-06-01 16:39           ` Alexander Aring
2014-06-01 17:49             ` Jean Sacren
2014-06-01 17:53               ` Jean Sacren

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=1401579542-17108-1-git-send-email-sakiwit@gmail.com \
    --to=sakiwit@gmail.com \
    --cc=alex.aring@gmail.com \
    --cc=alex.bluesman.smirnov@gmail.com \
    --cc=dbaryshkov@gmail.com \
    --cc=linux-zigbee-devel@lists.sourceforge.net \
    --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).