From: Pavel Roskin <proski@gnu.org>
To: okias <d.okias@gmail.com>
Cc: linux-wireless@vger.kernel.org
Subject: Re: [PATCH] v2: rtl8187: micro cleanup
Date: Wed, 17 Feb 2010 17:44:45 -0500 [thread overview]
Message-ID: <1266446685.12365.14.camel@mj> (raw)
In-Reply-To: <c2673ca61002171104xddb6275t6d9e69878a8c5f82@mail.gmail.com>
On Wed, 2010-02-17 at 20:04 +0100, okias wrote:
> ok, sorry I tested it on x86_64. Here is correct patch:
I'm sorry, but it's not a cleanup. Initializing reg outside the block
gives a wrong impression that reg may be used outside the block. Code
is safer is it's more readable, and it's more readable if the logic is
not spread around, but kept in one place.
Unnecessary initialization can prevent gcc from issuing warnings about
using uninitialized variables when the code changes. Such warnings may
be useful to find real bugs. I can give you a realistic example, but it
would be off-topic here.
A real cleanup would be to give reg the block scope and to refactor the
code where reg is written to the hardware:
--- a/drivers/net/wireless/rtl818x/rtl8187_dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8187_dev.c
@@ -1163,9 +1163,10 @@ static void rtl8187_bss_info_changed(struct ieee80211_hw *dev,
{
struct rtl8187_priv *priv = dev->priv;
int i;
- u8 reg;
if (changed & BSS_CHANGED_BSSID) {
+ u8 reg;
+
mutex_lock(&priv->conf_mutex);
for (i = 0; i < ETH_ALEN; i++)
rtl818x_iowrite8(priv, &priv->map->BSSID[i],
@@ -1176,13 +1177,12 @@ static void rtl8187_bss_info_changed(struct ieee80211_hw *dev,
else
reg = 0;
- if (is_valid_ether_addr(info->bssid)) {
+ if (is_valid_ether_addr(info->bssid))
reg |= RTL818X_MSR_INFRA;
- rtl818x_iowrite8(priv, &priv->map->MSR, reg);
- } else {
+ else
reg |= RTL818X_MSR_NO_LINK;
- rtl818x_iowrite8(priv, &priv->map->MSR, reg);
- }
+
+ rtl818x_iowrite8(priv, &priv->map->MSR, reg);
mutex_unlock(&priv->conf_mutex);
}
But I would never bother with that simply because wireless developers
have more important things to do.
I respectfully suggest that you do your exercises in C programming
elsewhere.
--
Regards,
Pavel Roskin
next prev parent reply other threads:[~2010-02-17 22:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-17 18:15 [PATCH] v2: rtl8187: micro cleanup okias
2010-02-17 18:30 ` Larry Finger
2010-02-17 18:34 ` okias
2010-02-17 18:36 ` Johannes Berg
2010-02-17 18:38 ` okias
2010-02-17 18:58 ` Pavel Roskin
2010-02-17 19:04 ` okias
2010-02-17 19:13 ` Sedat Dilek
2010-02-17 21:14 ` Hin-Tak Leung
2010-02-17 22:44 ` Pavel Roskin [this message]
2010-02-17 20:47 ` Hin-Tak Leung
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=1266446685.12365.14.camel@mj \
--to=proski@gnu.org \
--cc=d.okias@gmail.com \
--cc=linux-wireless@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).