From: Dan Carpenter <dan.carpenter@oracle.com>
To: Sebastian Rachuj <sebastian.rachuj@studium.uni-erlangen.de>
Cc: linux@rationality.eu, devel@driverdev.osuosl.org,
linux-kernel@i4.cs.fau.de, tvboxspy@gmail.com,
gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
forest@alittletooquiet.net, more.andres@gmail.com
Subject: Re: [PATCH 10/11] Staging: vt6656: Combined nested conditions
Date: Thu, 2 Jan 2014 17:29:54 +0300 [thread overview]
Message-ID: <20140102142953.GE28413@mwanda> (raw)
In-Reply-To: <1388084140-21562-11-git-send-email-sebastian.rachuj@studium.uni-erlangen.de>
On Thu, Dec 26, 2013 at 07:55:39PM +0100, Sebastian Rachuj wrote:
> - if (pbyDesireSSID != NULL) {
> - if (((PWLAN_IE_SSID) pbyDesireSSID)->len != 0)
> - pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
> - }
> + if ((pbyDesireSSID != NULL) &&
> + (((PWLAN_IE_SSID) pbyDesireSSID)->len != 0))
> + pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
That's a lot of extra parentheses!
This patch is fine, but for future reference, adding a double negative
" != NULL" almost never doesn't makes the code less readable. If we
remove it then this fits on one line.
if (pbyDesireSSID && ((PWLAN_IE_SSID) pbyDesireSSID)->len != 0)
pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
The casting is horrible and this is garbage staging code. If the types
were cleaned up then it would look like:
if (pbyDesireSSID && pbyDesireSSID->len != 0)
pSSID = pbyDesireSSID;
The naming is also totally bogus, of course. What does "pby" mean? I
think "Desire" is clear but I don't think it's native English. The "p"
in "pSSID" probably stands for pointer??? It's as if someone
deliberately made every single character of this code as terrible as can
be.
if (new_ssid && new_ssid->len != 0)
ssid = new_ssid;
Technically " != 0" is the same as " != NULL" but " != 0" tells a story
and makes the code more readable.
> + } else if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
> + ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
> + ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))) {
Adding all these extra parentheses makes it harder to tell which are
needed and which are noise.
} else if (pMgmt->eConfigMode == WMAC_CONFIG_AUTO ||
(pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA &&
WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
(pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA &&
WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) {
In this case, the extra parentheses were there in the original code but
there are other times where this patch adds a number of pretty bogus
parens.
regards,
dan carpenter
next prev parent reply other threads:[~2014-01-02 14:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-26 18:55 [PATCHv2 0/11] Staging: vt6656: Cleanup of checkpatch problems in bssdb.c Sebastian Rachuj
2013-12-26 18:55 ` [PATCH 01/11] Staging: vt6656: Fix indentation of bssdb.c Sebastian Rachuj
2013-12-26 18:55 ` [PATCH 02/11] Staging: vt6656: Adjust comments in bssdb.c Sebastian Rachuj
2013-12-26 18:55 ` [PATCH 03/11] Staging: vt6656: Remove unnecessary semicolons Sebastian Rachuj
2013-12-26 18:55 ` [PATCH 04/11] Staging: vt6656: Correct operator coding style Sebastian Rachuj
2013-12-26 18:55 ` [PATCH 05/11] Staging: vt6656: Correct single space mistakes Sebastian Rachuj
2013-12-26 18:55 ` [PATCH 06/11] Staging: vt6656: Remove line feeds before else Sebastian Rachuj
2013-12-26 18:55 ` [PATCH 07/11] Staging: vt6656: Remove unnecessary spaces in format strings Sebastian Rachuj
2013-12-26 18:55 ` [PATCH 08/11] Staging: vt6656: Combine "else { if" to "else if" Sebastian Rachuj
2013-12-26 18:55 ` [PATCH 09/11] Staging: vt6656: Correct usage of braces Sebastian Rachuj
2013-12-26 18:55 ` [PATCH 10/11] Staging: vt6656: Combined nested conditions Sebastian Rachuj
2014-01-02 14:29 ` Dan Carpenter [this message]
2013-12-26 18:55 ` [PATCH 11/11] Staging: vt6656: Reduce line length of bssdb.c Sebastian Rachuj
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=20140102142953.GE28413@mwanda \
--to=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=forest@alittletooquiet.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@i4.cs.fau.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rationality.eu \
--cc=more.andres@gmail.com \
--cc=sebastian.rachuj@studium.uni-erlangen.de \
--cc=tvboxspy@gmail.com \
/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