Re: [PATCH] GMAC: fix simple_return.cocci warnings

From: Joe Perches
Date: Fri Jan 02 2015 - 19:46:58 EST


On Sat, 2015-01-03 at 08:25 +0800, kbuild test robot wrote:
> drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c:425:1-4: WARNING: end returns can be simpified
>
> Simplify a trivial if-return sequence. Possibly combine with a
> preceding function call.
> Generated by: scripts/coccinelle/misc/simple_return.cocci
>
> CC: Roger Chen <roger.chen@xxxxxxxxxxxxxx>
> Signed-off-by: Fengguang Wu <fengguang.wu@xxxxxxxxx>
> ---
>
> dwmac-rk.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> @@ -422,11 +422,7 @@ static int rk_gmac_init(struct platform_
> if (ret)
> return ret;
>
> - ret = gmac_clk_enable(bsp_priv, true);
> - if (ret)
> - return ret;
> -
> - return 0;
> + return gmac_clk_enable(bsp_priv, true);

I think this change is not particularly better.

When the pattern is multiply repeated like:

{
...
foo = bar();
if (foo)
return foo;

foo = baz();
if (foo)
return foo;

foo = qux();
if (foo)
return foo;

return 0;
}

I think it's better to not change the last
test in the sequence just to minimize overall
line count.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/