workflows.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Documentation/process/coding-style.rst: space around const/volatile
@ 2023-10-10 10:12 Max Kellermann
  2023-10-10 11:36 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Max Kellermann @ 2023-10-10 10:12 UTC (permalink / raw)
  To: linux, joe, Jonathan Corbet
  Cc: Max Kellermann, workflows, linux-doc, linux-kernel

There are currently no rules on the placement of "const" and
"volatile", but a recent code submission revealed that there is
clearly a preference for spaces around them.

checkpatch.pl has no check at all for this; though it does sometimes
complain, but only because it erroneously thinks that the "*" (on
local variables) is an unary dereference operator, not a pointer type.

Current coding style for const pointers-to-pointers:

 "*const*": 2 occurrences
 "* const*": 3
 "*const *": 182
 "* const *": 681

Just const pointers:

 "*const": 2833 occurrences
 "* const": 16615

Link: https://lore.kernel.org/r/264fa39d-aed6-4a54-a085-107997078f8d@roeck-us.net/
Link: https://lore.kernel.org/r/f511170fe61d7e7214a3a062661cf4103980dad6.camel@perches.com/
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
 Documentation/process/coding-style.rst | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
index 6db37a46d305..b40830517938 100644
--- a/Documentation/process/coding-style.rst
+++ b/Documentation/process/coding-style.rst
@@ -271,6 +271,18 @@ adjacent to the type name.  Examples:
 	unsigned long long memparse(char *ptr, char **retptr);
 	char *match_strdup(substring_t *s);
 
+Use space around the keywords ``const`` and ``volatile`` (except when
+adjacent to parentheses).  Example:
+
+.. code-block:: c
+
+	const void *a;
+	void * const b;
+	void ** const c;
+	void * const * const d;
+	void * volatile e;
+	int strcmp(const char *a, const char *b);
+
 Use one space around (on each side of) most binary and ternary operators,
 such as any of these::
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Documentation/process/coding-style.rst: space around const/volatile
  2023-10-10 10:12 [PATCH] Documentation/process/coding-style.rst: space around const/volatile Max Kellermann
@ 2023-10-10 11:36 ` Greg KH
  2023-10-10 12:03   ` Max Kellermann
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2023-10-10 11:36 UTC (permalink / raw)
  To: Max Kellermann
  Cc: linux, joe, Jonathan Corbet, workflows, linux-doc, linux-kernel

On Tue, Oct 10, 2023 at 12:12:40PM +0200, Max Kellermann wrote:
> There are currently no rules on the placement of "const" and
> "volatile", but a recent code submission revealed that there is
> clearly a preference for spaces around them.
> 
> checkpatch.pl has no check at all for this; though it does sometimes
> complain, but only because it erroneously thinks that the "*" (on
> local variables) is an unary dereference operator, not a pointer type.
> 
> Current coding style for const pointers-to-pointers:
> 
>  "*const*": 2 occurrences
>  "* const*": 3
>  "*const *": 182
>  "* const *": 681
> 
> Just const pointers:
> 
>  "*const": 2833 occurrences
>  "* const": 16615
> 
> Link: https://lore.kernel.org/r/264fa39d-aed6-4a54-a085-107997078f8d@roeck-us.net/
> Link: https://lore.kernel.org/r/f511170fe61d7e7214a3a062661cf4103980dad6.camel@perches.com/
> Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
> ---
>  Documentation/process/coding-style.rst | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
> index 6db37a46d305..b40830517938 100644
> --- a/Documentation/process/coding-style.rst
> +++ b/Documentation/process/coding-style.rst
> @@ -271,6 +271,18 @@ adjacent to the type name.  Examples:
>  	unsigned long long memparse(char *ptr, char **retptr);
>  	char *match_strdup(substring_t *s);
>  
> +Use space around the keywords ``const`` and ``volatile`` (except when
> +adjacent to parentheses).  Example:
> +
> +.. code-block:: c
> +
> +	const void *a;
> +	void * const b;
> +	void ** const c;
> +	void * const * const d;
> +	void * volatile e;
> +	int strcmp(const char *a, const char *b);

Don't encourage the use of volatile please, it shouldn't be needed in
kernel code (hint, almost all uses of it in the tree is wrong except for
asm statements and some .h files that know they need it for some
hardware operations.)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Documentation/process/coding-style.rst: space around const/volatile
  2023-10-10 11:36 ` Greg KH
@ 2023-10-10 12:03   ` Max Kellermann
  2023-10-10 12:21     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Max Kellermann @ 2023-10-10 12:03 UTC (permalink / raw)
  To: Greg KH; +Cc: linux, joe, Jonathan Corbet, workflows, linux-doc, linux-kernel

On Tue, Oct 10, 2023 at 1:37 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> Don't encourage the use of volatile please

I don't mean to - but I figured IF "volatile" is used (for whatever
reason, whether correct or not), it should follow the same coding
style as "const".

Do you want me to remove mentions of "volatile" (leaving the coding
style unspecified), or do you want me to add some warning about using
volatile?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Documentation/process/coding-style.rst: space around const/volatile
  2023-10-10 12:03   ` Max Kellermann
@ 2023-10-10 12:21     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2023-10-10 12:21 UTC (permalink / raw)
  To: Max Kellermann
  Cc: linux, joe, Jonathan Corbet, workflows, linux-doc, linux-kernel

On Tue, Oct 10, 2023 at 02:03:25PM +0200, Max Kellermann wrote:
> On Tue, Oct 10, 2023 at 1:37 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> > Don't encourage the use of volatile please
> 
> I don't mean to - but I figured IF "volatile" is used (for whatever
> reason, whether correct or not), it should follow the same coding
> style as "const".
> 
> Do you want me to remove mentions of "volatile" (leaving the coding
> style unspecified), or do you want me to add some warning about using
> volatile?

I would recommend just removing the mentions of it here.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-10 12:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-10 10:12 [PATCH] Documentation/process/coding-style.rst: space around const/volatile Max Kellermann
2023-10-10 11:36 ` Greg KH
2023-10-10 12:03   ` Max Kellermann
2023-10-10 12:21     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox