ksummit.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Bart Van Assche <bvanassche@acm.org>,
	ksummit@lists.linux.dev, Dan Williams <dan.j.williams@intel.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: Clarifying confusion of our variable placement rules caused by cleanup.h
Date: Tue, 18 Nov 2025 16:10:00 -0500	[thread overview]
Message-ID: <fc255e7fb2b3fb4a2896f4e8680cca1f0cf7fe8d.camel@HansenPartnership.com> (raw)
In-Reply-To: <20251118155122.59dde92f@gandalf.local.home>

On Tue, 2025-11-18 at 15:51 -0500, Steven Rostedt wrote:
> On Tue, 18 Nov 2025 15:21:10 -0500
> James Bottomley <James.Bottomley@HansenPartnership.com> wrote:
> 
> > There is one last case that hasn't been discussed, which is where
> > you deliberately introduce an extra scope block for the free and
> > allocation, so in your example above it would look like
> > 
> > 	if (ret < )
> > 		return -ERROR
> > 
> > 	[ several more error exits ]
> > 
> > 	{
> > 		struct foo *var __free(kfree) = kmalloc(...)
> > 
> > 		[...]
> > 	}
> 
> I'm not too big on explicit blocks for just declarations. Especially,
> in my case where the var is used until the end:

Well I don't do it often, but there are times when the scope of a
variable is definitely a lot less than the scope of the code block.

I see this as being analagous to when you should use a guard vs a
scoped guard.

> 
> 	{
> 		struct foo *var __free(kfree) = kmalloc(...)
> 
> 		[...]
> 
> 		return func(..., var);
> 	}
> 
> It seems a bit strange to have the final return of a function from
> within an explicit scope block.

Well, you did that ... the return could equally well have been outside
the block.  However, I do think additional scoped blocks for variables
looks most readable when the scope of the variable is less than the
code on both sides.  If the variable doesn't go out of scope until the
final return, I can see an argument for just doing an interior
declaration.

Regards,

James

>  Especially since the beginning is just for error conditions, and the
> meat of the function is now in that explicit block.
> 
> -- Steve
> 


  reply	other threads:[~2025-11-18 21:10 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18 16:39 James Bottomley
2025-11-18 17:18 ` Bart Van Assche
2025-11-18 18:38   ` Linus Torvalds
2025-11-18 19:04     ` Bart Van Assche
2025-11-18 19:14       ` Linus Torvalds
2025-11-18 20:43         ` Al Viro
2025-11-18 19:15       ` H. Peter Anvin
2025-11-18 19:11     ` H. Peter Anvin
2025-11-18 19:16       ` Linus Torvalds
2025-11-18 19:19         ` H. Peter Anvin
2025-11-18 19:17     ` Steven Rostedt
2025-11-18 19:22       ` Linus Torvalds
2025-11-18 19:56         ` Steven Rostedt
2025-11-18 20:23           ` Linus Torvalds
2025-11-18 21:05             ` Linus Torvalds
2025-11-18 20:21       ` James Bottomley
2025-11-18 20:30         ` Linus Torvalds
2025-11-18 20:51         ` Steven Rostedt
2025-11-18 21:10           ` James Bottomley [this message]
2025-11-18 22:34             ` Steven Rostedt
2025-11-18 23:32               ` James Bottomley
2025-11-18 19:23 ` H. Peter Anvin
2025-11-18 20:28   ` James Bottomley
2025-11-25 13:09 ` Jani Nikula
2025-11-25 14:25 ` Alexey Dobriyan
2025-11-25 15:32   ` Stephen Hemminger
2025-11-25 16:04   ` Steven Rostedt
2025-11-25 17:57   ` H. Peter Anvin
2025-12-31 12:17   ` Andy Shevchenko

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=fc255e7fb2b3fb4a2896f4e8680cca1f0cf7fe8d.camel@HansenPartnership.com \
    --to=james.bottomley@hansenpartnership.com \
    --cc=bvanassche@acm.org \
    --cc=dan.carpenter@linaro.org \
    --cc=dan.j.williams@intel.com \
    --cc=ksummit@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.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