All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Dan Williams <dan.j.williams@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org, kernel-janitors@vger.kernel.org
Cc: "Bjorn Helgaas" <bhelgaas@google.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Ira Weiny" <ira.weiny@intel.com>,
	"Jesse Brandeburg" <jesse.brandeburg@intel.com>,
	"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
	"Julia Lawall" <Julia.Lawall@inria.fr>,
	"Kevin Tian" <kevin.tian@intel.com>,
	"Lukas Wunner" <lukas.wunner@intel.com>,
	"Matthew Wilcox" <willy@infradead.org>
Subject: Re: [PATCH v3] cleanup: Add usage and style documentation
Date: Sat, 30 Mar 2024 21:23:39 +0100	[thread overview]
Message-ID: <5e16b656-514d-4598-8397-f2f8f87a05da@web.de> (raw)
In-Reply-To: <171175585714.2192972.12661675876300167762.stgit@dwillia2-xfh.jf.intel.com>

> Changes since v2:
> * remove the unnecessary newlines around code examples further reducing
>   the visual interruption of RST metadata (Jon)
> * Fix a missing FILO=>LIFO conversion
> * Fix a bug in the example

I find such improvements nice.


> * Collect Jonathan's reviewed-by

How good does this action fit to the event that you pointed issues out also yourself?


> Review has been quiet on this thread for a few days so I think is the
> final rev.

I got an other impression.


> Let me know if anything else to fix up.

I would appreciate if further patch review comments can get more attention.


…
> +++ b/include/linux/cleanup.h
> @@ -4,6 +4,142 @@
>
>  #include <linux/compiler.h>
>
> +/**
> + * DOC: scope-based cleanup helpers
> + *
> + * The "goto error" pattern is notorious for introducing …

Will any other label become more helpful for this description approach?


> + * this tedium …

Would an other wording be more appropriate here?




> + *                                                       … If a function
> + * wants to invoke pci_dev_put() on error, but return @dev (i.e. without
> + * freeing it) on success, it can do:
> + *
> + * ::
> + *
> + *	return no_free_ptr(dev);
> + *
> + * ...or:
> + *
> + * ::
> + *
> + *	return_ptr(dev);
…

Would this macro call be preferred as a succinct specification
(so that only the shorter one should be mentioned here)?
https://elixir.bootlin.com/linux/v6.8.2/source/include/linux/cleanup.h#L78


> + * Observe the lock is held for the remainder of the "if ()" block not
> + * the remainder of "func()".

I suggest to add a word in this sentence.

* Observe the lock is held for the remainder of the "if ()" block
* (and not the remainder of "func()").


> + * That bug is fixed by changing init() to call guard() and define +
> + * initialize @obj in this order::
> + *
> + *	guard(mutex)(&lock);
> + *	struct object *obj __free(remove_free) = alloc_add();

It is helpful to point such a design possibility and preference out.

But I imagine that the abstraction level should be raised another bit.
It seems that the mentioned variable definition should be achieved by
calling the macro “CLASS” instead for “an instance of the named class”.
Thus the macro “DEFINE_CLASS” should also be called before accordingly.
https://elixir.bootlin.com/linux/v6.8.2/source/include/linux/cleanup.h#L82


> + * the top of the function poses this potential interdependency problem

I suggest to add a comma at the end of this line.


> + * the recommendation is to always define and assign variables in one
> + * statement and not group variable definitions at the top of the
> + * function when __free() is used.

I became curious how code layout guidance will evolve further also
according to such an advice.


> + * Lastly, given that the benefit of cleanup helpers is removal of
> + * "goto", and that the "goto" statement can jump between scopes, the
> + * expectation is that usage of "goto" and cleanup helpers is never
> + * mixed in the same function. I.e. for a given routine, convert all
> + * resources that need a "goto" cleanup to scope-based cleanup, or
> + * convert none of them.

Can the word wrapping become nicer another bit?

* Lastly, given that the benefit of cleanup helpers is removal of "goto",
* and that the "goto" statement can jump between scopes,
* the expectation is that usage of "goto" and cleanup helpers is never
* mixed in the same function. I.e. for a given routine, convert all
* resources that need a "goto" cleanup to scope-based cleanup,
* or convert none of them.


Regards,
Markus

  reply	other threads:[~2024-03-30 20:24 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-20 22:04 [PATCH] cleanup: Add usage and style documentation Dan Williams
2024-03-22  5:43 ` Tian, Kevin
2024-03-23  0:17   ` Dan Williams
2024-03-23 18:01     ` Markus Elfring
2024-03-22  9:06 ` Peter Zijlstra
2024-03-22 19:10   ` Dan Williams
2024-03-23 20:44     ` Matthew Wilcox
2024-03-24  0:57       ` Dan Williams
2024-03-24  6:23         ` Lukas Wunner
2024-03-24  9:08         ` Jonathan Corbet
2024-03-24 20:37           ` Dan Williams
2024-03-22 13:00 ` Markus Elfring
2024-03-22 13:48   ` Greg Kroah-Hartman
2024-03-22 13:34 ` Bjorn Helgaas
2024-03-25 18:52   ` Dan Williams
2024-03-22 13:45 ` Matthew Wilcox
2024-03-25 22:57 ` [PATCH v2] " Dan Williams
2024-03-26 12:06   ` Markus Elfring
2024-03-26 15:35   ` Jonathan Corbet
2024-03-26 16:51     ` Dan Williams
2024-03-26 16:56   ` Jonathan Cameron
2024-03-26 17:49   ` Dan Williams
2024-03-26 17:53   ` Dan Williams
2024-03-29 23:48   ` [PATCH v3] " Dan Williams
2024-03-30 20:23     ` Markus Elfring [this message]
2024-04-01  8:19     ` Tian, Kevin
2024-04-02  7:15       ` [v3] " Markus Elfring

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=5e16b656-514d-4598-8397-f2f8f87a05da@web.de \
    --to=markus.elfring@web.de \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Julia.Lawall@inria.fr \
    --cc=bhelgaas@google.com \
    --cc=corbet@lwn.net \
    --cc=dan.j.williams@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=ira.weiny@intel.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas.wunner@intel.com \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    --cc=willy@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.