coccinelle: misc: remove "complex return code" warnings
PATCH 1/1 coccinelle: misc: remove "complex return code" warnings
This effectively reverts 932058a5d5f9 ("coccinelle: misc: semantic patch to delete overly complex return code processing").
There can be both symmetry and readability reasons for not wanting to do the final function call as part of the return statement and to maintain a clear separation of success and error paths.
Since this is in no way mandated by the coding standard, let's just remove this semantic patch to avoid having "clean up" patches being posted over and over in response to these Coccinelle warnings.
--- scripts/coccinelle/misc/simple_return.cocci | 180 ---------------------------- 1 file changed, 180 deletions(-) delete mode 100644 scripts/coccinelle/misc/simple_return.cocci
scripts/coccinelle/misc/simple_return.cocci deleted +0 -180
@@ -1,180 +0,0 @@ -/// Simplify a trivial if-return sequence. Possibly combine with a -/// preceding function call. -/// -// Confidence: High -// Copyright: (C) 2014 Julia Lawall, INRIA/LIP6. GPLv2. -// Copyright: (C) 2014 Gilles Muller, INRIA/LiP6. GPLv2. -// URL: http://coccinelle.lip6.fr/ -// Comments: -// Options: --no-includes --include-headers - -virtual patch -virtual context -virtual org -virtual report - -@r depends on patch@ -local idexpression e; -identifier i,f,fn; -@@ - -fn(...) { <... -- e@i = -+ return - f(...); --if (i != 0) return i; --return 0; -...> } - -@depends on patch@ -identifier r.i; -type t; -@@ - --t i; - ... when != i - -@depends on patch@ -expression e; -@@ - --if (e != 0) - return e; --return 0; - -// ----------------------------------------------------------------------- - -@s1 depends on context || org || report@ -local idexpression e; -identifier i,f,fn; -position p,p1,p2; -@@ - -fn(...) { <... -* e@i@p = f(...); - if (\(i@p1 != 0\|i@p2 < 0\)) - return i; - return 0; -...> } - -@s2 depends on context || org || report forall@ -identifier s1.i; -type t; -position q,s1.p; -expression e,f; -@@ - -* t i@q; - ... when != i - e@p = f(...); - -@s3 depends on context || org || report@ -expression e; -position p1!=s1.p1; -position p2!=s1.p2; -@@ - -*if (\(e@p1 != 0\|e@p2 < 0\)) - return e; - return 0; - -// ----------------------------------------------------------------------- - -@script:python depends on org@ -p << s1.p; -p1 << s1.p1; -q << s2.q; -@@ - -cocci.print_main("decl",q) -cocci.print_secs("use",p) -cocci.include_match(False) - -@script:python depends on org@ -p << s1.p; -p2 << s1.p2; -q << s2.q; -@@ - -cocci.print_main("decl",q) -cocci.print_secs("use with questionable test",p) -cocci.include_match(False) - -@script:python depends on org@ -p << s1.p; -p1 << s1.p1; -@@ - -cocci.print_main("use",p) - -@script:python depends on org@ -p << s1.p; -p2 << s1.p2; -@@ - -cocci.print_main("use with questionable test",p) - -@script:python depends on org@ -p << s3.p1; -@@ - -cocci.print_main("test",p) - -@script:python depends on org@ -p << s3.p2; -@@ - -cocci.print_main("questionable test",p) - -// ----------------------------------------------------------------------- - -@script:python depends on report@ -p << s1.p; -p1 << s1.p1; -q << s2.q; -@@ - -msg = "WARNING: end returns can be simpified and declaration on line %s can be dropped" % (q[0].line) -coccilib.report.print_report(p[0],msg) -cocci.include_match(False) - -@script:python depends on report@ -p << s1.p; -p1 << s1.p1; -q << s2.q -; -@@ - -msg = "WARNING: end returns may be simpified if negative or 0 value and declaration on line %s can be dropped" % (q[0].line) -coccilib.report.print_report(p[0],msg) -cocci.include_match(False) - -@script:python depends on report@ -p << s1.p; -p1 << s1.p1; -@@ - -msg = "WARNING: end returns can be simpified" -coccilib.report.print_report(p[0],msg) - -@script:python depends on report@ -p << s1.p; -p2 << s1.p2; -@@ - -msg = "WARNING: end returns can be simpified if negative or 0 value" -coccilib.report.print_report(p[0],msg) - -@script:python depends on report@ -p << s3.p1; -@@ - -msg = "WARNING: end returns can be simpified" -coccilib.report.print_report(p[0],msg) - -@script:python depends on report@ -p << s3.p2; -@@ - -msg = "WARNING: end returns can be simpified if tested value is negative or 0" -coccilib.report.print_report(p[0],msg)
Signature · 1 line
2.4.9
Quoted 10 lines · Johan Hovold
This effectively reverts
932058a5d5f9("coccinelle: misc: semantic patch to delete overly complex return code processing").There can be both symmetry and readability reasons for not wanting to do the final function call as part of the return statement and to maintain a clear separation of success and error paths.
Since this is in no way mandated by the coding standard, let's just remove this semantic patch to avoid having "clean up" patches being posted over and over in response to these Coccinelle warnings.
What do you mean by "posted"? Are you referring to 0-day build testing or individual usage of make coccicheck? Maybe it would make sense to remove the semantic patch from 0-day build testing but leave it in the kernel, perhaps removing the < 0 case because that one in practice doesn't seem to turn up much that is useful?
Perhaps it could also be improved to detect a previous != 0 case and then not return a warning. On some functions, this change can make some nice simplifications.
julia
Quoted 196 lines
Signed-off-by Johan Hovold <[email protected]>--- scripts/coccinelle/misc/simple_return.cocci | 180 ---------------------------- 1 file changed, 180 deletions(-) delete mode 100644 scripts/coccinelle/misc/simple_return.cocciscripts/coccinelle/misc/simple_return.cocci deleted +0
-180@@ -1,180 +0,0 @@ -/// Simplify a trivial if-return sequence. Possibly combine with a -/// preceding function call. -/// -// Confidence: High -// Copyright: (C) 2014 Julia Lawall, INRIA/LIP6. GPLv2. -// Copyright: (C) 2014 Gilles Muller, INRIA/LiP6. GPLv2. -// URL: http://coccinelle.lip6.fr/ -// Comments: -// Options: --no-includes --include-headers - -virtual patch -virtual context -virtual org -virtual report - - at r depends on patch@ -local idexpression e; -identifier i,f,fn; -@@ - -fn(...) { <... -- e at i = -+ return - f(...); --if (i != 0) return i; --return 0; -...> } - - at depends on patch@ -identifier r.i; -type t; -@@ - --t i; - ... when != i - - at depends on patch@ -expression e; -@@ - --if (e != 0) - return e; --return 0; - -// ----------------------------------------------------------------------- - - at s1 depends on context || org || report@ -local idexpression e; -identifier i,f,fn; -position p,p1,p2; -@@ - -fn(...) { <... -* e at i@p = f(...); - if (\(i at p1 != 0\|i at p2 < 0\)) - return i; - return 0; -...> } - - at s2 depends on context || org || report forall@ -identifier s1.i; -type t; -position q,s1.p; -expression e,f; -@@ - -* t i at q; - ... when != i - e at p = f(...); - - at s3 depends on context || org || report@ -expression e; -position p1!=s1.p1; -position p2!=s1.p2; -@@ - -*if (\(e at p1 != 0\|e at p2 < 0\)) - return e; - return 0; - -// ----------------------------------------------------------------------- - - at script:python depends on org@ -p << s1.p; -p1 << s1.p1; -q << s2.q; -@@ - -cocci.print_main("decl",q) -cocci.print_secs("use",p) -cocci.include_match(False) - - at script:python depends on org@ -p << s1.p; -p2 << s1.p2; -q << s2.q; -@@ - -cocci.print_main("decl",q) -cocci.print_secs("use with questionable test",p) -cocci.include_match(False) - - at script:python depends on org@ -p << s1.p; -p1 << s1.p1; -@@ - -cocci.print_main("use",p) - - at script:python depends on org@ -p << s1.p; -p2 << s1.p2; -@@ - -cocci.print_main("use with questionable test",p) - - at script:python depends on org@ -p << s3.p1; -@@ - -cocci.print_main("test",p) - - at script:python depends on org@ -p << s3.p2; -@@ - -cocci.print_main("questionable test",p) - -// ----------------------------------------------------------------------- - - at script:python depends on report@ -p << s1.p; -p1 << s1.p1; -q << s2.q; -@@ - -msg = "WARNING: end returns can be simpified and declaration on line %s can be dropped" % (q[0].line) -coccilib.report.print_report(p[0],msg) -cocci.include_match(False) - - at script:python depends on report@ -p << s1.p; -p1 << s1.p1; -q << s2.q -; -@@ - -msg = "WARNING: end returns may be simpified if negative or 0 value and declaration on line %s can be dropped" % (q[0].line) -coccilib.report.print_report(p[0],msg) -cocci.include_match(False) - - at script:python depends on report@ -p << s1.p; -p1 << s1.p1; -@@ - -msg = "WARNING: end returns can be simpified" -coccilib.report.print_report(p[0],msg) - - at script:python depends on report@ -p << s1.p; -p2 << s1.p2; -@@ - -msg = "WARNING: end returns can be simpified if negative or 0 value" -coccilib.report.print_report(p[0],msg) - - at script:python depends on report@ -p << s3.p1; -@@ - -msg = "WARNING: end returns can be simpified" -coccilib.report.print_report(p[0],msg) - - at script:python depends on report@ -p << s3.p2; -@@ - -msg = "WARNING: end returns can be simpified if tested value is negative or 0" -coccilib.report.print_report(p[0],msg)Signature · 1 line
2.4.9
Quoted 13 lines · Julia Lawall
Quoted 10 lines · Johan Hovold
This effectively reverts
932058a5d5f9("coccinelle: misc: semantic patch to delete overly complex return code processing").There can be both symmetry and readability reasons for not wanting to do the final function call as part of the return statement and to maintain a clear separation of success and error paths.
Since this is in no way mandated by the coding standard, let's just remove this semantic patch to avoid having "clean up" patches being posted over and over in response to these Coccinelle warnings.
Quoted 5 lines
What do you mean by "posted"? Are you referring to 0-day build testing or individual usage of make coccicheck? Maybe it would make sense to remove the semantic patch from 0-day build testing but leave it in the kernel, perhaps removing the < 0 case because that one in practice doesn't seem to turn up much that is useful?
Individuals running coccicheck on in-kernel code and posting patches to "fix warnings", where the end result is not necessarily an improvement.
But I don't think these warnings should be enabled for 0-day build testing either as it is should be up to the author to decide what style to prefer in each case.
Quoted 3 lines
Perhaps it could also be improved to detect a previous != 0 case and then not return a warning. On some functions, this change can make some nice simplifications.
Yes, that would at least improve things.
I don't think warnings should be generated at all for the following code:
{
int ret;
ret = init_a(...);
if (ret)
return ret;
ret = init_b(...);
if (ret)
return ret;
return 0;
}as it is (at least to me) preferred over:
{
int ret;
ret = init_a(...);
if (ret)
return ret;
return init_b(...);
}for symmetry and readability reasons (e.g. I don't have to look at init_b to figure out what the functions returns). And with a long parameter list to init_b with line breaks, this would look even worse.
But either way, it should be up to the author of the code to decide what style to use.
Thanks,
Johan
Do you consider that this function would be better off in two lines?
static int mxt_acquire_irq(struct mxt_data *data)
{
int error;
enable_irq(data->irq);
error = mxt_process_messages_until_invalid(data);
if (error)
return error;
return 0;
}Would simplifying the code at the end of the following function be helpful or not?
static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios)
{
struct gpio_chip *chip = &adnp->gpio;
int err;
adnp->reg_shift = get_count_order(num_gpios) - 3;
chip->direction_input = adnp_gpio_direction_input;
chip->direction_output = adnp_gpio_direction_output;
chip->get = adnp_gpio_get;
chip->set = adnp_gpio_set;
chip->can_sleep = true;
if (IS_ENABLED(CONFIG_DEBUG_FS))
chip->dbg_show = adnp_gpio_dbg_show;
chip->base = -1;
chip->ngpio = num_gpios;
chip->label = adnp->client->name;
chip->dev = &adnp->client->dev;
chip->of_node = chip->dev->of_node;
chip->owner = THIS_MODULE;
err = gpiochip_add(chip);
if (err)
return err;
return 0;
}thanks,
julia
Quoted 14 lines · Julia Lawall
Do you consider that this function would be better off in two lines?
static int
mxt_acquire_irq(struct mxt_data *data){ int error; enable_irq(data->irq); error = mxt_process_messages_until_invalid(data); if (error) return error; return 0; }
Actually no, but again I'd say it's up to the author to decide.
Quoted 24 lines
Would simplifying the code at the end of the following function be helpful or not?
static int
adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios){ struct gpio_chip *chip = &adnp->gpio; int err; adnp->reg_shift = get_count_order(num_gpios) - 3; chip->direction_input = adnp_gpio_direction_input; chip->direction_output = adnp_gpio_direction_output; chip->get = adnp_gpio_get; chip->set = adnp_gpio_set; chip->can_sleep = true; if (IS_ENABLED(CONFIG_DEBUG_FS)) chip->dbg_show = adnp_gpio_dbg_show; chip->base = -1; chip->ngpio = num_gpios; chip->label = adnp->client->name; chip->dev = &adnp->client->dev; chip->of_node = chip->dev->of_node;
Quoted 8 lines
chip->owner = THIS_MODULE;
err = gpiochip_add(chip);
if (err)
return err;
return 0;
}I think this is just fine as is as well.
Thanks,
Johan
Julia Lawall
Acked-byPerhaps there is a more restricted version that can be acceptable, but I'm OK with dropping the current version.
julia
Quoted 72 lines · Johan Hovold
Quoted 13 lines · Julia Lawall
Quoted 10 lines · Johan Hovold
This effectively reverts
932058a5d5f9("coccinelle: misc: semantic patch to delete overly complex return code processing").There can be both symmetry and readability reasons for not wanting to do the final function call as part of the return statement and to maintain a clear separation of success and error paths.
Since this is in no way mandated by the coding standard, let's just remove this semantic patch to avoid having "clean up" patches being posted over and over in response to these Coccinelle warnings.
Quoted 5 lines
What do you mean by "posted"? Are you referring to 0-day build testing or individual usage of make coccicheck? Maybe it would make sense to remove the semantic patch from 0-day build testing but leave it in the kernel, perhaps removing the < 0 case because that one in practice doesn't seem to turn up much that is useful?
Individuals running coccicheck on in-kernel code and posting patches to "fix warnings", where the end result is not necessarily an improvement.
But I don't think these warnings should be enabled for 0-day build testing either as it is should be up to the author to decide what style to prefer in each case.
Quoted 3 lines
Perhaps it could also be improved to detect a previous != 0 case and then not return a warning. On some functions, this change can make some nice simplifications.
Yes, that would at least improve things.
I don't think warnings should be generated at all for the following code:
{ int ret; ret = init_a(...); if (ret) return ret; ret = init_b(...); if (ret) return ret; return 0; }as it is (at least to me) preferred over:
{ int ret; ret = init_a(...); if (ret) return ret; return init_b(...); }for symmetry and readability reasons (e.g. I don't have to look at
init_bto figure out what the functions returns). And with a long parameter list toinit_bwith line breaks, this would look even worse.But either way, it should be up to the author of the code to decide what style to use.
Thanks,
Johan
Quoted 4 lines · Julia Lawall
Acked-by Julia Lawall <[email protected]>Perhaps there is a more restricted version that can be acceptable, but I'm OK with dropping the current version.
Great, thanks!
Johan
Should have acked this message...
Quoted 207 lines · Johan Hovold
This effectively reverts
932058a5d5f9("coccinelle: misc: semantic patch to delete overly complex return code processing").There can be both symmetry and readability reasons for not wanting to do the final function call as part of the return statement and to maintain a clear separation of success and error paths.
Since this is in no way mandated by the coding standard, let's just remove this semantic patch to avoid having "clean up" patches being posted over and over in response to these Coccinelle warnings.
Signed-off-by Johan Hovold <[email protected]>--- scripts/coccinelle/misc/simple_return.cocci | 180 ---------------------------- 1 file changed, 180 deletions(-) delete mode 100644 scripts/coccinelle/misc/simple_return.cocciscripts/coccinelle/misc/simple_return.cocci deleted +0
-181@@ -1,180 +0,0 @@ -/// Simplify a trivial if-return sequence. Possibly combine with a -/// preceding function call. -/// -// Confidence: High -// Copyright: (C) 2014 Julia Lawall, INRIA/LIP6. GPLv2. -// Copyright: (C) 2014 Gilles Muller, INRIA/LiP6. GPLv2. -// URL: http://coccinelle.lip6.fr/ -// Comments: -// Options: --no-includes --include-headers - -virtual patch -virtual context -virtual org -virtual report - - at r depends on patch@ -local idexpression e; -identifier i,f,fn; -@@ - -fn(...) { <... -- e at i = -+ return - f(...); --if (i != 0) return i; --return 0; -...> } - - at depends on patch@ -identifier r.i; -type t; -@@ - --t i; - ... when != i - - at depends on patch@ -expression e; -@@ - --if (e != 0) - return e; --return 0; - -// ----------------------------------------------------------------------- - - at s1 depends on context || org || report@ -local idexpression e; -identifier i,f,fn; -position p,p1,p2; -@@ - -fn(...) { <... -* e at i@p = f(...); - if (\(i at p1 != 0\|i at p2 < 0\)) - return i; - return 0; -...> } - - at s2 depends on context || org || report forall@ -identifier s1.i; -type t; -position q,s1.p; -expression e,f; -@@ - -* t i at q; - ... when != i - e at p = f(...); - - at s3 depends on context || org || report@ -expression e; -position p1!=s1.p1; -position p2!=s1.p2; -@@ - -*if (\(e at p1 != 0\|e at p2 < 0\)) - return e; - return 0; - -// ----------------------------------------------------------------------- - - at script:python depends on org@ -p << s1.p; -p1 << s1.p1; -q << s2.q; -@@ - -cocci.print_main("decl",q) -cocci.print_secs("use",p) -cocci.include_match(False) - - at script:python depends on org@ -p << s1.p; -p2 << s1.p2; -q << s2.q; -@@ - -cocci.print_main("decl",q) -cocci.print_secs("use with questionable test",p) -cocci.include_match(False) - - at script:python depends on org@ -p << s1.p; -p1 << s1.p1; -@@ - -cocci.print_main("use",p) - - at script:python depends on org@ -p << s1.p; -p2 << s1.p2; -@@ - -cocci.print_main("use with questionable test",p) - - at script:python depends on org@ -p << s3.p1; -@@ - -cocci.print_main("test",p) - - at script:python depends on org@ -p << s3.p2; -@@ - -cocci.print_main("questionable test",p) - -// ----------------------------------------------------------------------- - - at script:python depends on report@ -p << s1.p; -p1 << s1.p1; -q << s2.q; -@@ - -msg = "WARNING: end returns can be simpified and declaration on line %s can be dropped" % (q[0].line) -coccilib.report.print_report(p[0],msg) -cocci.include_match(False) - - at script:python depends on report@ -p << s1.p; -p1 << s1.p1; -q << s2.q -; -@@ - -msg = "WARNING: end returns may be simpified if negative or 0 value and declaration on line %s can be dropped" % (q[0].line) -coccilib.report.print_report(p[0],msg) -cocci.include_match(False) - - at script:python depends on report@ -p << s1.p; -p1 << s1.p1; -@@ - -msg = "WARNING: end returns can be simpified" -coccilib.report.print_report(p[0],msg) - - at script:python depends on report@ -p << s1.p; -p2 << s1.p2; -@@ - -msg = "WARNING: end returns can be simpified if negative or 0 value" -coccilib.report.print_report(p[0],msg) - - at script:python depends on report@ -p << s3.p1; -@@ - -msg = "WARNING: end returns can be simpified" -coccilib.report.print_report(p[0],msg) - - at script:python depends on report@ -p << s3.p2; -@@ - -msg = "WARNING: end returns can be simpified if tested value is negative or 0" -coccilib.report.print_report(p[0],msg) --2.4.9
Quoted 18 lines · Julia Lawall
Should have acked this message...
Acked-by Julia Lawall <[email protected]>Quoted 12 lines · Johan Hovold
This effectively reverts
932058a5d5f9("coccinelle: misc: semantic patch to delete overly complex return code processing").There can be both symmetry and readability reasons for not wanting to do the final function call as part of the return statement and to maintain a clear separation of success and error paths.
Since this is in no way mandated by the coding standard, let's just remove this semantic patch to avoid having "clean up" patches being posted over and over in response to these Coccinelle warnings.
Signed-off-by Johan Hovold <[email protected]>
Is anyone planning on picking this patch up?
Thanks,
Johan
Dne 28.10.2015 v 10:54 Johan Hovold napsal(a):
Quoted 14 lines · Julia Lawall
Quoted 13 lines
Should have acked this message...
Acked-by Julia Lawall <[email protected]>Quoted 7 lines · Johan Hovold
This effectively reverts
932058a5d5f9("coccinelle: misc: semantic patch to delete overly complex return code processing").There can be both symmetry and readability reasons for not wanting to do the final function call as part of the return statement and to maintain a clear separation of success and error paths.
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Since this is in no way mandated by the coding standard, let's just remove this semantic patch to avoid having "clean up" patches being posted over and over in response to these Coccinelle warnings.
Signed-off-by Johan Hovold <[email protected]>Is anyone planning on picking this patch up?
It is already in kbuild.git as commit 1a617a8475e8, I apparenly forgot to reply to this thread.
Michal
Quoted 19 lines · Michal Marek
Dne 28.10.2015 v 10:54 Johan Hovold napsal(a):
Quoted 18 lines · Julia Lawall
Quoted 17 lines
Should have acked this message...
Acked-by Julia Lawall <[email protected]>Quoted 11 lines · Johan Hovold
This effectively reverts
932058a5d5f9("coccinelle: misc: semantic patch to delete overly complex return code processing").There can be both symmetry and readability reasons for not wanting to do the final function call as part of the return statement and to maintain a clear separation of success and error paths.
Since this is in no way mandated by the coding standard, let's just remove this semantic patch to avoid having "clean up" patches being posted over and over in response to these Coccinelle warnings.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Signed-off-by Johan Hovold <[email protected]>Is anyone planning on picking this patch up?
It is already in kbuild.git as commit
1a617a8475e8, I apparenly forgot to reply to this thread.
Ok, great.
Thanks,
Johan