mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Theodore Tso" <tytso@mit.edu>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: cocci@inria.fr, tools@kernel.org,
	kernel-janitors@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC] Replacing special goto statements by direct returns?
Date: Wed, 4 Nov 2026 07:58:37 -0500	[thread overview]
Message-ID: <ausnPnWk9qSCnWad@mit.edu> (raw)
In-Reply-To: <52418f50-b3ff-461d-8e66-c10f70e35b2a@web.de>

On Tue, Nov 03, 2026 at 03:23:23PM -0500, Markus Elfring wrote:
> 
> The documentation for the Linux coding style contains the following information.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v7.4-rc1#n526
> 
> “…
> The goto statement comes in handy when a function exits from multiple
> locations and some common work such as cleanup has to be done.  If there is no
> cleanup needed then just return directly.
> …”

I wonder if the churn in this sort of clean up is really worth it.
There is a very large set of AI-generated fixes for AI-discovered
security vulnerabilities, and so code churn that doesn't actually
result in net benefit in terms of making the code more maintainable,
or more testable, or addresses live security vulnerabilities may in
fact just make maintainer's job more difficult.

I will say at the moment, for me presonally, this kind of cleanup is
very likely going to be significantly down-prioritized in terms of
code acceptance because I'm really swamped with patches for ext4 and
e2fsprogs --- patches which in my opinion are much higher priority.

Cheers,

					- Ted




> 
> 
> Thus it seems that the following script for the semantic patch language
> can work to some degree.
> 
> 
> @replacement exists@
> identifier label, var;
> @@
> -goto label;
> +return var;
>  ...
> -label:
>  return var;
> 
> 
> 
> Unfortunately, patches would be generated then by such a simple SmPL code
> which would still preserve return statements that became unreachable.
> 
> Test result example:
> Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time spatch --allow-inconsistent-paths fs/xfs/libxfs/xfs_btree.c …/Projekte/Coccinelle/janitor/replace_goto_by_return2.cocci
> …
> @@ -1735,7 +1735,7 @@ xfs_btree_increment(
>                 --lev;
>                 error = xfs_btree_read_buf_block(cur, ptrp, 0, &block, &bp);
>                 if (error)
> -                       goto error0;
> +                       return error;
>  
>                 xfs_btree_setbuf(cur, lev, bp);
>                 cur->bc_levels[lev].ptr = 1;
> @@ -1747,8 +1747,6 @@ out1:
>  out0:
>         *stat = 0;
>         return 0;
> -
> -error0:
>         return error;
>  }
> …
> real    0m1,074s
> user    0m0,995s
> sys     0m0,071s
> 
> 
> 
> How should such a source code transformation approach be improved accordingly?
> 
> Regards,
> Markus
> 

      parent reply	other threads:[~2026-11-04 12:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 14:23 Markus Elfring
2026-11-03 16:38 ` Julia Lawall
2026-11-03 17:48   ` Markus Elfring
2026-11-04 11:12   ` Markus Elfring
2026-11-04 12:58 ` Theodore Tso [this message]

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=ausnPnWk9qSCnWad@mit.edu \
    --to=tytso@mit.edu \
    --cc=Markus.Elfring@web.de \
    --cc=cocci@inria.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tools@kernel.org \
    /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

all inboxes | Powered by JetHome®