Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Fri, 2013-12-06 at 10:11 +0300, Dan Carpenter wrote: > On Thu, Dec 05, 2013 at 03:29:22PM -0800, Joe Perches wrote: > > On Fri, 2013-12-06 at 02:21 +0300, Dan Carpenter wrote: > > > On Thu, Dec 05, 2013 at 03:09:15PM -0800, Joe Perches wrote: > > > > On Fri, 2013-12-06 at 01:50 +0300, Dan Carpenter wrote: > > > > > On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: > > > > Ah. > > > > Then maybe use a single ?: or a ! instead > > > > return ret ? 0 : 1; > > or > > return !ret; > > > > You still have to handle the negative. > > if (ret < 0) > return ret; > > return !ret; Of course. Apologies for not being clear. I meant using that ?: or ! after the first if (ret < 0) as you wrote. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Thu, Dec 05, 2013 at 03:29:22PM -0800, Joe Perches wrote: > On Fri, 2013-12-06 at 02:21 +0300, Dan Carpenter wrote: > > On Thu, Dec 05, 2013 at 03:09:15PM -0800, Joe Perches wrote: > > > On Fri, 2013-12-06 at 01:50 +0300, Dan Carpenter wrote: > > > > On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: > > Ah. > > Then maybe use a single ?: or a ! instead > > return ret ? 0 : 1; > or > return !ret; > You still have to handle the negative. if (ret < 0) return ret; return !ret; regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Fri, 2013-12-06 at 02:21 +0300, Dan Carpenter wrote: > On Thu, Dec 05, 2013 at 03:09:15PM -0800, Joe Perches wrote: > > On Fri, 2013-12-06 at 01:50 +0300, Dan Carpenter wrote: > > > On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: > > > > Fixes warnings regarding redundant parantheses thrown by the checkpatch > > > > tool in bpctl_mod.c > > [] > > > if (ret < 0) > > > return BP_NOT_CAP; > > > if (ret == 0) > > > return 1; > > > return 0; > > > > > > More lines, but simpler to understand than the original. > > > > > > Think of checkpatch.pl as a pointer to bad code and not that we just > > > have to silence checkpatch and move on. > > > > So true. > > > > If 0 is the expected ret value and 1 is the > > expected function return for not-errored use, > > I suggest changing the last bit to: > > > > if (ret < 0) > > return BP_NOT_CAP; > > else if (ret > 0) > > return 0; > > > > return 1; > > > > so that the error conditions are done first > > and the normal return is at the bottom of > > the function. > > In this function, -1 means fail, 1 means "on" and 0 means "off". I > sorted them from lowest to highest: negative, zero and greater than > zero. Ah. Then maybe use a single ?: or a ! instead return ret ? 0 : 1; or return !ret; cheers, Joe -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Thu, Dec 05, 2013 at 03:09:15PM -0800, Joe Perches wrote: > On Fri, 2013-12-06 at 01:50 +0300, Dan Carpenter wrote: > > On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: > > > Fixes warnings regarding redundant parantheses thrown by the checkpatch > > > tool in bpctl_mod.c > [] > > if (ret < 0) > > return BP_NOT_CAP; > > if (ret == 0) > > return 1; > > return 0; > > > > More lines, but simpler to understand than the original. > > > > Think of checkpatch.pl as a pointer to bad code and not that we just > > have to silence checkpatch and move on. > > So true. > > If 0 is the expected ret value and 1 is the > expected function return for not-errored use, > I suggest changing the last bit to: > > if (ret < 0) > return BP_NOT_CAP; > else if (ret > 0) > return 0; > > return 1; > > so that the error conditions are done first > and the normal return is at the bottom of > the function. In this function, -1 means fail, 1 means "on" and 0 means "off". I sorted them from lowest to highest: negative, zero and greater than zero. regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Fri, 2013-12-06 at 01:50 +0300, Dan Carpenter wrote: > On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: > > Fixes warnings regarding redundant parantheses thrown by the checkpatch > > tool in bpctl_mod.c [] > if (ret < 0) > return BP_NOT_CAP; > if (ret == 0) > return 1; > return 0; > > More lines, but simpler to understand than the original. > > Think of checkpatch.pl as a pointer to bad code and not that we just > have to silence checkpatch and move on. So true. If 0 is the expected ret value and 1 is the expected function return for not-errored use, I suggest changing the last bit to: if (ret < 0) return BP_NOT_CAP; else if (ret > 0) return 0; return 1; so that the error conditions are done first and the normal return is at the bottom of the function. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: > Fixes warnings regarding redundant parantheses thrown by the checkpatch tool > in bpctl_mod.c > Fair enough, but if you wanted to go clean the returns up further then you could. Remove all the "!= 0" bits. > @@ -3125,11 +3125,11 @@ static int tx_status(struct bpctl_dev *pbpctl_dev) > > ctrl = BPCTL_READ_REG(pbpctl_dev, CTRL); > if (pbpctl_dev->bp_i80) > - return ((ctrl & BPCTLI_CTRL_SWDPIN1) != 0 ? 0 : 1); > + return (ctrl & BPCTLI_CTRL_SWDPIN1) != 0 ? 0 : 1; The double negative just makes the code not as not confusing as it could be. Simpler: return (ctrl & BPCTLI_CTRL_SWDPIN1) ? 0 : 1; > > if ((pbpctl_dev->bp_caps & BP_CAP)) { > if (pbpctl_dev->bp_ext_ver >= PXG2BPI_VER) { > - return read_reg(pbpctl_dev, STATUS_REG_ADDR)) & > + return (((read_reg(pbpctl_dev, STATUS_REG_ADDR)) & > BYPASS_FLAG_MASK) == > - BYPASS_FLAG_MASK) ? 1 : 0); > + BYPASS_FLAG_MASK) ? 1 : 0; These super long lines would be better if we introduced a temporary variable. reg = read_reg(pbpctl_dev, STATUS_REG_ADDR); return (reg & BYPASS_FLAG_MASK) == BYPASS_FLAG_MASK; BYPASS_FLAG_MASK is poorly named. It's actually just a bit or a flag and not a mask, so it could be renamed. reg = read_reg(pbpctl_dev, STATUS_REG_ADDR); return (reg & BP_BYPASS_FLAG) ? 1 : 0; Which is way simpler than the original and only 2 lines long instead of 4. I don't know that "BP_" is the right prefix... BYPASS_FLAG is too generic. > @@ -4730,7 +4730,7 @@ int get_disc_pwup_fn(struct bpctl_dev *pbpctl_dev) > return -1; > > ret = default_pwron_disc_status(pbpctl_dev); > - return (ret == 0 ? 1 : (ret < 0 ? BP_NOT_CAP : 0)); > + return ret == 0 ? 1 : (ret < 0 ? BP_NOT_CAP : 0); if (ret < 0) return BP_NOT_CAP; if (ret == 0) return 1; return 0; More lines, but simpler to understand than the original. Think of checkpatch.pl as a pointer to bad code and not that we just have to silence checkpatch and move on. regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
Fixes warnings regarding redundant parantheses thrown by the checkpatch tool in bpctl_mod.c Signed-off-by: Will Tange --- drivers/staging/silicom/bpctl_mod.c | 122 ++-- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/drivers/staging/silicom/bpctl_mod.c b/drivers/staging/silicom/bpctl_mod.c index 39dc92a..ffd5d48 100644 --- a/drivers/staging/silicom/bpctl_mod.c +++ b/drivers/staging/silicom/bpctl_mod.c @@ -3125,11 +3125,11 @@ static int tx_status(struct bpctl_dev *pbpctl_dev) ctrl = BPCTL_READ_REG(pbpctl_dev, CTRL); if (pbpctl_dev->bp_i80) - return ((ctrl & BPCTLI_CTRL_SWDPIN1) != 0 ? 0 : 1); + return (ctrl & BPCTLI_CTRL_SWDPIN1) != 0 ? 0 : 1; if (pbpctl_dev->bp_540) { ctrl = BP10G_READ_REG(pbpctl_dev, ESDP); - return ((ctrl & BP10G_SDP1_DATA) != 0 ? 0 : 1); + return (ctrl & BP10G_SDP1_DATA) != 0 ? 0 : 1; } } @@ -3150,8 +3150,8 @@ static int tx_status(struct bpctl_dev *pbpctl_dev) } if (pbpctl_dev->bp_10g9) { - return ((BP10G_READ_REG(pbpctl_dev, ESDP) & -BP10G_SDP3_DATA) != 0 ? 0 : 1); + return (BP10G_READ_REG(pbpctl_dev, ESDP) & +BP10G_SDP3_DATA) != 0 ? 0 : 1; } else if (pbpctl_dev->bp_fiber5) { ctrl = BPCTL_READ_REG(pbpctl_dev, CTRL_EXT); @@ -3186,10 +3186,10 @@ static int tx_status(struct bpctl_dev *pbpctl_dev) if (pbpctl_dev->bp_540) { ctrl = BP10G_READ_REG(pbpctl_dev, ESDP); - return ((ctrl & BP10G_SDP1_DATA) != 0 ? 0 : 1); + return (ctrl & BP10G_SDP1_DATA) != 0 ? 0 : 1; } - return ((ctrl & BPCTLI_CTRL_SWDPIN0) != 0 ? 0 : 1); + return (ctrl & BPCTLI_CTRL_SWDPIN0) != 0 ? 0 : 1; } else return ((BP10G_READ_REG(pbpctl_dev, ESDP) & BP10G_SDP0_DATA) != 0 ? 0 : 1); @@ -3204,8 +3204,8 @@ static int bp_force_link_status(struct bpctl_dev *pbpctl_dev) if (DBI_IF_SERIES(pbpctl_dev->subdevice)) { if ((pbpctl_dev->bp_10g) || (pbpctl_dev->bp_10g9)) { - return ((BP10G_READ_REG(pbpctl_dev, ESDP) & -BP10G_SDP1_DIR) != 0 ? 1 : 0); + return (BP10G_READ_REG(pbpctl_dev, ESDP) & +BP10G_SDP1_DIR) != 0 ? 1 : 0; } } @@ -3251,9 +3251,9 @@ int bypass_flag_status(struct bpctl_dev *pbpctl_dev) if ((pbpctl_dev->bp_caps & BP_CAP)) { if (pbpctl_dev->bp_ext_ver >= PXG2BPI_VER) { - return read_reg(pbpctl_dev, STATUS_REG_ADDR)) & + return (((read_reg(pbpctl_dev, STATUS_REG_ADDR)) & BYPASS_FLAG_MASK) == -BYPASS_FLAG_MASK) ? 1 : 0); +BYPASS_FLAG_MASK) ? 1 : 0; } } return BP_NOT_CAP; @@ -3298,8 +3298,8 @@ int bypass_off_status(struct bpctl_dev *pbpctl_dev) if (pbpctl_dev->bp_caps & BP_CAP) { if (pbpctl_dev->bp_ext_ver >= PXG2BPI_VER) { - return read_reg(pbpctl_dev, STATUS_REG_ADDR)) & - BYPASS_OFF_MASK) == BYPASS_OFF_MASK) ? 1 : 0); + return (((read_reg(pbpctl_dev, STATUS_REG_ADDR)) & + BYPASS_OFF_MASK) == BYPASS_OFF_MASK) ? 1 : 0; } } return BP_NOT_CAP; @@ -,18 +,18 @@ static int bypass_status(struct bpctl_dev *pbpctl_dev) ctrl_ext = BP10G_READ_REG(pbpctl_dev_b, I2CCTL); BP10G_WRITE_REG(pbpctl_dev_b, I2CCTL, (ctrl_ext | BP10G_I2C_CLK_OUT)); - return ((BP10G_READ_REG(pbpctl_dev_b, I2CCTL) & -BP10G_I2C_CLK_IN) != 0 ? 0 : 1); + return (BP10G_READ_REG(pbpctl_dev_b, I2CCTL) & +BP10G_I2C_CLK_IN) != 0 ? 0 : 1; } else if (pbpctl_dev->bp_540) { - return (((BP10G_READ_REG(pbpctl_dev_b, ESDP)) & -BP10G_SDP0_DATA) != 0 ? 0 : 1); + return ((BP10G_READ_REG(pbpctl_dev_b, ESDP)) & +BP10G_SDP0_DATA) != 0 ? 0 : 1; } else if ((pbpctl_dev->bp_fiber5) ||
[PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
Fixes warnings regarding redundant parantheses thrown by the checkpatch tool in bpctl_mod.c Signed-off-by: Will Tange bh3...@gmail.com --- drivers/staging/silicom/bpctl_mod.c | 122 ++-- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/drivers/staging/silicom/bpctl_mod.c b/drivers/staging/silicom/bpctl_mod.c index 39dc92a..ffd5d48 100644 --- a/drivers/staging/silicom/bpctl_mod.c +++ b/drivers/staging/silicom/bpctl_mod.c @@ -3125,11 +3125,11 @@ static int tx_status(struct bpctl_dev *pbpctl_dev) ctrl = BPCTL_READ_REG(pbpctl_dev, CTRL); if (pbpctl_dev-bp_i80) - return ((ctrl BPCTLI_CTRL_SWDPIN1) != 0 ? 0 : 1); + return (ctrl BPCTLI_CTRL_SWDPIN1) != 0 ? 0 : 1; if (pbpctl_dev-bp_540) { ctrl = BP10G_READ_REG(pbpctl_dev, ESDP); - return ((ctrl BP10G_SDP1_DATA) != 0 ? 0 : 1); + return (ctrl BP10G_SDP1_DATA) != 0 ? 0 : 1; } } @@ -3150,8 +3150,8 @@ static int tx_status(struct bpctl_dev *pbpctl_dev) } if (pbpctl_dev-bp_10g9) { - return ((BP10G_READ_REG(pbpctl_dev, ESDP) -BP10G_SDP3_DATA) != 0 ? 0 : 1); + return (BP10G_READ_REG(pbpctl_dev, ESDP) +BP10G_SDP3_DATA) != 0 ? 0 : 1; } else if (pbpctl_dev-bp_fiber5) { ctrl = BPCTL_READ_REG(pbpctl_dev, CTRL_EXT); @@ -3186,10 +3186,10 @@ static int tx_status(struct bpctl_dev *pbpctl_dev) if (pbpctl_dev-bp_540) { ctrl = BP10G_READ_REG(pbpctl_dev, ESDP); - return ((ctrl BP10G_SDP1_DATA) != 0 ? 0 : 1); + return (ctrl BP10G_SDP1_DATA) != 0 ? 0 : 1; } - return ((ctrl BPCTLI_CTRL_SWDPIN0) != 0 ? 0 : 1); + return (ctrl BPCTLI_CTRL_SWDPIN0) != 0 ? 0 : 1; } else return ((BP10G_READ_REG(pbpctl_dev, ESDP) BP10G_SDP0_DATA) != 0 ? 0 : 1); @@ -3204,8 +3204,8 @@ static int bp_force_link_status(struct bpctl_dev *pbpctl_dev) if (DBI_IF_SERIES(pbpctl_dev-subdevice)) { if ((pbpctl_dev-bp_10g) || (pbpctl_dev-bp_10g9)) { - return ((BP10G_READ_REG(pbpctl_dev, ESDP) -BP10G_SDP1_DIR) != 0 ? 1 : 0); + return (BP10G_READ_REG(pbpctl_dev, ESDP) +BP10G_SDP1_DIR) != 0 ? 1 : 0; } } @@ -3251,9 +3251,9 @@ int bypass_flag_status(struct bpctl_dev *pbpctl_dev) if ((pbpctl_dev-bp_caps BP_CAP)) { if (pbpctl_dev-bp_ext_ver = PXG2BPI_VER) { - return read_reg(pbpctl_dev, STATUS_REG_ADDR)) + return (((read_reg(pbpctl_dev, STATUS_REG_ADDR)) BYPASS_FLAG_MASK) == -BYPASS_FLAG_MASK) ? 1 : 0); +BYPASS_FLAG_MASK) ? 1 : 0; } } return BP_NOT_CAP; @@ -3298,8 +3298,8 @@ int bypass_off_status(struct bpctl_dev *pbpctl_dev) if (pbpctl_dev-bp_caps BP_CAP) { if (pbpctl_dev-bp_ext_ver = PXG2BPI_VER) { - return read_reg(pbpctl_dev, STATUS_REG_ADDR)) - BYPASS_OFF_MASK) == BYPASS_OFF_MASK) ? 1 : 0); + return (((read_reg(pbpctl_dev, STATUS_REG_ADDR)) + BYPASS_OFF_MASK) == BYPASS_OFF_MASK) ? 1 : 0; } } return BP_NOT_CAP; @@ -,18 +,18 @@ static int bypass_status(struct bpctl_dev *pbpctl_dev) ctrl_ext = BP10G_READ_REG(pbpctl_dev_b, I2CCTL); BP10G_WRITE_REG(pbpctl_dev_b, I2CCTL, (ctrl_ext | BP10G_I2C_CLK_OUT)); - return ((BP10G_READ_REG(pbpctl_dev_b, I2CCTL) -BP10G_I2C_CLK_IN) != 0 ? 0 : 1); + return (BP10G_READ_REG(pbpctl_dev_b, I2CCTL) +BP10G_I2C_CLK_IN) != 0 ? 0 : 1; } else if (pbpctl_dev-bp_540) { - return (((BP10G_READ_REG(pbpctl_dev_b, ESDP)) -BP10G_SDP0_DATA) != 0 ? 0 : 1); + return ((BP10G_READ_REG(pbpctl_dev_b, ESDP)) +BP10G_SDP0_DATA) != 0 ? 0 : 1; } else if ((pbpctl_dev-bp_fiber5) || (pbpctl_dev-bp_i80)) { -
Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: Fixes warnings regarding redundant parantheses thrown by the checkpatch tool in bpctl_mod.c Fair enough, but if you wanted to go clean the returns up further then you could. Remove all the != 0 bits. @@ -3125,11 +3125,11 @@ static int tx_status(struct bpctl_dev *pbpctl_dev) ctrl = BPCTL_READ_REG(pbpctl_dev, CTRL); if (pbpctl_dev-bp_i80) - return ((ctrl BPCTLI_CTRL_SWDPIN1) != 0 ? 0 : 1); + return (ctrl BPCTLI_CTRL_SWDPIN1) != 0 ? 0 : 1; The double negative just makes the code not as not confusing as it could be. Simpler: return (ctrl BPCTLI_CTRL_SWDPIN1) ? 0 : 1; if ((pbpctl_dev-bp_caps BP_CAP)) { if (pbpctl_dev-bp_ext_ver = PXG2BPI_VER) { - return read_reg(pbpctl_dev, STATUS_REG_ADDR)) + return (((read_reg(pbpctl_dev, STATUS_REG_ADDR)) BYPASS_FLAG_MASK) == - BYPASS_FLAG_MASK) ? 1 : 0); + BYPASS_FLAG_MASK) ? 1 : 0; These super long lines would be better if we introduced a temporary variable. reg = read_reg(pbpctl_dev, STATUS_REG_ADDR); return (reg BYPASS_FLAG_MASK) == BYPASS_FLAG_MASK; BYPASS_FLAG_MASK is poorly named. It's actually just a bit or a flag and not a mask, so it could be renamed. reg = read_reg(pbpctl_dev, STATUS_REG_ADDR); return (reg BP_BYPASS_FLAG) ? 1 : 0; Which is way simpler than the original and only 2 lines long instead of 4. I don't know that BP_ is the right prefix... BYPASS_FLAG is too generic. @@ -4730,7 +4730,7 @@ int get_disc_pwup_fn(struct bpctl_dev *pbpctl_dev) return -1; ret = default_pwron_disc_status(pbpctl_dev); - return (ret == 0 ? 1 : (ret 0 ? BP_NOT_CAP : 0)); + return ret == 0 ? 1 : (ret 0 ? BP_NOT_CAP : 0); if (ret 0) return BP_NOT_CAP; if (ret == 0) return 1; return 0; More lines, but simpler to understand than the original. Think of checkpatch.pl as a pointer to bad code and not that we just have to silence checkpatch and move on. regards, dan carpenter -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Fri, 2013-12-06 at 01:50 +0300, Dan Carpenter wrote: On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: Fixes warnings regarding redundant parantheses thrown by the checkpatch tool in bpctl_mod.c [] if (ret 0) return BP_NOT_CAP; if (ret == 0) return 1; return 0; More lines, but simpler to understand than the original. Think of checkpatch.pl as a pointer to bad code and not that we just have to silence checkpatch and move on. So true. If 0 is the expected ret value and 1 is the expected function return for not-errored use, I suggest changing the last bit to: if (ret 0) return BP_NOT_CAP; else if (ret 0) return 0; return 1; so that the error conditions are done first and the normal return is at the bottom of the function. -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Thu, Dec 05, 2013 at 03:09:15PM -0800, Joe Perches wrote: On Fri, 2013-12-06 at 01:50 +0300, Dan Carpenter wrote: On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: Fixes warnings regarding redundant parantheses thrown by the checkpatch tool in bpctl_mod.c [] if (ret 0) return BP_NOT_CAP; if (ret == 0) return 1; return 0; More lines, but simpler to understand than the original. Think of checkpatch.pl as a pointer to bad code and not that we just have to silence checkpatch and move on. So true. If 0 is the expected ret value and 1 is the expected function return for not-errored use, I suggest changing the last bit to: if (ret 0) return BP_NOT_CAP; else if (ret 0) return 0; return 1; so that the error conditions are done first and the normal return is at the bottom of the function. In this function, -1 means fail, 1 means on and 0 means off. I sorted them from lowest to highest: negative, zero and greater than zero. regards, dan carpenter -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Fri, 2013-12-06 at 02:21 +0300, Dan Carpenter wrote: On Thu, Dec 05, 2013 at 03:09:15PM -0800, Joe Perches wrote: On Fri, 2013-12-06 at 01:50 +0300, Dan Carpenter wrote: On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: Fixes warnings regarding redundant parantheses thrown by the checkpatch tool in bpctl_mod.c [] if (ret 0) return BP_NOT_CAP; if (ret == 0) return 1; return 0; More lines, but simpler to understand than the original. Think of checkpatch.pl as a pointer to bad code and not that we just have to silence checkpatch and move on. So true. If 0 is the expected ret value and 1 is the expected function return for not-errored use, I suggest changing the last bit to: if (ret 0) return BP_NOT_CAP; else if (ret 0) return 0; return 1; so that the error conditions are done first and the normal return is at the bottom of the function. In this function, -1 means fail, 1 means on and 0 means off. I sorted them from lowest to highest: negative, zero and greater than zero. Ah. Then maybe use a single ?: or a ! instead return ret ? 0 : 1; or return !ret; cheers, Joe -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Thu, Dec 05, 2013 at 03:29:22PM -0800, Joe Perches wrote: On Fri, 2013-12-06 at 02:21 +0300, Dan Carpenter wrote: On Thu, Dec 05, 2013 at 03:09:15PM -0800, Joe Perches wrote: On Fri, 2013-12-06 at 01:50 +0300, Dan Carpenter wrote: On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: Ah. Then maybe use a single ?: or a ! instead return ret ? 0 : 1; or return !ret; You still have to handle the negative. if (ret 0) return ret; return !ret; regards, dan carpenter -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] staging: silicom: fix 'return is not a function, parentheses are not required' in bpctl_mod.c
On Fri, 2013-12-06 at 10:11 +0300, Dan Carpenter wrote: On Thu, Dec 05, 2013 at 03:29:22PM -0800, Joe Perches wrote: On Fri, 2013-12-06 at 02:21 +0300, Dan Carpenter wrote: On Thu, Dec 05, 2013 at 03:09:15PM -0800, Joe Perches wrote: On Fri, 2013-12-06 at 01:50 +0300, Dan Carpenter wrote: On Thu, Dec 05, 2013 at 10:23:53PM +0100, Will Tange wrote: Ah. Then maybe use a single ?: or a ! instead return ret ? 0 : 1; or return !ret; You still have to handle the negative. if (ret 0) return ret; return !ret; Of course. Apologies for not being clear. I meant using that ?: or ! after the first if (ret 0) as you wrote. -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/