All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Antonio Quartulli <ordex@autistici.org>
Cc: linux-wireless@vger.kernel.org
Subject: Re: [PATCH] nl/cfg/mac80211: use BIT(x) instead of (1 << x)
Date: Mon, 09 Jul 2012 11:22:04 +0200	[thread overview]
Message-ID: <1341825724.4455.16.camel@jlt3.sipsolutions.net> (raw)
In-Reply-To: <1341763805-7386-1-git-send-email-ordex@autistici.org>


> --- a/net/mac80211/iface.c
> +++ b/net/mac80211/iface.c
> @@ -1432,7 +1432,7 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
>  		struct ieee80211_supported_band *sband;
>  		sband = local->hw.wiphy->bands[i];
>  		sdata->rc_rateidx_mask[i] =
> -			sband ? (1 << sband->n_bitrates) - 1 : 0;
> +			sband ? BIT(sband->n_bitrates) - 1 : 0;

I don't like the BIT()-1 pattern, "(1 << x) - 1" seems like a more
regular pattern. Arguably, there should be a define for it, but I can't
seem to come up with a good name.

>  	/* This should be adjusted for each device */
> -	int device_constant = 1 << ARITH_SHIFT;
> +	int device_constant = BIT(ARITH_SHIFT);
>  	int test_frame_len = TEST_FRAME_LEN << ARITH_SHIFT;
> -	int s_unit = 1 << ARITH_SHIFT;
> +	int s_unit = BIT(ARITH_SHIFT);

similarly, I don't think this makes sense. Yes, it's the same code, but
this whole shift arithmetic is easier to understand when you don't use
BIT() I think, in particular since you can't replace things like
TEST_FRAME_LEN << ARITH_SHIFT and the code is less regular now.

> +++ b/net/mac80211/mesh_pathtbl.c
> @@ -84,7 +84,7 @@ static struct mesh_table *mesh_table_alloc(int size_order)
>  		return NULL;
>  
>  	newtbl->hash_buckets = kzalloc(sizeof(struct hlist_head) *
> -			(1 << size_order), GFP_ATOMIC);
> +			BIT(size_order), GFP_ATOMIC);

again here, the 1<<size_order isn't meant as BIT(), it's meant as a
size, so 1<< makes more sense.

> +++ b/net/mac80211/mlme.c
> @@ -168,7 +168,7 @@ void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
>  
>  static int ecw2cw(int ecw)
>  {
> -	return (1 << ecw) - 1;
> +	return BIT(ecw) - 1;

This is also not bit operations but calculations.

> @@ -463,7 +463,7 @@ void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
>  	mask = sdata->rc_rateidx_mask[info->band];
>  	memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band],
>  	       sizeof(mcs_mask));
> -	if (mask != (1 << txrc->sband->n_bitrates) - 1) {
> +	if (mask != BIT(txrc->sband->n_bitrates) - 1) {

again that mask thing ... I prefer the 1<< in this case, unless you want
to come up with a #define and submit it for linux/bitmap.h :)


>  /* Exponential averaging smoothness (used for I part of PID controller) */
>  #define RC_PID_SMOOTHING_SHIFT		3
> -#define RC_PID_SMOOTHING		(1 << RC_PID_SMOOTHING_SHIFT)
> +#define RC_PID_SMOOTHING		BIT(RC_PID_SMOOTHING_SHIFT)

Calculations again ...


>  		rthdr->it_present |=
> -			cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
> +			cpu_to_le32(BIT(IEEE80211_RADIOTAP_TSFT));

This makes sense, of course, it's actually doing bitwise operations.

johannes


  reply	other threads:[~2012-07-09  9:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-08 16:10 [PATCH] nl/cfg/mac80211: use BIT(x) instead of (1 << x) Antonio Quartulli
2012-07-09  9:22 ` Johannes Berg [this message]
2012-07-09  9:56   ` Antonio Quartulli
2012-07-09 15:56   ` Pavel Roskin

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=1341825724.4455.16.camel@jlt3.sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --cc=ordex@autistici.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.