2008-04-21 02:33:11

by Harvey Harrison

[permalink] [raw]
Subject: [PATCH] mac80211: remove unnecessary byteshifts in frame control testing

Byteshift the constants rather than the data.

Signed-off-by: Harvey Harrison <[email protected]>
---
include/linux/ieee80211.h | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index f27d11a..1068965 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -546,16 +546,17 @@ enum ieee80211_back_parties {
*/
static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
{
- u8 *raw = (u8 *) hdr;
- u8 tofrom = (*(raw+1)) & 3; /* get the TODS and FROMDS bits */
-
- switch (tofrom) {
- case 2:
- return hdr->addr3;
- case 3:
- return hdr->addr4;
+ __le16 fc = hdr->frame_control;
+ fc &= __constant_cpu_to_le16(IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS);
+
+ switch (fc) {
+ case __constant_cpu_to_le16(IEEE80211_FCTL_FROMDS):
+ return hdr->addr3;
+ case __constant_cpu_to_le16(IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS):
+ return hdr->addr4;
+ default:
+ return hdr->addr2;
}
- return hdr->addr2;
}

/**
@@ -571,12 +572,13 @@ static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
*/
static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
{
- u8 *raw = (u8 *) hdr;
- u8 to_ds = (*(raw+1)) & 1; /* get the TODS bit */
+ __le16 fc = hdr->frame_control;
+ fc &= __constant_cpu_to_le16(IEEE80211_FCTL_TODS);

- if (to_ds)
+ if (fc)
return hdr->addr3;
- return hdr->addr1;
+ else
+ return hdr->addr1;
}

/**
@@ -589,8 +591,8 @@ static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
*/
static inline int ieee80211_get_morefrag(struct ieee80211_hdr *hdr)
{
- return (le16_to_cpu(hdr->frame_control) &
- IEEE80211_FCTL_MOREFRAGS) != 0;
+ __le16 fc = hdr->frame_control;
+ return !!(fc & __constant_cpu_to_le16(IEEE80211_FCTL_MOREFRAGS));
}

#endif /* IEEE80211_H */
--
1.5.5.144.g3e42





2008-04-21 08:21:20

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH] mac80211: remove unnecessary byteshifts in frame control testing

On Sun, 2008-04-20 at 19:33 -0700, Harvey Harrison wrote:
> Byteshift the constants rather than the data.

> diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
> index f27d11a..1068965 100644
> --- a/include/linux/ieee80211.h
> +++ b/include/linux/ieee80211.h
> @@ -546,16 +546,17 @@ enum ieee80211_back_parties {
> */
> static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
> {
> - u8 *raw = (u8 *) hdr;
> - u8 tofrom = (*(raw+1)) & 3; /* get the TODS and FROMDS bits */
> -
> - switch (tofrom) {
> - case 2:
> - return hdr->addr3;
> - case 3:
> - return hdr->addr4;
> + __le16 fc = hdr->frame_control;
> + fc &= __constant_cpu_to_le16(IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS);

Can you use the non-underscore versions except where necessary (i.e. for
"case ...")

johannes


Attachments:
signature.asc (828.00 B)
This is a digitally signed message part

2008-04-21 17:40:49

by Harvey Harrison

[permalink] [raw]
Subject: Re: [PATCH] mac80211: remove unnecessary byteshifts in frame control testing

Byteswap the constants rather than the frame_control member.

Signed-off-by: Harvey Harrison <[email protected]>
---
Johannes, incorporated your suggestionsre non-underscored version
where possible.

include/linux/ieee80211.h | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index f27d11a..b73749a 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -546,16 +546,17 @@ enum ieee80211_back_parties {
*/
static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
{
- u8 *raw = (u8 *) hdr;
- u8 tofrom = (*(raw+1)) & 3; /* get the TODS and FROMDS bits */
-
- switch (tofrom) {
- case 2:
- return hdr->addr3;
- case 3:
- return hdr->addr4;
+ __le16 fc = hdr->frame_control;
+ fc &= cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS);
+
+ switch (fc) {
+ case __constant_cpu_to_le16(IEEE80211_FCTL_FROMDS):
+ return hdr->addr3;
+ case __constant_cpu_to_le16(IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS):
+ return hdr->addr4;
+ default:
+ return hdr->addr2;
}
- return hdr->addr2;
}

/**
@@ -571,12 +572,13 @@ static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
*/
static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
{
- u8 *raw = (u8 *) hdr;
- u8 to_ds = (*(raw+1)) & 1; /* get the TODS bit */
+ __le16 fc = hdr->frame_control;
+ fc &= cpu_to_le16(IEEE80211_FCTL_TODS);

- if (to_ds)
+ if (fc)
return hdr->addr3;
- return hdr->addr1;
+ else
+ return hdr->addr1;
}

/**
@@ -589,8 +591,8 @@ static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
*/
static inline int ieee80211_get_morefrag(struct ieee80211_hdr *hdr)
{
- return (le16_to_cpu(hdr->frame_control) &
- IEEE80211_FCTL_MOREFRAGS) != 0;
+ __le16 fc = hdr->frame_control;
+ return !!(fc & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS));
}

#endif /* IEEE80211_H */
--
1.5.5.144.g3e42