Re: [PATCH] Staging: ks7010: ks_*: Braces should be used on all arms of these statements
From: Joe Perches
Date: Fri Feb 17 2017 - 21:38:18 EST
On Fri, 2017-02-17 at 14:50 -0800, Joe Perches wrote:
> On Fri, 2017-02-17 at 22:41 +0100, Shiva Kerdel wrote:
> > Braces should be used on all arms of these statements (CHECK)..
>
> []
> > diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c
>
> []
> > @@ -2148,8 +2148,9 @@ void hostif_sme_mode_setup(struct ks_wlan_private *priv)
> > else
> > rate_octet[i] =
> > priv->reg.rate_set.body[i];
> > - } else
> > + } else {
> > break;
> > + }
>
> Generally, any time you see a form like this,
> the test should be reversed
>
> for/while/do {
> if (foo) {
> [bar...]
> } else {
> break;
> }
>
> should be:
>
> for/while/do {
> if (!foo)
> break;
> [bar...]
> }
btw: the code would read better using
a temporary. Something like:
if (priv->reg.phy_type == D_11B_ONLY_MODE) {
for (i = 0; i < priv->reg.rate_set.size; i++) {
u8 rate = priv->reg.rate_set.body[i];
if (!IS_11B_RATE(rate))
break;
rate_octet[i] = ((rate & RATE_MASK) >= TX_RATE_5M)
? (rate & RATE_MASK) : rate;
}