public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Harvey Harrison <harvey.harrison@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH-mm] kernel: add common endian load/store API
Date: Mon, 24 Nov 2008 11:35:33 -0800	[thread overview]
Message-ID: <1227555333.5511.17.camel@brick> (raw)
In-Reply-To: <1227553971.5511.15.camel@brick>

From: Harvey Harrison <harvey.harrison@gmail.com>
Subject: [PATCH] block: aoe switch to the new endian helpers

Add the necesary casts now that the unaligned helpers are typesafe
and switch to load_* where possible as it is more efficient.

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
Andrew, I thought it might be helpful to show what the new API will
look like as it gets used, this is an example conversion patch.

 drivers/block/aoe/aoecmd.c |   30 +++++++++++++++---------------
 drivers/block/aoe/aoenet.c |    4 ++--
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index 71ff78c..199494a 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -642,16 +642,16 @@ ataid_complete(struct aoedev *d, struct aoetgt *t, unsigned char *id)
 	u16 n;
 
 	/* word 83: command set supported */
-	n = get_unaligned_le16(&id[83 << 1]);
+	n = load_le16_noalign((__le16 *)&id[83 << 1]);
 
 	/* word 86: command set/feature enabled */
-	n |= get_unaligned_le16(&id[86 << 1]);
+	n |= load_le16_noalign((__le16 *)&id[86 << 1]);
 
 	if (n & (1<<10)) {	/* bit 10: LBA 48 */
 		d->flags |= DEVFL_EXT;
 
 		/* word 100: number lba48 sectors */
-		ssize = get_unaligned_le64(&id[100 << 1]);
+		ssize = load_le16_noalign((__le16 *)&id[100 << 1]);
 
 		/* set as in ide-disk.c:init_idedisk_capacity */
 		d->geo.cylinders = ssize;
@@ -662,12 +662,12 @@ ataid_complete(struct aoedev *d, struct aoetgt *t, unsigned char *id)
 		d->flags &= ~DEVFL_EXT;
 
 		/* number lba28 sectors */
-		ssize = get_unaligned_le32(&id[60 << 1]);
+		ssize = load_le32_noalign((__le32 *)&id[60 << 1]);
 
 		/* NOTE: obsolete in ATA 6 */
-		d->geo.cylinders = get_unaligned_le16(&id[54 << 1]);
-		d->geo.heads = get_unaligned_le16(&id[55 << 1]);
-		d->geo.sectors = get_unaligned_le16(&id[56 << 1]);
+		d->geo.cylinders = load_le16_noalign((__le16 *)&id[54 << 1]);
+		d->geo.heads = load_le16_noalign((__le16 *)&id[55 << 1]);
+		d->geo.sectors = load_le16_noalign((__le16 *)&id[56 << 1]);
 	}
 
 	if (d->ssize != ssize)
@@ -760,7 +760,7 @@ aoecmd_ata_rsp(struct sk_buff *skb)
 	u16 aoemajor;
 
 	hin = (struct aoe_hdr *) skb_mac_header(skb);
-	aoemajor = get_unaligned_be16(&hin->major);
+	aoemajor = load_be16_noalign(&hin->major);
 	d = aoedev_by_aoeaddr(aoemajor, hin->minor);
 	if (d == NULL) {
 		snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response "
@@ -772,7 +772,7 @@ aoecmd_ata_rsp(struct sk_buff *skb)
 
 	spin_lock_irqsave(&d->lock, flags);
 
-	n = get_unaligned_be32(&hin->tag);
+	n = load_be32_noalign(&hin->tag);
 	t = gettgt(d, hin->src);
 	if (t == NULL) {
 		printk(KERN_INFO "aoe: can't find target e%ld.%d:%012llx\n",
@@ -787,9 +787,9 @@ aoecmd_ata_rsp(struct sk_buff *skb)
 		snprintf(ebuf, sizeof ebuf,
 			"%15s e%d.%d    tag=%08x@%08lx\n",
 			"unexpected rsp",
-			get_unaligned_be16(&hin->major),
+			load_be16_noalign(&hin->major),
 			hin->minor,
-			get_unaligned_be32(&hin->tag),
+			load_be32_noalign(&hin->tag),
 			jiffies);
 		aoechr_error(ebuf);
 		return;
@@ -854,7 +854,7 @@ aoecmd_ata_rsp(struct sk_buff *skb)
 			printk(KERN_INFO
 				"aoe: unrecognized ata command %2.2Xh for %d.%d\n",
 				ahout->cmdstat,
-				get_unaligned_be16(&hin->major),
+				load_be16_noalign(&hin->major),
 				hin->minor);
 		}
 	}
@@ -982,7 +982,7 @@ aoecmd_cfg_rsp(struct sk_buff *skb)
 	 * Enough people have their dip switches set backwards to
 	 * warrant a loud message for this special case.
 	 */
-	aoemajor = get_unaligned_be16(&h->major);
+	aoemajor = load_be16_noalign(&h->major);
 	if (aoemajor == 0xfff) {
 		printk(KERN_ERR "aoe: Warning: shelf address is all ones.  "
 			"Check shelf dip switches.\n");
@@ -996,7 +996,7 @@ aoecmd_cfg_rsp(struct sk_buff *skb)
 		return;
 	}
 
-	n = be16_to_cpu(ch->bufcnt);
+	n = load_be16(&ch->bufcnt);
 	if (n > aoe_maxout)	/* keep it reasonable */
 		n = aoe_maxout;
 
@@ -1049,7 +1049,7 @@ aoecmd_cfg_rsp(struct sk_buff *skb)
 		spin_unlock_irqrestore(&d->lock, flags);
 		return;
 	}
-	d->fw_ver = be16_to_cpu(ch->fwver);
+	d->fw_ver = load_be16(&ch->fwver);
 
 	sl = aoecmd_ata_id(d);
 
diff --git a/drivers/block/aoe/aoenet.c b/drivers/block/aoe/aoenet.c
index 9157d64..7a61d54 100644
--- a/drivers/block/aoe/aoenet.c
+++ b/drivers/block/aoe/aoenet.c
@@ -127,7 +127,7 @@ aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt,
 	skb_push(skb, ETH_HLEN);	/* (1) */
 
 	h = (struct aoe_hdr *) skb_mac_header(skb);
-	n = get_unaligned_be32(&h->tag);
+	n = load_be32_noalign(&h->tag);
 	if ((h->verfl & AOEFL_RSP) == 0 || (n & 1<<31))
 		goto exit;
 
@@ -139,7 +139,7 @@ aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt,
 			printk(KERN_ERR
 				"%s%d.%d@%s; ecode=%d '%s'\n",
 				"aoe: error packet from ",
-				get_unaligned_be16(&h->major),
+				load_be16_noalign(&h->major),
 				h->minor, skb->dev->name,
 				h->err, aoe_errlist[n]);
 		goto exit;
-- 
1.6.0.4.1013.gc6a01




      reply	other threads:[~2008-11-24 19:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-24 19:12 [PATCH-mm] kernel: add common endian load/store API Harvey Harrison
2008-11-24 19:35 ` Harvey Harrison [this message]

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=1227555333.5511.17.camel@brick \
    --to=harvey.harrison@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@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